atom / snippets

Atom snippets package
MIT License
205 stars 100 forks source link

Dropdown/Autocomplete inside snippets #186

Open loranger opened 8 years ago

loranger commented 8 years ago

Hi,

It may be useful to use dropdown list inside snippets placeholder as textmate does.

Let's say I create a snippet for the HTML <input> element. That would be really powerful if I was able to write it like this ;

'.text.html.basic':
  'Input Element':
    'prefix': 'input'
    'body': '<input type="${1:(text,submit,hidden,button)}" value="$2"/>'

and use it like that :

I don't know how feasible it is, but it would be really convenient, at least for a bunch of my snippets, for a lot of HTML snippets, Laravel snippets and a lot of methods which signature change depending on the context.

Whether you consider my enhancement proposition or not, I'd like to thank you all for this awesome editor.

Atom Version: 1.2.4 OS and Version: OSX 10.11.1

pvorona commented 8 years ago

would be nice

sindresorhus commented 8 years ago

:+1: This would make snippets so much more useful!

sygint commented 8 years ago

:+1:

flyinbutrs commented 7 years ago

This would be amazing, add me to the 👍

gavnyx commented 7 years ago

Our team really need this feature, it's like npp fingerText plugin

Heiko-san commented 7 years ago

PyCharm Templates can do this, this is why I was looking for an open feature request here, since I currently evaluate Atom as an alternative to PyCharm. :) :+1:

<template name="req" value="- require:&#10;    - $TYPE$: $RESOURCE$&#10;$END$" description="Salt Requisite require statement" toReformat="false" toShortenFQNames="true">
    <variable name="TYPE" expression="enum(&quot;sls&quot;,&quot;pkg&quot;,&quot;file&quot;,&quot;service&quot;,&quot;cmd&quot;,&quot;test&quot;,&quot;user&quot;,&quot;group&quot;,&quot;host&quot;,&quot;mount&quot;,&quot;ssh_auth&quot;)" defaultValue="" alwaysStopAt="true" />
    <variable name="RESOURCE" expression="clipboard()" defaultValue="" alwaysStopAt="true" />
    <context>
      <option name="OTHER" value="true" />
    </context>
</template>

Of course PyCharm templates are hard to read, sorry it's java and java loves XML xD

PS: Filling in the contents of the clipboard (also shown in my example) would be also very nice, although the enum is much more important in my opinion.

here is a preview of some snippets for saltstack I'm working on: https://git.finchi.de/snippets/2/raw I really could use the drop-down feature for the True|False Values and some other choices which are rather limited.

lid3rs commented 7 years ago

Awesome feature

50Wliu commented 6 years ago

FYI autocomplete-html already does this. Is there any reason to keep this issue open since autocomplete and ide packages can provide snippet autocompletion without complicating the snippet syntax?

jinglesthula commented 6 years ago

@50Wliu I think definitely there is reason to keep it open.

To be sure, the existing autocomplete is very useful. I use it a great deal when using snippets.

However, with the existing autocomplete, you have to start typing, and the results are everything autocomplete knows about that's in scope. With what's suggested here, the list is specific and custom to the snippet, and only shows that.

Beyond that, the example screenshot above shows the first item highlighted by default, which would be great, too. You can type whatever, or hit tab again to accept the default, or arrow and hit tab to accept one of the other enumerated values. With the current autocomplete, you have to start typing a bit before you start to get things you want.

Another reason is that you may want to have a enumeration that autocomplete just won't have the proper suggestions for (see the below example).

If I create a snippet and want the options to be 'apple', 'ball', and 'carrot', I may want to always see those and only those for a particular tab stop in my custom snippet.

I think what's being asked for here is the ability to control what shows in the autocomplete.

And I would suggest that it would be great to allow for something like:

'Please enter your ${1:(name,gender,birthdate)} in order to $2. Without your $1, you cannot proceed.'

I frequently use the same number multiple places in my snippets where I need the same string inserted, and having trailing instances respect the first enumerated one still would be important behavior to preserve.

re: complicating the snippet syntax, I don't think that's an issue. Adding support for an additional bit of syntax doesn't complicate existing simpler snippets. I think a section at the bottom of the docs that says something like "and if you want to put an enum in a particular $'d tab stop, here's how you'd do that" would be simple enough. I don't think that would confuse anyone, especially forthose who don't end up using it. (How it plays out in the actual snippet parsing code would certainly be more complex, but that's a separate concern from snippet syntax for the user.)

savetheclocktower commented 5 years ago

VScode has implemented this; see the “Choice” heading in this documentation. If we add this in the future we should aim for syntax compatibility unless we have an excellent reason not to.

wasimxe commented 5 years ago

Atom and I guess also Sublime missing dynamic snippet, NP++ plugin fingertext is powerful snippet plugin which support, FILE, DATE, LIST, OPTION, EXEC, RUN and many other dynamic feature, seems like its hard for them to implement this request ;)

cdietrich commented 5 years ago

see https://macromates.com/textmate/manual/snippets#grammar too.

${«int»|«choice 1»,…,«choice n»|}

jinglesthula commented 5 years ago

If VSCode and TextMate both share the same syntax for this feature, I think it makes all the sense in the world to follow suit. It also makes sense if multiple other editors support the feature to add it to Atom so it's not lagging behind.