Closed VorpalBlade closed 8 years ago
Post the contents of snippet file, please.
Sure. The file is from the built in C++ package of the newer Sublime version.
<snippet>
<description>#include <…></description>
<content><![CDATA[include <${1:.h}>]]></content>
<tabTrigger>inc</tabTrigger>
<scope>(source.c | source.objc | source.c++ | source.objc++) &meta.preprocessor.incomplete</scope>
</snippet>
escape all +
in snippet file: ++
is not valid expression in regexp;
P.S. Sorry for long reply - was not in town
Hm how to do this for built in packages though? Would it work if I placed an overriding file in the User package? Apparently the built in C++ package is broken nowdays.
EDIT: Does not appear that overriding the file in the User package helps.
I didn't test built in c++
snippets because I don't work with c++
. I'll be glad to help you to fix this plugin in order it works with built-in snippets. Let me know if you would like to do that and I'll try to figure out where to start.
I would indeed be interested to figure out a solution. As I see it, there are two approaches:
It is preferred to fix this issue but not to suppress popup because popup is really precious when you occasionally broke the plugin. If you write c++
you can easily fix python code: try to check "snippet_caller.py", line 28. Also there is replace logic on lines 97-102 that fix old snippets in order to load it without troubles.
I wrote a simple fix for this. Since I'm not much of a git user (I use Mercurial both at work and personally) I'm not sure how you want the patch posted.
I also tried to attach the patch file but github did not want to cooperate.
Thus you get the patch inline. I'm terribly sorry for that. (I should probably learn the github workflow with pull requests and so on at some point.)
diff --git a/snippet_caller.py b/snippet_caller.py
index 66deff6..88c42c8 100644
--- a/snippet_caller.py
+++ b/snippet_caller.py
@@ -101,6 +101,11 @@ class Snippet():
replace('+', '\\+').replace('.', '\\.') + '(?:\W|$))'
)
+ # Fix built in C++ snippets that use invalid regular expressions.
+ # This is safe since no actual regex can contain the sequence ++.
+ if '++' in snippet['scope'] != None:
+ snippet['scope'] = snippet['scope'].replace('++', '\\+\\+')
+
snippet['scope'] = re.compile(snippet['scope'])
snippet['name'], _ = os.path.splitext(os.path.basename(name))
I went to integrate your change and found logic that already implements that feature but regexp used does not cover your case. I've fixed it in e5573a9. Please update plugin and restart sublime in order to be sure that changes were applied.
I really appreciate your work: it helped me a lot with this bug. If you have another 30 minutes please send me your contact data to leonid@shagabutdinov.com - I would like to ask several questions about this snippets.
After switching to dev build 3110 of Sublime Text I get the following popup as soon as I open a new C++ file (be it as a partial match when typing using Ctrl-P or otherwise) or start typing in an already opened file. The issue goes away if I disable the SnippetCaller plugin.
Failed to load snippet Packages/C++/Snippets/#include-(#inc angle).sublime-snippet: multiple repeat
This message is also in the console, but there is no further related information in the console.