Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created February 15, 2021 09:30
Show Gist options
  • Save OdatNurd/47b5485b052ea908566d5a2aec003287 to your computer and use it in GitHub Desktop.
Save OdatNurd/47b5485b052ea908566d5a2aec003287 to your computer and use it in GitHub Desktop.
Sublime Text 4 plugin to expand snippets and automatically fold parts of them up
import sublime
import sublime_plugin
class ExpandAndFoldSnippetCommand(sublime_plugin.TextCommand):
def run(self, edit, name, folds):
self.view.run_command("insert_snippet", {"name": name})
for _ in range(folds):
self.view.run_command("fold")
self.view.run_command("next_field")
class FoldingSnippetEventListener(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not all(view.match_selector(pt, "source.c") for pt in locations):
return None
return [
sublime.CompletionItem.command_completion(
"template",
"expand_and_fold_snippet",
{
"name": "Packages/User/testprog.sublime-snippet",
"folds": 1
},
"Template C Program",
sublime.KIND_SNIPPET,
details="Empty template for new program"
)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment