Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Dropdown/Autocomplete inside snippets #186

Open
loranger opened this issue Nov 27, 2015 · 13 comments
Open

Dropdown/Autocomplete inside snippets #186

loranger opened this issue Nov 27, 2015 · 13 comments

Comments

@loranger
Copy link

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
Copy link

pvorona commented Jan 25, 2016

would be nice

@sindresorhus
Copy link

👍 This would make snippets so much more useful!

@sygint
Copy link

sygint commented Apr 29, 2016

👍

@flyinbutrs
Copy link

This would be amazing, add me to the 👍

@gavnyx
Copy link

gavnyx commented Nov 7, 2016

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

@Heiko-san
Copy link

Heiko-san commented Apr 24, 2017

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. :) 👍

<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
Copy link

lid3rs commented Jul 21, 2017

Awesome feature

@50Wliu
Copy link
Contributor

50Wliu commented Oct 24, 2017

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
Copy link

jinglesthula commented Nov 2, 2017

@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
Copy link
Contributor

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
Copy link

wasimxe commented Nov 1, 2018

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
Copy link

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

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

@jinglesthula
Copy link

jinglesthula commented Dec 6, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests