4
votes

The following are two of the snippets I have scripted in snippets.cson file:

'.source.python':
  'print statement':
    'prefix': 'pr'
    'body' : 'print "${1:Hello world}"'


'.source.python':
  'Argument variables import':
    'prefix' : 'argv'
    'body' : 'from sys import argv'

The first one doesn't work, but the second one does. Help please.

Ps.

The snippets file was BLANK when I first installed atom on my machine. I use Ubuntu 16.04. Is that normal?

2

2 Answers

4
votes

I believe the root of your problem is that your scope .source.python was declared twice.

To answer your second question first, No, my snippets.cson file was not blank when I first opened it. Instead, it contained the following:

# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
#   'Console log':
#     'prefix': 'log'
#     'body': 'console.log $1'
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson

(This is on MacOS, though).

Notice how it instructs you that each scope can only be declared once. I think if you modify your two snippets to be included in the same scope, they will work as expected.

Changing your snippets.cson to the following appears to work for me:

'.source.python':
  'print statement':
    'prefix': 'pr'
    'body' : 'print "${1:Hello world}"'

  'Argument variables import':
    'prefix' : 'argv'
    'body' : 'from sys import argv'

I can access both snippets from the snippets import menu once I make the .source.python scope unique.

0
votes

Atom 1.53.0 x64 on Ubuntu 20.10 ("groovy gorilla"):

I had to disable the "build-in" snippets in "Settings" in the Core-Package "language-html" (0.53.1). From there I copied the snippet for a prefix, pasted it into my own local snippets.cson and changed it to my needs.

I also had to restart Atom to get the editor to show my custom snippet for usage.

The original snippets.cson was blank in my case, too. No hints, no example. Pure vi-feeling :-)