LoginSignup
4
4

More than 5 years have passed since last update.

Multiple snippets in Atom.io

Last updated at Posted at 2014-05-14

Edit: I just realized that the title is very ambiguous -- this is not about trying to support multiple snippet bodies for a given prefix. Sorry (it pains me too).

Quick post to complain about Atom.io's lack of documentation and its "gotcha" nature -- if you want to use multiple snippets for a language in Atom.io, you cannot have multiple source keys in your snippet.cson file or you will get stupid, random behavior.

How to do it correctly

'.source.js':
  'console.log':
    'prefix': 'log'
    'body': 'console.log($1)'
  'jshignore':
    'prefix': 'jsh'
    'body': '/*jshint ignore:start  */\n\t${1:code}\n/*jshint ignore:end  */'
  'map with anonymous function':
    'prefix': 'map'
    'body': 'map(function (${1:value}) {\n\t$2\n});'

So the structure for the correct usage of snippets is this:

LANG_KEY:
  DESCRIPTION
    'prefix': TRIGGER
    'body': SNIPPET
  DESCRIPTION_2
    [SNIPPET BODY]

Documentation doesn't say anything and the "snip" default snippet in the file gives you the whole tree, so I assumed every snippet needed to be inside of a new object rather than being members of the language objects (If this is actually the intended usage, then this is just one of many bugs).

How to do it wrongly

'.source.js':
  'console.log':
    'prefix': 'log'
    'body': 'console.log($1)'
'.source.js':
  'jshignore':
    'prefix': 'jsh'
    'body': '/*jshint ignore:start  */\n/*jshint ignore:end  */'
'.source.js':
  'map with anonymous function':
    'prefix': 'map'
    'body': 'map(function ($1) {\n\t$2\n});'

So doing it incorrectly will work somewhat, but in my case, only 'log' and 'map' were triggered while 'jsh' never triggered. Well, now we know.

Closing remarks

As of today, searching 'snippet' on Atom.io docs gives you some useless results:

Well, let's hope that as v1.0 gets closer, the documentation gets better (also hope for less bugs).

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4