Identifying Features for Sublime Text 2 Custom Snippets

When trying to write my own snippets for Sublime Text 2, I ran into the following two problems:

  • Search for scope keys . I realized that I can browse my packages one by one and find links to the declared "scope" property. For example, in ~/Library/Application Support/Sublime Text 2/Packages/JavaScript/Comments.tmPreferences (the file in my HTML package) there are two lines:

     <key>scope</key> <string>source.js</string> 

    So, if I want my current fragment to work with javascript files, I define my scope as follows:

     <scope>source.js</scope> 

    I assume that all of these scope keys are defined on the fly based on which packages I installed. Does Sublime Text list anywhere I can more easily link to? Listening through a bunch of package files seems too tedious.

  • Defining properties of several areas . I understood this, and the next line allows my fragment to work both in HTML files and in JavaScript.

     <scope>text.html, source.js</scope> 
+61
scope sublimetext2 code-snippets
Dec 17 '12 at 21:05
source share
5 answers

View current cursor position volume

  • Place the cursor in the file where you want to know the scope.
  • Use this key combination:

    Windows : ctrl + shift + alt + p
    Mac: ctrl + shift + p

  • The current area will be displayed on the left side of the status bar on Windows or in a popup window on Mac.

Use them as <scope> in your foo.sublime-snippet file.

The returned areas are listed as general to specific. Select the area (s) that is best "attached" to the fragment where it should be available to start the tab.

+72
Apr 09 '13 at 19:49
source share

The following is a list of areas used in Sublime Text 2 snippets -

 ActionScript: source.actionscript.2 AppleScript: source.applescript ASP: source.asp Batch FIle: source.dosbatch C#: source.cs C++: source.c++ Clojure: source.clojure CoffeeScript: source.coffee CSS: source.css D: source.d Diff: source.diff Erlang: source.erlang Go: source.go GraphViz: source.dot Groovy: source.groovy Haskell: source.haskell HTML: text.html(.basic) JSP: text.html.jsp Java: source.java Java Properties: source.java-props Java Doc: text.html.javadoc JSON: source.json Javascript: source.js BibTex: source.bibtex Latex Log: text.log.latex Latex Memoir: text.tex.latex.memoir Latex: text.tex.latex LESS: source.css.less TeX: text.tex Lisp: source.lisp Lua: source.lua MakeFile: source.makefile Markdown: text.html.markdown Multi Markdown: text.html.markdown.multimarkdown Matlab: source.matlab Objective-C: source.objc Objective-C++: source.objc++ OCaml campl4: source.camlp4.ocaml OCaml: source.ocaml OCamllex: source.ocamllex Perl: source.perl PHP: source.php Regular Expression(python): source.regexp.python Python: source.python R Console: source.r-console R: source.r Ruby on Rails: source.ruby.rails Ruby HAML: text.haml SQL(Ruby): source.sql.ruby Regular Expression: source.regexp RestructuredText: text.restructuredtext Ruby: source.ruby SASS: source.sass Scala: source.scala Shell Script: source.shell SQL: source.sql Stylus: source.stylus TCL: source.tcl HTML(TCL): text.html.tcl Plain text: text.plain Textile: text.html.textile XML: text.xml XSL: text.xml.xsl YAML: source.yaml 

If something is missing, add it to this gist https://gist.github.com/4705378 .

+144
Feb 04 '13 at 7:39
source share

There is a package called Scope Hunter , Isaac Muse , which is really useful for this.

It can display the scope under any cursor in the document, which I found very useful in debugging my own fragments. Sometimes it is very detailed; sample area from my first document:

 Scope: text.tex.latex meta.function.environment.list.latex meta.function.environment.general.latex meta.function.environment.math.latex string.other.math.block.environment.latex meta.group.braces.tex meta.space-after-command.latex 

(Wrapped for readability)

I would not be able to find this if I spent a week choosing SL2, but this package gets it in seconds. Highly recommended.

This level of detail also means that you can define fragments in a very granular way if you want. For example, meta.function.environment.list.latex generally matches lists in LaTeX, so I have a snippet that inserts a new \item when I press super + enter in the list environment, but no one else. I can orient fragments much more efficiently than blind guesses.

The source code on Github , or you can install it through Package Management .

+9
May 24 '13 at 10:36
source share

In fact, you can use Ctrl + Alt + Shift + P (without using Scope Hunter), and it will show you the area in the lower panel on the left side after the Col / Line information. It's a pretty small print, but it's there.

+7
Dec 25 '13 at 8:52
source share

To answer # 1, look in the syntax .tmLanguage file, find the key: scopeName . This is what syntax uses for the value of the snapshot region.

For example, an excerpt from nathos / sass-textmate-bundle

 <key>scopeName</key> <string>source.sass</string> 

So, you would use source.sass in your fragment.

More on syntax definition

+5
Feb 08 '13 at 22:23
source share



All Articles