Comments (15)
Would a PR be accepted that added these vars?
- files
- ${dirname} => /root/proj/lib
- ${filename} => /root/proj/lib/main.coffee
- ${basename} => main.coffee
- ${extname} => .coffee
- ${sep} => /
- ${deliminator} => :
- ${package} => /root/proj
- ${dirnamerel} => lib
- ${filenamerel} => lib/main.coffee
- date & times (Note the colon)
- ${:any-moment-format} current time in any format provided by the
moment
npm package- ${:MMMM Do YYYY, h:mm:ss a} => November 22nd 2014, 2:24:26 am
- ${:dddd} => Saturday
- ${:MMM Do YY} => Nov 22nd 14
- ${:any-moment-format} current time in any format provided by the
- positioning -- these variables always show an empty string
- ${top} => insert entire snippet at top of file
- ${bottom} => insert entire snippet at bottom of file
- ${12} => insert such that top line of snippet is on line 12
- ${cursor-3} => insert such that top line of snippet is 3 lines above cursor
- Package.json (note the exclamation mark)
- ${!path:in:project:json} Shows value from project.json file
- ${!name} => moment
- ${!version} => 2.8.4
- ${!repository:url} => https://github.com/moment/moment.git
- ${!path:in:project:json} Shows value from project.json file
from snippets.
Another idea for variables I desperately need: ${clipboard}
Let's say I have a need to generate for my Rails project something as follows:
# GET
# /resource
def index
end
# POST
# /resource
def create
end
# PATCH
# /resource/:id
def update
end
# DELETE
# /resource/:id
def destroy
end
Let's say, I typed users
, copied that text into clipboard, and
if I had an access to the clipboard with that very text, I would get ready-to-use code blocks like follows:
# DELETE
# /users/:id
def destroy
end
and for copied teams
:
# DELETE
# /teams/:id
def destroy
end
With the following snippet:
'DELETE':
'prefix': 'delete'
'body': """
# DELETE
# /${clipboard}/:id
def destroy
end
"""
from snippets.
Just to add another idea (I admit, one that I desperately need and did not find) would be the selected text [1]. I would love to mark something, press a hotkey and encapsulate the selected text.
In Gedit it is possible with something like that: \emph{${1:$GEDIT_SELECTED_TEXT}}$0
for LaTeX.
May this be done with this plugin?
[1] https://wiki.gnome.org/Apps/Gedit/Plugins/Snippets
from snippets.
My guess is that this never got prioritized because there are ways of achieving the same effect via commands.
For instance, if you're trying to replicate TextMate's $TM_SELECTED_TEXT
variable, you could do something like this in your init file:
// WRAP IN HTML TAG
atom.commands.add('atom-text-editor', {
'custom:wrap-in-html-tag': () => {
let editor = atom.workspace.getActiveTextEditor();
let selection = editor.getLastSelection();
let snippet = atom.packages.activePackages.snippets.mainModule;
snippet.insert('<${1:div}>' + selection.getText() + '</${1:div}>');
}
});
So this feels like one of those features where anyone who knows Atom well enough to write the PR also knows alternative strategies for these use cases. But that's not an argument against the feature β just a description of how we got here.
I'd happily accept a PR. Looks like VS Code has implemented snippet variables also, so I'd be cool with a PR that added all (or a meaningful subset of) the variables on their list. Might as well standardize.
If anyone wants to take a stab at this, I can probably help them through some of the tricky parts, like changing the parser grammar.
from snippets.
See #83
Edit: @Brandon-Grimshaw, you wouldn't want to help test this, would you? (grin)
from snippets.
π for the ${clipboard}
variable.
from snippets.
+1 for clipboard as well
some basic features that sublime has taken care of over the years but are essential to proper macro building
from snippets.
+1 clipboard xD
from snippets.
Clipboard!!!
from snippets.
+1 for clipboard as well
from snippets.
+1 for clipboard
from snippets.
The lack of variables like this is one of the biggest missing features that prevent me from switching from TM2 to Atom.
As a maker of snippets that use this type of variables, I would advise the addition of some transformation capabilities. For instance a snippet I use in TM2 looks like this
module Processes
module ${TM_DIRECTORY/(?:\A|.+\/|_)([A-Za-z0-9]+)(?:\.[a-z]+)*/(?2::\u$1)/g}
class ${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.[a-z]+)*/(?2::\u$1)/g}
$0
end
end
end
Sure, that's not pretty at all, but with a file named client_accounts/list_all.rb
it would make
module Processes
module ClientAccounts
class ListAll
end
end
end
You can't imagine the time I save with this kind of nuggets but the ability to transform the folder and filename values is key.
Cheers π
from snippets.
What happened to this?
from snippets.
// WRAP IN HTML TAG atom.commands.add('atom-text-editor', { 'custom:wrap-in-html-tag': () => { let editor = atom.workspace.getActiveTextEditor(); let selection = editor.getLastSelection(); let snippet = atom.packages.activePackages.snippets.mainModule; snippet.insert('<${1:div}>' + selection.getText() + '</${1:div}>'); } });
I tried pasting it in init file and error appear "Reserved word let" What should be issue?
from snippets.
I tried pasting it in init file and error appear "Reserved word let" What should be issue?
I donβt know; I pasted that code snippet into my init.js
just now and it worked fine. Try the forums or the Slack channel for tech support.
from snippets.
Related Issues (20)
- snippet not working without spaces between characters HOT 6
- Documentation: description of finding snippet scope does not work HOT 5
- Implement $0 as a snippet exit point (Γ la TextMate or Sublime Text) HOT 4
- <unknown> is deprecated. HOT 1
- Replace snippet starting with backslash does not work HOT 3
- Multi-cursor, multi-line snippets have indents eaten when certain characters are input HOT 2
- Loading of Snippets on start up HOT 1
- Make snippets LSP compliant HOT 1
- Project Based Snippets HOT 2
- Add highlighting to non-selected placeholders HOT 1
- Custom snippets added to snippets.cson do not load HOT 3
- Snippets Trigger while Typing in Tab Stops HOT 6
- Snippets with variable HOT 2
- Autocomplet is not working at all for me HOT 6
- Shift Tab Moves Contents Of Buffer
- Snippet not working without space. HOT 1
- Snippets inside snippets HOT 1
- Wrap selection HOT 3
- Failed to load the snippets package
- Failed to load the snippets package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snippets.