Можно ли прикрепить фрагмент только к конкретному проекту в Sublime?
Я пытался сохранить файлы фрагментов в папке проекта, но это не работает. У тебя есть другая идея?
1 ответ
С пользовательским плагином
РЕДАКТИРОВАТЬ: обобщение следующего плагина был опубликован на https://packagecontrol.io/packages/ProjectCompletions
If you put this plugin in your User folder under the name ProjectCompletions.py
import sublime_plugin
class ProjectCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
return view.window().project_data().get("completions")
You can inject completions using a "completions"
entry in your project file:
{
"folders": ...
"completions":[
["I", "I am a ${1:snippet} baby!"]
]
}
The format for completions is [trigger, snippet]
, More elaborate approaches are possible so that the scope is also taken in account.
In an indirect way using the ProjectSpecific plugin
With that installed, you can use the settings
key of your project file to install additional commands. Then to enable a snippet you can add this to your project:
{
"folders": ...
"settings": {
"project-specific": {
"sublime-commands": [
{"caption": "My Snippet",
"command": "insert_snippet",
"args": {"contents": "I am a ${1:snippet} baby!"} }
]
}
...
}
}
and you'll find the "My Snippet" command in the command palette only in the current project.
You can also bind keys in a project specific way. By binding them to the insert_snippet
command you can achieve a similar effect without having to go through the palette.