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
* Initial working version
* Working draft
* Fixes
* Allow user snippets
* Cleanup
* Add docs and make experimental
* Switch to tag to enable experimental support
* tweak snippet name
* Fix docs
* Doc fix
* More doc
* Doc
* New snippets; fix watcher
* Use `.` instead of `/` for snippet placeholders
* Update docs
* Fix link in docs
* Change tag name
* Update docs
Here we document features which are currently considered experimental. They are generally functional and well tested, but the API is subject change.
4
+
5
+
## Wrapper snippets
6
+
7
+

8
+
9
+
In addition to wrapping with paired delimiters (eg `"square wrap"`, `"round wrap"`, etc), we experimentally support wrapping with snippets. Cursorless ships with a few built-in snippets, but users can also use their own snippets.
10
+
11
+
### Enabling wrapper snippets
12
+
13
+
Add the following line to the end of your `settings.talon` (or any other `.talon` file that will be active when vscode is focused):
14
+
15
+
```
16
+
tag(): user.cursorless_experimental_snippets
17
+
```
18
+
19
+
### Using wrapper snippets
20
+
21
+
#### Command syntax
22
+
23
+
The command syntax is as follows:
24
+
25
+
```
26
+
"<snippet_name> wrap <target>"
27
+
```
28
+
29
+
#### Examples
30
+
31
+
-`"try wrap air"`: Wrap the statement containing the marked `a` in a try-catch statement
32
+
-`"try wrap air past bat"`: Wrap the sequence of statements from the marked `a` to the marked `b` in a try-catch statement
33
+
34
+
#### Default scope types
35
+
36
+
Each snippet wrapper has a default scope type. When you refer to a target, by default it will expand to the given scope type. This way, for example, when you say `"try wrap air"`, it will refer to the statement containing `a` rather than just the token.
37
+
38
+
### Built-in wrapper snippets
39
+
40
+
| Default spoken form | Snippet | Default target scope type |
|`"if else wrap"`| If-else statement; target goes in if branch | Statement |
45
+
|`"try wrap"`| Try-catch statement | Statement |
46
+
47
+
### Customizing spoken forms
48
+
49
+
As usual, the spoken forms for these wrapper snippets can be [customized by csv](customization.md). The csvs are in the file `cursorless-settings/experimental/wrapper_snippets.csv`.
50
+
51
+
### Adding your own snippets
52
+
53
+
To define your own wrapper snippets, proceed as follows:
54
+
55
+
#### Define snippets in vscode
56
+
57
+
1. Set the `cursorless.experimental.snippetsDir` setting to a directory in which you'd like to create your snippets.
58
+
2. Add snippets to the directory in files ending in `.cursorless-snippets`. See the [documentation](https://github.com/pokey/cursorless-vscode/tree/main/docs/experimental/snippets.md) for the cursorless snippet format.
59
+
60
+
#### 2. Add snippet to spoken forms csv
61
+
62
+
For each snippet that you'd like to be able to use as a wrapper snippet, add a line to the `cursorless-settings/experimental/wrapper_snippets.csv` csv overrides file. The first column is the desired spoken form, and the second column is of the form `<name>.<variable>`, where `name` is the name of the snippet (ie the key in your snippet json file), and `variable` is one of the placeholder variables in your snippet where the target should go.
63
+
64
+
### Customizing built-in snippets
65
+
66
+
To customize a built-in snippet, just define a custom snippet (as above), but
67
+
use the same name as the cursorless core snippet you'd like to change, and give
68
+
definitions along with scopes where you'd like your override to be active. Here
69
+
is an example:
70
+
71
+
```json
72
+
{
73
+
"tryCatchStatement": {
74
+
"definitions": [
75
+
{
76
+
"scope": {
77
+
"langIds": [
78
+
"typescript",
79
+
"typescriptreact",
80
+
"javascript",
81
+
"javascriptreact"
82
+
]
83
+
},
84
+
"body": [
85
+
"try {",
86
+
"\t$body",
87
+
"} catch (err) {",
88
+
"\t$exceptBody",
89
+
"}"
90
+
]
91
+
}
92
+
]
93
+
}
94
+
}
95
+
```
96
+
97
+
The above will change the definition of the try-catch statement in typescript.
0 commit comments