Closed hinell closed 1 year ago
Currently we don't have a sane context matching syntax, so I wrote a small script that can be used to match snippets against major languages:
global function ctxmatcher (scope,name,c) { let v = c.scopes.some(txCntx => txCntx.startsWith(scope)); return v }; let langs = [ [ "source.js" , "javascript" ] , [ "source.ts" , "typescript" ] , [ "source.shell" , "shell" ] , [ "source.c" , "clang" ] , [ "source.cpp" , "cpp" ] , [ "source.py" , "py" ] , [ "source.batchfile" , "batch" ] , [ "text.html.markdown", "md" ] ]; for (let i=0; i < langs.length - 1; i++) { let [ scope, name ] = langs[i]; if(this[name] !== null){ this[name] = ctxmatcher.bind(this, scope, name) } }; // Use it like: // context javascript(context) // snippet ... // endsnippet endglobal # Example how to use context javascript(context) snippet hsnip.test.js "Test scope" Wi This snippet is expanded only in JavaScript! endsnippet
Extend the langs = [...] array for more languages. Hope it helps!
langs = [...]
Thanks for the snippet, but I do believe this is more appropriate as a discussion topic!
Currently we don't have a sane context matching syntax, so I wrote a small script that can be used to match snippets against major languages:
Extend the
langs = [...]
array for more languages. Hope it helps!