Why isn't doesn't this snippet work?


#1

My snippets file has 4 snippets that have the same scope, with different titles, triggers and bodies. For some reason the 2nd to last one isn’t triggering whenever I have my last snippet there also. Renaming the titles and triggers doesn’t fix this issue.

2nd to last snippet:

'.source.shell':
  "If Exists":
    'prefix': 'IfEx'
    'body':"""
    if [ -e /some/dir ]
    then
      ${1:echo "doing this"}
    else
      ${2:echo "It wasn't found"}
    fi
    """

Last snippet

'.source.shell':
  "If it Doesn't Exists":
    'prefix': '!IfEx'
    'body':"""
    if [ ! -e /some/dir ]
    then
      ${1:echo "doing this"}
    else
      ${2:echo "It was found"}
    fi
    """

Which version of Atom are I using?
0.189.0

What OS and version are I running?
Linux Mint 17.1 with the Linux 3.13.0-37-generic kernel

Do you have the Shadow DOM feature enabled?
Yes

Do I have the Emmet package installed?
No

Can I reproduce the issue after completely exiting Atom and restarting using atom --safe?
Yes


#2

CSON, like JSON, is an Object Notation. It consists of keys and structured values. If you specify two or more copies of the same key … the last copy overwrites the previous ones, not adds to it.

It sounds like you have:

'.source.shell':
  "If Exists":
    # snip
'.source.shell':
  "If it Doesn't Exists":
    #snip

Notice that you have two copies of the '.source.shell' key. If you change it to:

'.source.shell':
  "If Exists":
    # snip
  "If it Doesn't Exists":
    #snip

things will work fine.


#3

That works; thanks.


#4

Very few parsers check for this which is a real problem. I can’t think of a situation where you aren’t losing data when you have duplicates.


#5

I have a similar question.
That’s my snippet:
‘.text.html’:
‘html’: ‘html’
‘prefix’: ‘html’
‘body’: ‘skeletal structure of html, that i want to use

The snippet works on my Laptop. But on the Computer in my School the snippet adds an other structure. In the snippet.cson is no other snippet and i found no package that could explain this.

Hope my english is okay and I would enjoy if someone could help me (and if i have some bad phrases, it would be nice when someone could tell me how it would be better).

Greetings Chikako


#6

Your snippet should be written as

'.text.html':
  html:
    prefix: 'html'
    body: '<html></html>'

#7

Thanks but it doesn’t work.

Thats what I wrote:

> 'body': '<!DOCTYPE html>\n<html lang="de">\n\n\t<head>\n\t\t<meta charset="utf-8">\n\t\t<title></title>\n\t\t<link rel="stylesheet" type="text/css" href="">\n\t</head>\n\n\t<body>\n\n\t</body>\n\n</html>'

And thats the result:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    
  </body>
</html>

Could there is a predefined Snippet which isn’t in the cson? I also deactivate all “autocomplete” Packages without success.


#8

Hello.

I see no problem with what you are trying to do. Even with the prefix was html - no problem.

My preference is with using the triple quote """ and having a more closely what-you-see-is-what-you-get style. :thinking: you did save the snippet file before trying to use it - right?

BR


#9

Yes, I saved it. I closed Atom and start it again and watched in the file. My snippet was saved but didn’t work… but i found some autocomplete-packages for html, maybe there is the one that blocked my snippet.


#10

What happens if you press esc to close the autocomplete popup, and then press tab to expand the snippet?


#11

Your snippets.cson file should take priority over any snippets defined by packages. autocomplete-plus providers don’t generally carry snippets with them, so you’re not competing with those.

Mind providing a screenshot of your whole snippets.cson file?


#12

Thank you for your feedback.

Additional to what @Aerijo and @DamnedScholar said ->

Please name the prefix to something unique. Call it aaa or something strange. Then try to use that instead of the word html. This will indicate that the user snippets file is working as expected.

If this temporary plan does not work, then we know to look for the problem in the scope name or some error anywhere inside the user snippet file.