atom / snippets Goto Github PK
View Code? Open in Web Editor NEWAtom snippets package
License: MIT License
Atom snippets package
License: MIT License
Maybe snip<tab>
to expand a snippet template
For example, the language-javascript
package includes 24 default snippets, many of which I have developed alternatives for which better match my coding style.
How can I block this package from polluting the snippets selection I've defined elsewhere?
I have a snippet for expanding Atom range literals bound to ra
.
But when i try to use it here, it doesn't work, presumably due to the prefix including the entire preceding word:
buffer.markRange(ra
Would be nice if this were more forgiving.
In ruby file, I do this:
metrics.sel<tab>
and expect it to trigger this snippet:
https://github.com/atom/language-ruby/blob/master/snippets/language-ruby.cson#L252-L254
but it does not. If I just type sel<tab>
without a preceding "." it expands as expected. Seems like a matching issue of some sort.
Sublime Text provides a default "exit point" for snippets; after the last tab stop, the cursor is moved to the end of the snippet's content. Atom does not appear to have a default exit point for snippets, which means that if you want an exit point in your snippet you have to create it yourself.
Interestingly, the $0
marker that is used in Sublime to override the default exit point does seem to work in Atom.
I want to create a snippets package with several nested folder structure.
snippets
-- javascript
-- my-snippet-code.cson
Currently it did not work, by exam the source code, it is default to the folder path snippets. How could I override the snippet package prototype getUserSnippetsPath function to hack the path variable to be one or two level deep into the snippets folder?
Feature Request:
Variables, whether sourced from the editor, or other packages. One particular use-case are documentation generators; Javadoc snippets would certainly benefit from variables like user name, date, project version, etc., to give an idea.
I'm trying to create the following snippet for use with Event Emitters in Node.js.
'on':
'prefix': 'on'
'body': 'on(\'$1\', function($2) {\n\t$3\n});'
So that typing emitter.on
then hitting tab let's me quickly attach a handler to an event.
I can't seem to get this to work in Atom. I see that another issue was created then closed for (
as whitespace (#23 - notice the most recent comment there), but the ability to add methods with snippets would be spectacular.
❤️
I often have trouble with the available snippet list from command palette not showing the snippets belong to the language of the currently selected tab (even after editing code in that a couple of minutes).
The available snippets always display correctly the first time I use that menu after starting Atom. However, when I change to another tab with a different language, bringing up the available snippets will often (most of the time) still display the snippets for the language in the previous tab. I have managed to get the list to change language, e.g. by changing the order of the open tabs, but the behavior is not entirely predictable.
Do other people have the same issue?
Regards,
Jens Jacob
P.S.: I really, really like this feature, so I hope it is easy to fix.
As far as I can tell this was introduced with the merge that enabled multi-cursor tabstops, if you backspace while editing a tabstop, tab no longer proceeds to the next tabstop, instead inserting a tab.
I must be doing something wrong here:
Contents of snippets.cson:
'.source.js':
'Console log':
'prefix': 'co'
'body': "console.log('$1');"
'.source.js':
'Self log':
'prefix': 'sl'
'body': "self.log('$1', '$2green');"
'.source.js':
'$':
'prefix': '$'
'body': "$('$1')"
Only the last snippet $-tab does anything. The other two do not work. However, whichever snippet I put last will work.
'.source.js':
'Simple Module':
'prefix': 'smod'
'body': """
function ${1:Module} (${2:args}) {
if (!(this instanceof ${1:Module})) return new ${1:Module}(${2:args});
$0
}
module.exports = ${1:Module};
"""
On the 2nd tab the error is triggered, but the interactions and snippet still work. The only issue is the console pops up.
It would be great to propagate the event. Say any random key like "/" forward slash it being bound and it calls "class:method". that Method should have the ability to return true if it should continue propagation or return false to stop propagation. or maybe pass an event object through the method or something.
I was hoping to implement this snippet in atom, but I can't find any support for triggering snippets based on context.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>#{${1:$TM_SELECTED_TEXT}}</string>
<key>keyEquivalent</key>
<string>#</string>
<key>name</key>
<string>Embedded Code — #{…}</string>
<key>scope</key>
<string>B:(string.quoted.double.ruby|string.interpolated.ruby) - string source</string>
<key>uuid</key>
<string>EEE6D060-C5A0-400D-A2E0-0835013C5365</string>
</dict>
</plist>
It will expand #
to #{}
when inside a ruby string without hitting tab. The current migration tool doesn't seem to be able to do this. apm init --package . --convert https://github.com/textmate/ruby.tmbundle
.
Hi, dear snippets team.
I wonder, if it is possible to add a "shift+tab" keybinding as default in atom, so that I can add a tab right after "a" in html instead of expanding it into "a href". This is an idea borrowed from Sublime Text. Of course, I can add it in my preference myself and so I did. But it would be wonderful if this keybinding is there in the first place.
Thank you very much and keep up the good work!!
I would like to support multicaret autocomplete in my snippets>
When you press tab to complete your snippet the first time it would simultaneously select all matching tab indexes in numerical order for insertion. Currently it just advances to the last one instead.
Example Snippet:
"Entity Metadata Wrapper": {
"prefix": "emw",
"body": "$${1:type}_wrapper = entity_metadata_wrapper('${1:type}', $${1:type});"
}
In this case pressing emw would add the completion body and multiselect all 3 $1 labeled replacement areas for editing. If there was a $2 (or multiple ones) it owuld select them after another tab press. im happy to get digging in the source for the package if you can point the right direction as this functionality is a huge timesaver for me and my dev team.
I'm working right now with mustaches - especially includes. The syntax is {{> name }}
. Its not expendable in mustache files - if I change it to source.js
and try it in a .js file it works fine.
'.source.mustache':
'PL: Mustache Include':
'prefix': 'plinc'
'body': '{{> ${1:atoms}-${2:name} }}'
In converting some sublime/textmate snippets, things like TM_FILENAME
are not currently supported. In many cases these can be useful in snippets as placeholders/tab values or just as values within the expanded snippet. For example: https://github.com/robballou/drupal-sublimetext/blob/master/Snippets/hook.sublime-snippet (this snippet will create a function with the filename preprended to the front of the function name).
I noticed in the APM conversion that they are normally replaced with $1
but this won't necessarily be a correct replacement in many cases.
Thanks!
Matches the new pattern of having a single file in the ~/.atom
dir for these things that was previously done for keymaps.
They will break multiple things, like tabstops for example. Escaping them (\\}
) does not solve the problem either.
I have a snippet for creating a new react component:
/** @jsx React.DOM */
var React = require('react');
var $1 = React.createClass({
render: function() {
return (
$2
)
}
});
module.exports = $1;
For me to make this snippet work, this is what it looks like...
'.source.js':
'React Component':
'prefix': 'rcomp'
'body': '/** @jsx React.DOM */\n\nvar React = require(\'react\');\n\nvar $1 = React.createClass({\n render: function() {\n return (\n $2\n )\n }\n});\n\nmodule.exports = $1;'
If I wanted anything more than this, it would be a little unruly... Any ideas on making it a little more reasonable?
To start with, I'm using Windows 8.1 x64, and Atom Editor is currently at 0.120.0 (via chocolatey).
I love using the snippets functionality alt+shift+s
but it doesn't always work, and it always opens the Selection menu on the toolbar first before typing something else to get rid of it to be able to type in the code I wanted to use from my own collection of snippets. Sometimes the snippets drop-down menu doesn't even come up at all, and the Selection menu comes up each time.
I'm wondering if this is an known issue or it's just a matter due to the keybindings being lost in translation from Mac to Windows?
Trying to recreate this snippet in atom. Here is how it looks in textmate 1:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>console.log "$1: ", $1$0</string>
<key>name</key>
<string>console.log with label</string>
<key>scope</key>
<string>source.coffee</string>
<key>tabTrigger</key>
<string>cll</string>
</dict>
</plist>
Here is how it looks in sublime text 2:
<snippet>
<content><![CDATA[
console.log "${1}: ", ${1}
]]></content>
<tabTrigger>cll</tabTrigger>
<scope>source.coffee</scope>
</snippet>
I tried both of these formats in Atom and had no luck getting two placeholders to mirror the same value as I type.
Here are some of the examples I tried:
'Console log extended':
'prefix': 'cll'
'body': 'console.log "${0:hi}: ", ${0:ok}'
'Console log extended':
'prefix': 'cll'
'body': 'console.log "${0}: ", ${0}'
'Console log extended':
'prefix': 'cll'
'body': 'console.log "$1: ", $1$0'
In reference to a problem a user had here:
http://discuss.atom.io/t/how-do-you-configure-use-snippets/335/21?u=d0nkeybob
Within code, you have a way to check if the folder exists, but it only returns null, no matter. Specifically this bit:
getUserSnippetsPath: function() {
var userSnippetsPath;
userSnippetsPath = CSON.resolve(path.join(atom.getConfigDirPath(), 'snippets'));
return userSnippetsPath != null ? userSnippetsPath : path.join(atom.getConfigDirPath(), 'snippets.cson');
},
Does adding a snippets folder not work yet?
It seems an SCSS snippet I've defined isn't triggering (despite another in my file triggering fine). My defined snippets:
Triggering hide
works fine:
Triggering comment
not so much:
Here are the relevant snippets:
'.source.scss':
'Block Comment':
'prefix': 'comment'
'body': '// -----------------------------------------------------------------------------\n * $1\n * ---------------------------------------------------------------------------*/$2'
'.source.scss':
'Screen Reader Content':
'prefix': 'hide'
'body': '.hide {\n\tposition: absolute;\n\ttop: -9999px;\n\tleft: -9999px;\n}'
Extra info:
.text.scss
just for kicks but no changehello,
the set up here is Atom 0.96.0 on a 27" iMac with an intell core i7 processor, 16 GB of RAM, and the latest updates for Mac OS X 10.9.3 Mavericks.
with this set-up, when you launch Atom 0.96.0, and then open the Developer Tools pane (cmd-alt.-i), it shows as the following for language-typescript and snippets -
Error reading snippets file '/Users/yuetsu/.atom/packages/language-typescript/snippets/language-typescript.cson': [stdin]:1:14: error: unexpected end of input
'.source.js':
^ /Applications/Atom.app/Contents/Resources/app/node_modules/snippets/lib/snippets.js:127
so i'm not sure language-typescript and its snippets are ever really loading. please advise on this issue. thank you.
i have also filed this as an issue with @olegbl for their language-typescript package - https://github.com/olegbl/language-typescript/issues/2
best,
— faddah wolf
portland, oregon, u.s.a.
github.com/faddah
See atom/atom#483
Feature Request:
Support for regular expressions, to enable stuff like method name camel-casing, particularly useful for getters and setters.
If I want to activate Ruby Hash Pair, I type :[tab]
But if the cursor is not directly after whitespace, it won't trigger. Examples:
params(:[tab])
my_hash = {:[tab]}
The SnippetExpansion
constructor contains @editor.selectToBeginningOfWord()
method call which is heavily reduces module re-usability.
For example, in Emmet package I want to insert result as snippet to enable tabstops. Since Emmet abbreviations may contain non-word characters, editor.selectToBeginningOfWord()
won’t work for me so I have to remove abbreviation from editor first. But forced selection of word in SnippetExpansion
may select characters that should’t be removed.
I suggest you to remove editor.selectToBeginningOfWord()
call from SnippetExpansion
class and allow package authors to decide how to insert snippet.
Is there a good solution to this? It seems like the only option is to litter the snippet with \n
s, which makes it very ugly and difficult to maintain. Sublime had neat XML files that did not get in the way of formatting. Or am I missing something?
Thanks!
I'm trying to write a snippet for def
in Scala:
'method':
'prefix': 'def'
'body': 'def ${1:method}${2:(${3:arg}: ${4:Type})} = {\n\t$0\n}'
After typing in the method name and hitting tab, the parentheses and arguments should be highlighted, but Atom highlights the most of the method name I typed too (everything but the first character).
Uncaught TypeError: Cannot call method 'getScopes' of undefined /usr/share/atom/resources/app/src/editor.js:583
module.exports.Editor.getCursorScopes /usr/share/atom/resources/app/src/editor.js:583
module.exports.getSnippets /usr/share/atom/resources/app/node_modules/snippets/lib/snippets.js:242
module.exports.SnippetsAvailable.populate /usr/share/atom/resources/app/node_modules/snippets/lib/snippets-available.js:44
module.exports.SnippetsAvailable.toggle /usr/share/atom/resources/app/node_modules/snippets/lib/snippets-available.js:37
(anonymous function) /usr/share/atom/resources/app/node_modules/snippets/lib/snippets.js:205
jQuery.event.dispatch /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4676
elemData.handle /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4360
jQuery.event.trigger /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4594
(anonymous function) /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:5119
jQuery.extend.each /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:590
jQuery.fn.jQuery.each /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:237
jQuery.fn.extend.trigger /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:5118
module.exports.CommandPaletteView.confirmed /usr/share/atom/resources/app/node_modules/command-palette/lib/command-palette-view.js:110
module.exports.SelectListView.confirmSelection /usr/share/atom/resources/app/src/select-list-view.js:269
(anonymous function) /usr/share/atom/resources/app/src/select-list-view.js:108
jQuery.event.dispatch /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4676
elemData.handle /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4360
module.exports.KeymapManager.dispatchCommandEvent /usr/share/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:400
module.exports.KeymapManager.handleKeyboardEvent /usr/share/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:181
(anonymous function) /usr/share/atom/resources/app/src/window-event-handler.js:90
jQuery.event.dispatch /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4676
elemData.handle /usr/share/atom/resources/app/node_modules/space-pen/vendor/jquery.js:4360
Atom version: 0.100.0
OS: Mac OS X 10.9.3
On Sublime Text 3 (ST3) I have a Ruby snippet ruby-class.sublime-snippet
that is triggered by the text "class".
When I start typing "cls" in the context (source) of a Ruby file, an autocomplete list of fuzzy-matched items shows up (see screenshots):
I've been playing with Atom for a little while and I have found this to be a feature I very much miss from ST3. It would be really nice to have fuzzy matching as well as an autocomplete list of matched snippets for the current context/source.
Would be great if it was possible to create multiple snippets with the same prefix which presented a dropdown of the matching snippets upon pressing tab.
Sublime currently behaves this way (though you don't even need to press tab). For example in Sublime if I start typing "backbone" the autocomplete dropdown presents me with the various snippets I have for creating backbone.js Views, Models etc... I don't need to remember a different prefix for each.
I'd like to dynamically include the current date/time in a snippet for markdown.
The snippet would look something like this.
'.source.gfm':
'Header':
'prefix': 'header'
'body': 'My name - `Date.today.strftime('%D')`'
which would print:
My name - 4/2/14
Date.today.strftime('%D') is Ruby, the equivalent js a little longer (unless there's an easier way):
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month++;
var curr_year = d.getFullYear();
console.log(curr_month + "/" + curr_date + "/" + curr_year);
Thoughts?
I originally posted this on the atom forum
I've noticed some problems in creating snippets that revolve around characters like a hyphen or colon punctuation.
This is my test code:
# These snippets don't work
'.text.html':
'Snippet-1':
'prefix': 'sn1'
'body': 'Snippet 1!'
'Snippet 2':
'prefix': 'sn-2'
'body': 'Snippet 2!'
'Snippet 3':
'prefix': 'sn:3'
'body': 'Snippet 3!'
# These snippets work
'.text.html':
'Snippet 4':
'prefix': 'sn4'
'body': 'Snippet 4!'
'Snippet 5':
'prefix': 'sn_5'
'body': 'Snippet 5!'
I also noticied for html scippets, you have to use '.text.html' instead of '.source.html'. When you use the 'snippet' snippet or follow the other examples, it only shows the '.source.' representation.
More on that problem is here:
http://discuss.atom.io/t/how-do-you-configure-use-snippets/335/4
Hope this makes sense. Using certain puncuation helps me categorize my snippets better instead of one full string. I may be a little OCD too.
Thanks.
For example:
In html files, when we type "script" and then hitting tab, we will get the following code:
<script charset="utf-8">
</script>
Now I want to override this native snippet, and I write the following code in snippets.cson:
'.html':
'script':
'prefix': 'script'
'body': """
<script>
$1
</script>
"""
But it does not work.
I believe the snippet for "sp" --> shared_ptr typedef has a superfluous closing curvy bracket at the end.
I don't know if this is a problem syncing my ~/.atom directory, but since last week, my previously-working snippets are no longer working, and if I view the snippet list via the Preferences pane, only the two default snippets are visible, not the ones I've created. For reference, this is my snippets.cson file, in ful:
# 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'
#
'.source.python':
'Django ugettext':
'prefix': '_'
'body': 'from django.utils.translation import ugettext_lazy as _'
'Django login_required':
'prefix': '@login_required'
'body': 'from django.contrib.auth.decorators import login_required'
'Django never_cache':
'prefix': '@never_cache':
'body': 'from django.views.decorators.cache import never_cache'
'.text.html':
'Bootstrap media list':
'prefix': 'medialist'
'body': '<ul class="media-list">\n\t<li class="media">\n\t\t<a class="pull-left" href="#">\n\t\t\t<img class="media-object" src="..." alt="..." />\n\t\t</a>\n\t\t<div class="media-body">\n\t\t\t<h4 class="media-heading">Media heading</h4>\n\t\t\t...\n\t\t</div>\n\t</li>\n</ul>'
Thanks!
Allows you to write snippets and immediately seem them working in the editor
Hi,
I got a strange problem. I have this snippet file:
'.source.js':
'console log':
'prefix': 'log'
'body': 'console.log($1);$2'
'.source.js':
'd3 style':
'prefix': '.style'
'body': '.style("$1",$2)$3'
'.source.js':
'd3 attribute':
'prefix': '.attr'
'body': '.attr("$1",$2)$3'
Currently the .attr
snippet works. The .style
does not.
If I change their place (ctrl-x, ctrl-v the .attr one over the .style one), the .style
does now work,
but the .attr
does not anymore.
When I define a variable in PHP, and my cursor is within the variable '$address' (between the double 's'), or right after the variable '$address' and I hit [tab] the 'snippets:expand' command is triggered:
This is unexpected behavior, since I just wanted a tab being inserted.
From within the '$address'-variable it isn't very likely to occur (the double 's' expansion to <s></s>
), but hitting [tab] right after the variable definition is actually something I do a lot, and probably most do.
Maybe the default keybinding of [tab] to 'snippets:expand' could be changed to something else?
Mac OS X 10.8.5
Atom Version 0.106.0 (0.106.0)
Snippets package: 0.46.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.