@@ -18,7 +18,7 @@ Snippet files can be either `.json` or `.cson`.
18
18
' body' : ' console.log(${1:"crash"});$2'
19
19
```
20
20
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) .
22
22
23
23
The next level of keys are the snippet names.
24
24
@@ -56,3 +56,50 @@ You can also use multi-line syntax using `"""` for larger templates:
56
56
}
57
57
"""
58
58
```
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