garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.
www.vim.org/scripts/script.php?script_id=2540
2.01k stars 181 forks source link

Feature Request: allow an option or selection list #265

Closed sigzero closed 5 months ago

sigzero commented 6 years ago

It would be nice to be to able to present multiple items to select from when the snippet section is called.

For example, for a shell script, I would define a TODO list like:

# ${1|TODO,FIXME,BUG,XXX|} - ${2:synopsis}

I've taken the construct from how vscode does it. So using the pipe character to enclose a comma delineated list gives a popup list to make a selection from.

ajzafar commented 6 years ago

This is already implemented in the completion branch. There are just a couple bugs that need working out before it's merged to master.

yann-morin-1998 commented 5 months ago

@ajzafar Any update for this "selection list in tab-stop"?

I have rebased the completion branch on top of the current master branch (after fixing a very few trivial conflict issues due to the rebase), and from what I can see, the selection is working as expected, for example with this snippet:

snippet applied
    Applied to ${1|master|next|backports}, thanks.

which gives the behaviour I would expect and like to have:

applied<TAB>
Applied to master, thanks
          |>master   <|
          | next      |
          | backports |

(For readability, I replaced colours with bars for the menu, and with >< for the selection).

Is there something else I can help with, to get this merged?

Thanks!

ajzafar commented 5 months ago

@yann-morin-1998 I fixed a few bugs over the weekend. There are a few left, but they're going to take a bit more effort to fix, and they only show up when you try to use a mirror or an evaluation inside a selection option. (Well one is actually a problem independent of selections, when using a mirror of a placeholder with a nested placeholder.) They may somewhat work, but I've decided to merge the branch with the caveat that those combinations are not currently supported.

I'm going to go ahead and close this as the major feature is implemented, and I'm going to open new issues for the remaining bugs.

yann-morin-1998 commented 5 months ago

@ajzafar That's wonderful, thanks a lot! 👍