Custom snippets are not working, but it did before


#1

Hello all.

I have created snippets that work but without knowing why, today they do not work.

An idea ??

Thank you in advance for your answer

PS: sorry for my bad english


Snippet failed to load
#2

Hello.

There is not enough detail in your question for us to be helpful to you.
Please provide information such as:

  • Operating System (OS)

  • Atom version

  • Which snippets worked before

  • Which program language (called: grammar) did you have the snippet before

  • The snippet that worked before, was it…

    a) part of a standard lanuage
    b) you placed the snippet in the snippets.cson file
    c) somone else made a custom snippet for you.

  • Provide us of a copy of your snippets.cson file
    (more information later)


For some background information, please have a look at the manual:

http://flight-manual.atom.io/


Special focus on the chapter of snippets:

http://flight-manual.atom.io/using-atom/sections/snippets/


To identify which grammar is active in Atom, please refer to the picture below. Make sure that Atom is identifying the correct program language (grammar).

You can also click on the grammar to change it, if it is wrong. Grammar is identified by primarily the extension of the file. For example myCode.js would be JavaScript. Not everyone uses file extensions as expected.

See active grammar


If you have doubt on where to find the snippets.cson file, please look at the picture below. It will be most helpful if you could copy-paste the text of the file here so we may dig deeper.

See custom snippets

Putting code into the forum can be a little tricky. Please use the following method:

```coffeescript
#your code will be where this line is
```

I hope you find these notes helpful so you may help us, so we may help you help.

Regards.
- Dan Padric


#3

Hi

‘.source.c’:
‘main’:
‘prefix’:‘main’
‘body’: “”“
int main() {
$1
return 0;
}
”""

‘.source.c’:
‘scanf’:
‘prefix’:‘scanf’
‘body’: “”“
scanf(”%s", $1);
"""

‘.source.c’:
‘printf’:
‘prefix’:‘printf’
‘body’: “”“
printf(”$1");
"""

‘.source.c’:
‘for’:
‘prefix’:‘for’
‘body’: “”“
for (i= 0; i</variable/; i++) {
/* code */
}
”""

For the language, i’m sure it’s good.

Thx for your help


#4

Hello,

:blush: I have updated my first response a little too late.
But see if there is anything of value there.

Something else to try. Put focus on your code and then do the following:

  • press Ctrl + Shift + p

  • start typing Snippets: Available
    snippets available

What do you see?..


UPDATE
I have taken your snippets, modified it a bit and and tested it.

Note the selected language at bottom right… even if I am using a blank unsaved text file.

The modified version is as follows:

# LANGUAGE C -------------------------------------------------------------------
'.source.c':
  'Main routine':
    'prefix': 'main'
    'body': """
    int main() {
      ${1:/* code */}
      return 0;
    }
    """

  'Function: scanf':
    'prefix': 'scanf'
    'body': 'scanf("%s", ${1:/variable/});'

  'Function: printf':
    'prefix': 'printf'
    'body': 'printf("${1:/message/}");'

  'Structure: For loop':
    'prefix': 'for'
    'body': """
    for (i= 0; i<${1:/variable/}; i++) {
      ${2:/* code */}
    }
    """

Bonus
I have the following in my keymap.cson file:

# MAIN TEXT EDITOR
'atom-text-editor:not(.mini)':
  'alt-x': 'snippets:available'

This helps me to check what is all the available snippets for the active file I am busy with.

Are these helpful to you? Does it solve your issue?
- Dan


Autocomplete templates list
#5

I think I figured out what the original problem was.
Quoting from Flight Manual Manual: Snippets
Screenshot-2017-10-16 Snippets

The link given above is: Configuring with CSON. Specifically the detail below -

Basically - your snippet mentions the scope source.c several times. This is cause for issues. If you have not done that, you would see a different result.
:sunglasses:


#6

Thank you very much. I look tomorrow and I keep you informed

:grin:


#7

Thank you very much. Everything seems to work as I want.

You are the best ^^ :grin: