vim-vsnip
vim-vsnip copied to clipboard
Regex + transformations are not supported?
I can't get this to work it throws an error, $TM_FILENAME_BASE by itself works fine
{
"test": {
"prefix": "test",
"body": "${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}"
}
}
Error detected while processing function
<SNR>101_expand[1]
vsnip#expand[7]
vsnip#anonymous[4]
33[1]
17[1]
vsnip#snippet#parser#parse[7]
E605: Exception not caught: {"result": [false, null, 0], "text": "${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}"}
Error detected while processing function
<SNR>101_expand[1]
vsnip#expand[7]
E171: Missing :endif
Sorry. Currently, vsnip does not supported the transform feature.
transform feature is hard to implement because we should parse and translate javascript regexp.
Anyway, The parse failing does not expect so I've fixed it.
Hm... we can't support [^\W] regex maybe...
Anyway, The parse failing does not expect so I've fixed it.
Fixed, thanks
transform feature is hard to implement because we should parse and translate javascript regexp.
I understand that, but if the project goal is to support VSCode snippets format, IMO this is required. Otherwise, you can support vim regex instead but this will be breaking the interoperability with VSCode snippets then.
Yes. I planning and investigating to support it.
The feature is hard to support but I think the implementation is fun.
Since ${VIM:...} is supported, is there a way to use Regex this way? At least using Vims Regex (maybe \v by default).
As a workaround is it possible to pass variables into VIM/python, and then use python to manipulate them?
For example, note the first one works, the last 2 do not.
"${VIM:system('python -c \"import uuid, re, sys;sys.stdout.write(re.sub(r\\\"[^a-j]\\\",\\\"\\\",\\\"\\$USER\\\"))\"')}",
"${VIM:system('python -c \"import uuid, re, sys;sys.stdout.write(re.sub(r\\\"[^a-j]\\\",\\\"\\\",\\\"\\$TM_DIRECTORY\\\"))\"')}",
"${VIM:system('python -c \"import uuid, re, sys;sys.stdout.write(re.sub(r\\\"[^a-j]\\\",\\\"\\\",\\\"$TM_DIRECTORY\\\"))\"')}",
I know its not portable, but neither is $VIM....
Then we can use this: https://www.tutorialspoint.com/python/python_reg_expressions.htm
Couldn't /upcase//downcase//capitalize be implemented first? It seems to be much easier to implement than Regex transformation support.
I agree that this is a very important thing to support. I believe UltiSnips manages to do it but they have the luxury of working with Python.