Created
February 15, 2021 09:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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