I'm looking to create a VScode snippet that would execute on an arbitrary prefix. I'm not exactly sure if a snippet is the right term for it, but here's what I'm thinking:
myFunction();
// Autofill this block
call(myFunction);
//
myFunctionNamedBob();
// Autofill this block
call(myFunctionNamedBob);
//
Is it possible to insert call(anyFunction) any time I hit enter after anyFunction();?
Thanks in advance.
the extension Snippet Generator does a good creating snippets, else you can create user snippets by :
You can create a vscode snippet to do this but you would have to trigger it manually - it won't happen automatically. In your snippets file:
In your snippets file:
"call function": {
"prefix": "();",
"body": [
"();\ncall(${TM_CURRENT_LINE/\\s*([^(]+)\\(\\);/$1/});"
]
}
With this after typing the trailing (); you have to hit Ctrl+Space to bring up the suggestions and select this one. Demo:
You can get automatic triggering with the extension HyperSnips. After installing it and following its setup instructions this "snippet" will do what you want:
snippet `(.*)\(\);` "call function" A
``
rv=m[0]+ '\n' + 'call(' + m[1] + ');'
``
endsnippet