Cannot add multiple snippets to snippets.cson


#1

I’ve been exploring Atom today, and so far I like it a lot.

However, one problem that I found and cannot find an answer too, is with adding multiple snippets to snippets.cson

For context, this is what my snippet file looks like currently.

'.source.batchfile':
  'Error check':
    'prefix': 'error'
    'body': """
    if errorlevel 1 (
        type nul
        echo Faiure! Detailed above
        pause
      ) else (
        echo Success
    )
    echo.
    """


'.source.batchfile':
  'Snippet Name':
    'prefix': 'hello'
    'body': 'Hello World!'

The problem is that only the second snippet (prefix “hello”) is usable. The previous one (prefix “error”) used to work, but as soon as I added “hello” it stopped working. By this I mean that I was no longer able to call it, and when pressing ALT+SHIFT+S it is no longer on the list of available and usable snippets.

Im pretty sure this is a user error and I am doing something wrong, but I cannot figure it out.

Help?
Thanks!


Why snippet doesn't work with ejs file?
#2

Your second one has the same key value as the first and is replacing it. I consider it a bug when parsers allow this to happen. It should throw an error.


#3

Sorry if this seems obvious but, which one is the key value? The idea is that I can have many of these, so how do I allow that to happen?

Thanks :slight_smile:


#4

The key is the text before a colon. The value is the text after the colon. The value includes everything indented further than the key, including other keys and values. For example:

'base key 1': 'value 1'
'base key 2': 
  'descendant key 2-1': 'value 2-1'
  'descendant key 2-2':
    'descendant key 2-2-1': 'value 2-2-1'

If you know how JSON works, CSON is just like it but without the braces and commas.


#5

'.source.batchfile':


#6

Okay so you guys have been great but I still don’t get how to fix the problem at hand. Would you mind supplying a altered copy of the code that I posted in the op that fixes the problem?


#7

Here’s what it should look like:

'.source.batchfile':
  'Error check':
    'prefix': 'error'
    'body': """
    if errorlevel 1 (
        type nul
        echo Faiure! Detailed above
        pause
      ) else (
        echo Success
    )
    echo.
    """

  'Snippet Name':
    'prefix': 'hello'
    'body': 'Hello World!'

#8

Oh so all you have to do is get rid of it the conflicting line?

Thanks!


#9

The nested indentation means both snippets are declared under the one key.


#10

Got it. I feel like, logically, I should be able to be redundant but then again Im not a skilled programmer :slight_smile: