LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Autotrigger conditions

Open dtomvan opened this issue 2 years ago • 5 comments

Hi, I have a feature request about conditional snippets

Normal conditions already exist: https://github.com/L3MON4D3/LuaSnip/blob/663d54482b11bca1ce94f56993b9f6ab485a13dc/DOC.md?plain=1#L164

These decide wether to show and/or expand at all. I would like it if I could have such a condition for autoexpansion. This would decide wether to autoexpand, but it will always be shown and can be manually expanded. This would be handy for snippets in for example markdown or latex, allowing the user to contextualize autoexpansion of snippets, to avoid errors.

Example: https://castel.dev/post/lecture-notes-1/#context

These kinds of snippets are nice to autoexpand in a mathematical context, like sr. But in another context they would be nice to still have, instead of just never expanding at all.

Current workaround

  1. duplicate the snippet with vim.deepcopy in both an autoexpand section and a normal one
  2. add the condition to the autoexpand one
  3. add the inverse of the condition to the normal one

This way either one of the snippets always expands: either the autoexpand one because the condition is met, or the normal one because the condition isn't met and the autoexpand one is disabled

Proposal

Either a similar autoexpand_condition option in a snippet, or by applying the condition in a different (breaking) way to autoexpand snippets, which would effectively do the same as the workaround I just mentioned.

PS: I very much like your project, keep it up!

dtomvan avatar Oct 22 '22 21:10 dtomvan