Skip to content

Commit 70df673

Browse files
committed
git subrepo pull --remote=file:///Users/pokey/src/cursorless-talon-development --branch=insert-snippet cursorless-talon
subrepo: subdir: "cursorless-talon" merged: "61eb0b55" upstream: origin: "file:///Users/pokey/src/cursorless-talon-development" branch: "insert-snippet" commit: "61eb0b55" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596"
1 parent 99a9123 commit 70df673

File tree

5 files changed

+133
-47
lines changed

5 files changed

+133
-47
lines changed

cursorless-talon/src/actions/actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def vscode_command_no_wait(command_id: str, target: dict, command_options: dict
8787
"swap_action": {"swap": "swapTargets"},
8888
"move_bring_action": {"bring": "replaceWithTarget", "move": "moveToTarget"},
8989
"wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"},
90+
"insert_snippet_action": {"snippet": "insertSnippet"},
9091
"reformat_action": {"format": "applyFormatter"},
9192
}
9293

cursorless-talon/src/actions/wrap.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
11
from typing import Union
22
from ..paired_delimiter import paired_delimiters_map
3-
from talon import Module, actions, app, Context
4-
from ..csv_overrides import init_csv_and_watch_changes
3+
from talon import Module, actions
54

65

76
mod = Module()
87

9-
mod.tag(
10-
"cursorless_experimental_snippets",
11-
desc="tag for enabling experimental snippet support",
12-
)
13-
148
mod.list("cursorless_wrap_action", desc="Cursorless wrap action")
15-
mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")
16-
17-
experimental_snippets_ctx = Context()
18-
experimental_snippets_ctx.matches = r"""
19-
tag: user.cursorless_experimental_snippets
20-
"""
21-
22-
23-
# NOTE: Please do not change these dicts. Use the CSVs for customization.
24-
# See https://github.com/cursorless-dev/cursorless-vscode/blob/main/docs/user/customization.md
25-
wrapper_snippets = {
26-
"else": "ifElseStatement.alternative",
27-
"if else": "ifElseStatement.consequence",
28-
"if": "ifStatement.consequence",
29-
"try": "tryCatchStatement.body",
30-
"link": "link.text",
31-
}
329

3310

