Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit bf01cbb

Browse files
committed
How to find out the correct scope (selector)
Added findings from https://discuss.atom.io/t/how-do-you-configure-use-snippets/335/28
1 parent 8d5bab4 commit bf01cbb

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Snippet files can be either `.json` or `.cson`.
1818
'body': 'console.log(${1:"crash"});$2'
1919
```
2020

21-
The outermost keys are the selectors where this snippets should be active.
21+
The outermost keys are the selectors where this snippets should be active (details below).
2222

2323
The next level of keys are the snippet names.
2424

@@ -56,3 +56,50 @@ You can also use multi-line syntax using `"""` for larger templates:
5656
}
5757
"""
5858
```
59+
60+
### Finding out the correct selector (scope) for a snippet
61+
62+
The outmost key of a snippet is the "scope" that you want the descendent snippets to be available in. To determine the scope of a language, do:
63+
64+
* Open a file of the type for which you want to add a snippet
65+
* Open the Developer Tools (<kbd>Cmd+Alt+I</kbd> on OS X)
66+
* Switch to the Console tab
67+
* Focus the source file and execute the _Editor > Log Cursor Scope_ command (<kbd>Cmd+Alt+P</kbd> on OS X)
68+
69+
The first entry in the array that is logged to the Console is the scope for that language.
70+
71+
If you have special characters (like `+`) in the scope, you have to escape them:
72+
73+
```coffee
74+
.source.c, .source.c\\+\\+, .source.objc, .source.objc\\+\\+':
75+
...
76+
```
77+
78+
### Multiple snippets for the same scope
79+
80+
Since the `snippets.cson` file describes one single object, snippets for the same selector must be placed within the same key, so that would work:
81+
82+
```coffee
83+
'.source.gfm': # The selector for "markdown" (.md) files
84+
'Preformatted text':
85+
'prefix': 'pre'
86+
'body': '`$1`'
87+
88+
'Strikethrough':
89+
'prefix': 'strike'
90+
'body': '~~$1~~'
91+
```
92+
93+
While this apperently not:
94+
95+
```coffee
96+
'.source.gfm': # This one is used
97+
'Preformatted text':
98+
'prefix': 'pre'
99+
'body': '`$1`'
100+
101+
'.source.gfm': # Second declaration of the same key, ignored
102+
'Strikethrough':
103+
'prefix': 'strike'
104+
'body': '~~$1~~'
105+
```

0 commit comments

Comments
 (0)