You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 8, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+78-18Lines changed: 78 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Snippets files are stored in a package's `snippets/` folder and also loaded from
18
18
19
19
The outermost keys are the selectors where these snippets should be active, prefixed with a period (`.`) (details below).
20
20
21
-
The next level of keys are the snippet names.
21
+
The next level of keys are the snippet names. Because this is object notation, each snippet must have a different name.
22
22
23
23
Under each snippet name is a `body` to insert when the snippet is triggered.
24
24
@@ -32,24 +32,26 @@ console.log("crash");
32
32
33
33
The string `"crash"` would be initially selected and pressing tab again would place the cursor after the `;`
34
34
35
-
A snippet must define**at least one** of the following keys:
35
+
A snippet specifies how it can be triggered. Thus it must provide**at least one** of the following keys:
36
36
37
37
### The ‘prefix’ key
38
38
39
-
If a `prefix` is defined, it specifies a string that can trigger the snippet: type the string in the editor and press <kbd>Tab</kbd>. In this example, typing `log` (as its own word) and then pressing <kbd>Tab</kbd> would replace `log` with the string `console.log("crash")` as described above.
39
+
If a `prefix` is defined, it specifies a string that can trigger the snippet. In the above example, typing `log` (as its own word) and then pressing <kbd>Tab</kbd> would replace `log` with the string `console.log("crash")` as described above.
40
40
41
41
Prefix completions can be suggested if partially typed thanks to the `autocomplete-snippets` package.
42
42
43
43
### The ‘command’ key
44
44
45
45
If a `command` is defined, it specifies a command name that can trigger the snippet. That command can be invoked from the command palette or mapped to a keyboard shortcut via your `keymap.cson`.
46
46
47
-
If you defined the `console.log` snippet described above in your own `snippets.cson`, it would be available in the command palette as “Snippets: Insert Console Log”, or could be referenced in a keymap file as `snippets:insert-console-log`.
47
+
If a package called `some-package` had defined that snippet, it would be available in the keymap as `some-package:insert-console-log`, or in the command palette as **Some Package: Insert Console Log**.
48
48
49
-
If a package called `some-package` had defined that snippet, it would be available in the keymap as `some-package:insert-console-log`, or in the command palette as “Some Package: Insert Console Log”.
49
+
If you defined the `console.log` snippet described above in your own `snippets.cson`, it could be referenced in a keymap file as `snippets:insert-console-log`, or in the command palette as **Snippets: Insert Console Log**.
50
50
51
51
Invoking the command would insert the snippet at the cursor, replacing any text that may be selected.
52
52
53
+
Snippet command names must be unique. They can’t conflict with each other, nor can they conflict with any other commands that have been defined. If there is such a conflict, you’ll see an error notification describing the problem.
54
+
53
55
### Optional parameters
54
56
55
57
These parameters are meant to provide extra information about your snippet to [autocomplete-plus](https://github.com/atom/autocomplete-plus/wiki/Provider-API).
@@ -74,24 +76,76 @@ Example:
74
76
75
77
### Determining the correct scope for a snippet
76
78
77
-
The outmost key of a snippet is the "scope" that you want the descendent snippets to be available in. The key should be prefixed with a period (`text.html.basic`=>`.text.html.basic`). You can find out the correct scope by opening the Settings (<kbd>cmd-,</kbd> on macOS) and selecting the corresponding *Language [xxx]* package, e.g. for *Language Html*:
79
+
The outmost key of a snippet is the “scope” that you want the descendent snippets to be available in. The key should be prefixed with a period (`text.html.basic`→`.text.html.basic`). You can find out the correct scope by opening the Settings (<kbd>cmd-,</kbd> on macOS) and selecting the corresponding *Language [xxx]* package. For example, here’s the settings page for `language-html`:
78
80
79
81

80
82
81
-
If it's difficult to determine the package handling the file type in question (for example, for `.md`-documents), you can also proceed as following. Put your cursor in a file in which you want the snippet to be available, open the [Command Palette](https://github.com/pulsar-edit/command-palette)
82
-
(<kbd>cmd-shift-p</kbd>), and run the `Editor: Log Cursor Scope` command. This will trigger a notification which will contain a list of scopes. The first scope that's listed is the scope for that language. Here are some examples: `source.coffee`, `text.plain`, `text.html.basic`.
83
+
If it's difficult to determine the package handling the file type in question (for example, for `.md`-documents), you can use another approach:
84
+
85
+
1. Put your cursor in a file in which you want the snippet to be available.
86
+
2. Open the [Command Palette](https://github.com/pulsar-edit/command-palette)
87
+
(<kbd>cmd-shift-p</kbd> or <kbd>ctrl-shift-p</kbd>).
88
+
3. Run the `Editor: Log Cursor Scope` command.
89
+
90
+
This will trigger a notification which will contain a list of scopes. The first scope that's listed is the scope for that language. Here are some examples: `source.coffee`, `text.plain`, `text.html.basic`.
91
+
92
+
## Snippet syntax
93
+
94
+
This package supports a subset of the features of TextMate snippets, [documented here](http://manual.macromates.com/en/snippets), as well as most features described in the [LSP specification][lsp] and [supported by VSCode][vscode].
95
+
96
+
The following features from TextMate snippets are not yet supported:
97
+
98
+
* Interpolated shell code can’t reliably be supported cross-platform, and is probably a bad idea anyway. No other editors that support snippets have adopted this feature, and Pulsar won’t either.
99
+
100
+
The following features from VSCode snippets are not yet supported:
101
+
102
+
* “Choice” syntax like `${1|one,two,three|}` requires that the autocomplete engine pop up a menu to offer the user a choice between the available placeholder options. This may be supported in the future, but right now Pulsar effectively converts this to `${1:one}`, treating the first choice as a conventional placeholder.
103
+
104
+
### Variables
105
+
106
+
Pulsar snippets support all of the variables mentioned in the [LSP specification][lsp], plus many of the variables [supported by VSCode][vscode].
107
+
108
+
Variables can be referenced with `$`, either without braces (`$CLIPBOARD`) or with braces (`${CLIPBOARD}`). Variables can also have fallback values (`${CLIPBOARD:http://example.com}`), simple flag-based transformations (`${CLIPBOARD:/upcase}`), or `sed`-style transformations `${CLIPBOARD/ /_/g}`.
83
109
84
-
### Snippet syntax
110
+
One of the most useful is `TM_SELECTED_TEXT`, which represents whatever text was selected when the snippet was invoked. (Naturally, this can only happen when a snippet is invoked via command or key shortcut, rather than by typing in a <kbd>Tab</kbd> trigger.)
85
111
86
-
This package supports a subset of the features of TextMate snippets, [documented here](http://manual.macromates.com/en/snippets#transformations).
112
+
Others that can be useful:
87
113
88
-
The following features are not yet supported:
114
+
*`TM_FILENAME`: The name of the current file (`foo.rb`).
115
+
*`TM_FILENAME_BASE`: The name of the current file, but without its extension (`foo`).
116
+
*`TM_FILEPATH`: The entire path on disk to the current file.
117
+
*`TM_CURRENT_LINE`: The entire current line that the cursor is sitting on.
118
+
*`TM_CURRENT_WORD`: The entire word that the cursor is within or adjacent to, as interpreted by `cursor.getCurrentWordBufferRange`.
119
+
*`CLIPBOARD`: The current contents of the clipboard.
120
+
*`CURRENT_YEAR`, `CURRENT_MONTH`, et cetera: referneces to the current date and time in various formats.
89
121
90
-
* Variables
91
-
* Interpolated shell code
92
-
* Conditional insertions in transformations
122
+
Any variable that has no value — for instance, `TM_FILENAME` on an untitled document — will resolve to an empty string.
93
123
94
-
### Multi-line Snippet Body
124
+
#### Variable transformation flags
125
+
126
+
Pulsar supports the three flags defined in the [LSP snippets specification][lsp] and two other flags that are [implemented in VSCode][vscode]:
127
+
128
+
*`/upcase` (`foo` → `FOO`)
129
+
*`/downcase` (`BAR` → `bar`)
130
+
*`/capitalize` (`lorem ipsum dolor` → `Lorem ipsum dolor`)
*`WORKSPACE_NAME`, `WORKSPACE_FOLDER`, and `RELATIVE_PATH` all rely on the presence of a root project folder, but a Pulsar project can technically have multiple root folders. While this is rare, it is handled by `snippets` as follows: whichever project path is an ancestor of the currently active file is treated as the project root — or the first one found if multiple roots are ancestors.
137
+
*`WORKSPACE_NAME` in VSCode refers to “the name of the opened workspace or folder.” In the former case, this appears to mean bundled projects with a `.code-workspace` file extension — which have no Pulsar equivalent. Instead, `WORKSPACE_NAME` will always refer to the last path component of your project’s root directory as defined above.
138
+
139
+
#### Variables that are not yet supported
140
+
141
+
Of the variables supported by VSCode, Pulsar does not yet support:
142
+
143
+
*`UUID`
144
+
*`BLOCK_COMMENT_START`
145
+
*`BLOCK_COMMENT_END`
146
+
*`LINE_COMMENT`
147
+
148
+
## Multi-line Snippet Body
95
149
96
150
You can also use multi-line syntax using `"""` for larger templates:
97
151
@@ -110,7 +164,7 @@ You can also use multi-line syntax using `"""` for larger templates:
110
164
"""
111
165
```
112
166
113
-
###Escaping Characters
167
+
## Escaping Characters
114
168
115
169
Including a literal closing brace inside the text provided by a snippet's tab stop will close that tab stop early. To prevent that, escape the brace with two backslashes, like so:
116
170
@@ -127,6 +181,12 @@ Including a literal closing brace inside the text provided by a snippet's tab st
127
181
"""
128
182
```
129
183
130
-
### Multiple snippets for the same scope
184
+
Likewise, if your snippet includes literal references to `$` or `{`, you may have to escape those with two backslashes as well, depending on the context.
185
+
186
+
## Multiple snippets for the same scope
187
+
188
+
Snippets for the same scope must be placed within the same key. See [this section of the Pulsar Flight Manual](https://pulsar-edit.dev/docs/launch-manual/sections/using-pulsar/#configuring-with-cson) for more information.
189
+
131
190
132
-
Snippets for the same scope must be placed within the same key. See [this section of the Atom Flight Manual](https://pulsar-edit.dev/docs/atom-archive/using-atom/#configuring-with-cson) for more information.
0 commit comments