3411
@mod.capture(
@@ -71,18 +48,3 @@ def cursorless_wrap(action_type: str, targets: dict, cursorless_wrapper: dict):
7148
actions.user.cursorless_single_target_command_with_arg_list(
7249
action, targets, cursorless_wrapper["extra_args"]
7350
)
74-
75-
76-
def on_ready():
77-
init_csv_and_watch_changes(
78-
"experimental/wrapper_snippets",
79-
{
80-
"wrapper_snippet": wrapper_snippets,
81-
},
82-
allow_unknown_values=True,
83-
default_list_name="wrapper_snippet",
84-
ctx=experimental_snippets_ctx,
85-
)
86-
87-
88-
app.register("ready", on_ready)

cursorless-talon/src/command.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from talon import actions, Module, speech_system
22
from typing import Any
3+
from .primitive_target import IMPLICIT_TARGET
34

45
mod = Module()
56

@@ -45,18 +46,19 @@ def cursorless_single_target_command_no_wait(
4546
action, [target], arg1, arg2, arg3
4647
)
4748

48-
def cursorless_single_target_command_with_arg_list(
49-
action: str, target: str, args: list[Any]
49+
def cursorless_this_command(
50+
action: str,
51+
arg1: Any = NotSet,
52+
arg2: Any = NotSet,
53+
arg3: Any = NotSet,
5054
):
51-
"""Execute single-target cursorless command with argument list"""
52-
actions.user.cursorless_single_target_command(
53-
action,
54-
target,
55-
*args,
55+
"""Execute cursorless command, passing `this` as single target"""
56+
actions.user.cursorless_multiple_target_command(
57+
action, [IMPLICIT_TARGET], arg1, arg2, arg3
5658
)
5759

5860
def cursorless_single_target_command_with_arg_list(
59-
action: str, target: str, args: list[Any]
61+
action: str, target: dict, args: list[Any]
6062
):
6163
"""Execute single-target cursorless command with argument list"""
6264
actions.user.cursorless_single_target_command(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
app: vscode
2+
tag: user.cursorless_experimental_snippets
3+
-
4+
5+
{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
6+
user.cursorless_this_command(cursorless_insert_snippet_action, cursorless_insertion_snippet)
7+
8+
{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet> <user.cursorless_target>:
9+
user.cursorless_single_target_command(cursorless_insert_snippet_action, cursorless_target, cursorless_insertion_snippet)
10+
11+
{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [halt]:
12+
user.cursorless_insert_snippet_with_phrase(cursorless_insert_snippet_action, cursorless_insertion_snippet_single_phrase, text)

cursorless-talon/src/snippets.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from talon import Module, actions, app, Context
2+
from .csv_overrides import init_csv_and_watch_changes
3+
4+
mod = Module()
5+
mod.list("cursorless_insert_snippet_action", desc="Cursorless insert snippet action")
6+
7+
mod.tag(
8+
"cursorless_experimental_snippets",
9+
desc="tag for enabling experimental snippet support",
10+
)
11+
12+
mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")
13+
mod.list(
14+
"cursorless_insertion_snippet_no_phrase",
15+
desc="Cursorless insertion snippets that don't accept a phrase",
16+
)
17+
mod.list(
18+
"cursorless_insertion_snippet_single_phrase",
19+
desc="Cursorless insertion snippet that can accept a single phrase",
20+
)
21+
22+
23+
@mod.capture(
24+
rule="{user.cursorless_insertion_snippet_no_phrase} | {user.cursorless_insertion_snippet_single_phrase}"
25+
)
26+
def cursorless_insertion_snippet(m) -> str:
27+
try:
28+
return m.cursorless_insertion_snippet_no_phrase
29+
except AttributeError:
30+
pass
31+
32+
return m.cursorless_insertion_snippet_single_phrase.split(".")[0]
33+
34+
35+
experimental_snippets_ctx = Context()
36+
experimental_snippets_ctx.matches = r"""
37+
tag: user.cursorless_experimental_snippets
38+
"""
39+
40+
41+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
42+
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
43+
wrapper_snippets = {
44+
"else": "ifElseStatement.alternative",
45+
"funk": "functionDeclaration.body",
46+
"if else": "ifElseStatement.consequence",
47+
"if": "ifStatement.consequence",
48+
"try": "tryCatchStatement.body",
49+
"link": "link.text",
50+
}
51+
52+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
53+
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
54+
insertion_snippets_no_phrase = {
55+
"if": "ifStatement",
56+
"if else": "ifElseStatement",
57+
"try": "tryCatchStatement",
58+
}
59+
60+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
61+
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
62+
insertion_snippets_single_phrase = {
63+
"funk": "functionDeclaration.name",
64+
}
65+
66+
67+
@mod.action_class
68+
class Actions:
69+
def cursorless_insert_snippet_with_phrase(
70+
action: str, snippet_description: str, text: str
71+
):
72+
"""Perform cursorless wrap action"""
73+
snippet_name, snippet_variable = snippet_description.split(".")
74+
actions.user.cursorless_this_command(
75+
action, snippet_name, {snippet_variable: text}
76+
)
77+
78+
79+
def on_ready():
80+
init_csv_and_watch_changes(
81+
"experimental/wrapper_snippets",
82+
{
83+
"wrapper_snippet": wrapper_snippets,
84+
},
85+
allow_unknown_values=True,
86+
default_list_name="wrapper_snippet",
87+
ctx=experimental_snippets_ctx,
88+
)
89+
init_csv_and_watch_changes(
90+
"experimental/insertion_snippets",
91+
{
92+
"insertion_snippet_no_phrase": insertion_snippets_no_phrase,
93+
},
94+
allow_unknown_values=True,
95+
default_list_name="insertion_snippet_no_phrase",
96+
ctx=experimental_snippets_ctx,
97+
)
98+
init_csv_and_watch_changes(
99+
"experimental/insertion_snippets_single_phrase",
100+
{
101+
"insertion_snippet_single_phrase": insertion_snippets_single_phrase,
102+
},
103+
allow_unknown_values=True,
104+
default_list_name="insertion_snippet_single_phrase",
105+
ctx=experimental_snippets_ctx,
106+
)
107+
108+
109+
app.register("ready", on_ready)

0 commit comments

Comments
 (0)