vim-vsnip icon indicating copy to clipboard operation
vim-vsnip copied to clipboard

Regex + transformations are not supported?

Open ahmedelgabri opened this issue 5 years ago • 9 comments

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

ahmedelgabri avatar Aug 08 '20 21:08 ahmedelgabri

Sorry. Currently, vsnip does not supported the transform feature.

transform feature is hard to implement because we should parse and translate javascript regexp.

hrsh7th avatar Aug 09 '20 02:08 hrsh7th

Anyway, The parse failing does not expect so I've fixed it.

hrsh7th avatar Aug 09 '20 07:08 hrsh7th

Hm... we can't support [^\W] regex maybe...

hrsh7th avatar Aug 09 '20 08:08 hrsh7th

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.

ahmedelgabri avatar Aug 09 '20 08:08 ahmedelgabri

Yes. I planning and investigating to support it.

The feature is hard to support but I think the implementation is fun.

hrsh7th avatar Aug 09 '20 09:08 hrsh7th

Since ${VIM:...} is supported, is there a way to use Regex this way? At least using Vims Regex (maybe \v by default).

jandamm avatar Oct 23 '20 21:10 jandamm

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

jimcornmell avatar May 05 '21 15:05 jimcornmell

Couldn't /upcase//downcase//capitalize be implemented first? It seems to be much easier to implement than Regex transformation support.

nawordar avatar Jun 07 '21 16:06 nawordar

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.

thorlucas avatar Jun 09 '21 13:06 thorlucas