Skip to content

Commit 974cd8a

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 877eb29 commit 974cd8a

File tree

6 files changed

+136
-50
lines changed

6 files changed

+136
-50
lines changed

cursorless-talon/.gitrepo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
55
;
66
[subrepo]
7-
remote = https://github.com/cursorless-dev/cursorless-talon.git
8-
branch = main
9-
commit = afa65b88397984b3a9e66702550beaadd23a3f00
10-
parent = bfd4097f4ac0eeaf4db325a05ad238c845cdcaac
7+
remote = file:///Users/pokey/src/cursorless-talon-development
8+
branch = insert-snippet
9+
commit = 61eb0b5502ebb1afbc24dddeda2ee1d81791dc3d
10+
parent = 877eb297a0aa209cbe1a65d3a5bf089f0d351dcd
1111
method = merge
1212
cmdver = 0.4.3

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 & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +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/pokey/cursorless-talon/blob/main/docs/customization.md
25-
wrapper_snippets = {
26-
"else": "ifElseStatement.alternative",
27-
"if else": "ifElseStatement.consequence",
28-
"if": "ifStatement.consequence",
29-
"try": "tryCatchStatement.body",
30-
}
319

3210

3311
@mod.capture(
@@ -70,18 +48,3 @@ def cursorless_wrap(action_type: str, targets: dict, cursorless_wrapper: dict):
7048
actions.user.cursorless_single_target_command_with_arg_list(
7149
action, targets, cursorless_wrapper["extra_args"]
7250
)
73-
74-
75-
def on_ready():
76-
init_csv_and_watch_changes(
77-
"experimental/wrapper_snippets",
78-
{
79-
"wrapper_snippet": wrapper_snippets,
80-
},
81-
allow_unknown_values=True,
82-
default_list_name="wrapper_snippet",
83-
ctx=experimental_snippets_ctx,
84-
)
85-
86-
87-
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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
}
50+
51+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
52+
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
53+
insertion_snippets_no_phrase = {
54+
"if": "ifStatement",
55+
"if else": "ifElseStatement",
56+
"try": "tryCatchStatement",
57+
}
58+
59+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
60+
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
61+
insertion_snippets_single_phrase = {
62+
"funk": "functionDeclaration.name",
63+
}
64+
65+
66+
@mod.action_class
67+
class Actions:
68+
def cursorless_insert_snippet_with_phrase(
69+
action: str, snippet_description: str, text: str
70+
):
71+
"""Perform cursorless wrap action"""
72+
snippet_name, snippet_variable = snippet_description.split(".")
73+
actions.user.cursorless_this_command(
74+
action, snippet_name, {snippet_variable: text}
75+
)
76+
77+
78+
def on_ready():
79+
init_csv_and_watch_changes(
80+
"experimental/wrapper_snippets",
81+
{
82+
"wrapper_snippet": wrapper_snippets,
83+
},
84+
allow_unknown_values=True,
85+
default_list_name="wrapper_snippet",
86+
ctx=experimental_snippets_ctx,
87+
)
88+
init_csv_and_watch_changes(
89+
"experimental/insertion_snippets",
90+
{
91+
"insertion_snippet_no_phrase": insertion_snippets_no_phrase,
92+
},
93+
allow_unknown_values=True,
94+
default_list_name="insertion_snippet_no_phrase",
95+
ctx=experimental_snippets_ctx,
96+
)
97+
init_csv_and_watch_changes(
98+
"experimental/insertion_snippets_single_phrase",
99+
{
100+
"insertion_snippet_single_phrase": insertion_snippets_single_phrase,
101+
},
102+
allow_unknown_values=True,
103+
default_list_name="insertion_snippet_single_phrase",
104+
ctx=experimental_snippets_ctx,
105+
)
106+
107+
108+
app.register("ready", on_ready)

0 commit comments

Comments
 (0)