How do you configure/use snippets?


#1

I couldn’t find any documentation on how to use snippets on the atom.io site.

This is what I wrote in my snippets.cson file:

'.source.html':
  'HTML5 Skeleton':
    'prefix': 'html5skel'
    'body': '<!doctype html>'

saved it, quit atom, then opened a new test.html file, typed “html5skel” then hit tab and nothing showed up, I just added up tabbing 2 spaces, lol.

Can someone explain to me how to use the snippets feature?


Website Templating
#2

Try http://atom.io/docs/v0.60.0/creating-a-package#snippets

I can’t see why it isn’t working though.

Edit: Try removing quotes from 'prefix' and 'body' key names.


#3

I followed similar syntax to @bricejlin and also couldn’t get it to work. It just added two spaces.


#4

I tried removing the quotes but it didn’t help.

It’s kinda confusing because the comments shows a different syntax using quotes.

# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
#   'Console log':
#     'prefix': 'log'
#     'body': 'console.log $1'

#5

Snippets for CSS and JS work, but not for HTML and PHP. Here my PHP snippet:

'.source.php':
  'Formatted var_dump':
    'prefix': 'test'
    'body': 'This is a test.'

#7

I’ve gotten it to work.

Instead of:

'.source.html':
  'HTML5 Skeleton':
    'prefix': 'html5skel'
    'body': '<!doctype html>'

Use:

'.text.html': <--
    'HTML5 Skeleton':
      'prefix': 'html5skel'
      'body': '<!doctype html>'

Its not working well with the ‘source’ name, but ‘text’ works . . .mostly. I’ve noticed some differences when including non-alpha/numeric characters too.


#8

I’m not having any luck using the included Ruby on Rails snippets either. I opened app/models/something.rb and added:

class Something < ActiveRecord::Base
  aftc{tab}
end

Which just resulted in a tab, not after_create like I hoped.


#10

Do I need a “snippet configuration” for this? I’m just trying to do what it says in the documentation in the settings for atom/language-ruby-on-rails… Potentially that stuff just isn’t working yet?


#11

Here an example of my working snippets for HTML, CSS, JS and PHP.


#12

@jsanders Here ya go https://gist.github.com/keikun17/9264032#comment-1181855


#13

Oh man, I should have known this. I rarely use HTML so it must have slipped my mind that it uses the text scope.

I can’t see why Php is using text.php though.


#14

@jsanders: I think you’re referring to the grammer ‘Ruby on Rails’ snippets correct? You need to verify that the file’s grammer is set to that and not ‘Ruby’ (ctrl-shift-l, i think…)


#15

What would the syntax for a generic snippet look like? One that could be applied to any document?

I tried starting the snippet with '.*' but that didn’t seem to work.


#16

Probably .text, .source covers everything.


#17

Any idea what I should use for Markdown snippets. Tried all suggest but nothing was working.


#18

Markdown (in Sublime Text) has the text.html.markdown base scope.


#19

Had no luck with that either.


#20

Any luck with ERB files ? Got frustrated when trying to do a simple snippet. If is not possible to aim ERB specifically, at least a generic way to add snippets to all kind of extensions would be good.


#21

in my snippets.cson, i want to require a folder named javascript and has a file named console.cson. you could see the structure below:

--snippets.cson
--javascript
    -- console.cson

Now, in my snippets.cson, i want to include the console.cson to use the snippet I defined in there, What should I do?

I tried with

require './javascript/console.cson'

it output the error

Error reading snippets file '/Users/mma/.atom/snippets.cson': ReferenceError: require is not defined

I figure that it is not a node javascript file, so require is not available in the scope.

Is there a better way that I could lazy load all files inside javascript folder? I could just create new snippet in there, it just reload in atom editor and ready to be used? Thanks in advance!


#22

I managed to get a couple of ERB snippets to work with the following:

'.text.erb':
  'end tag':
    'prefix': 'end'
    'body': '<% end %> $1'

.text.html.erb worked too.