SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.51k stars 690 forks source link

Is there any way to list regular expressions snippers (option r) #1512

Open jambag opened 1 year ago

jambag commented 1 year ago

I only want to know if there is a way to list snippets created with option r (pyton regular expression). For example:

snippet "be(gin)?( (\S+))?" "begin{} / end{}" br
\begin{${1:`!p
...

I've configured "g:UltiSnipsListSnippets", but this type of snippets don't appear on the list, and that's important for me to avoid remembering them.

Sorry I've not found the solution in docs and this list of issues.

Thank you very much


smjonas commented 1 year ago

There is currently no built-in API to get this information. You have to write some hacky python code to achieve this.

For an example for Neovim, have a look here to see how we're doing this in cmp_nvim_ultisnips: https://github.com/quangnguyen30192/cmp-nvim-ultisnips/blob/main/autoload/cmp_nvim_ultisnips.vim. This is where the Python code is called: https://github.com/quangnguyen30192/cmp-nvim-ultisnips/blob/f90ebb220306e39766ad0ec1f094e4e12bb2fdd4/lua/cmp_nvim_ultisnips/snippets.lua#L8

SirVer commented 1 year ago

@smjonas well, or submit a PR that introduces a relevant public API, right?

@jambag at the moment there is no easy way to get regex snippets. Background is that the default python regex engine cannot report "partial matches", hence we do not know in a context if a regex trigger is actually potentially valid or not.

nonetallt commented 1 year ago

I was also just looking into this since I tried getting around the lack of aliases by using "or" regexes like "ns|namespace" but the regex snippets don't seem to play nice with other plugins (likely because they're not included in the snippets list).

I got the coc-snippets plugin to list my regex snippets but the string interpolation feature turned out problematic. More details in https://github.com/neoclide/coc-snippets/issues/323.

Currently using coc-ultisnips, which works as one would expect from UltiSnips - regex snippets aren't listed.

jambag commented 1 year ago

Thank you very much.

I hadn't thought about the complexity of partial matches, perhaps because the regexp I had in mind were very simple. I see now.