Skip to content

Commit cea952a

Browse files
AndreasArvidssonpre-commit-ci-lite[bot]pokey
authored
Community wrapper snippets (#1998)
This is the Cursorless side of the community wrapper snippets talonhub/community#1315 ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <[email protected]>
1 parent 67f2920 commit cea952a

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

src/cursorless.talon

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ tag: user.cursorless
2424
<user.cursorless_wrapper_paired_delimiter> {user.cursorless_wrap_action} <user.cursorless_target>:
2525
user.private_cursorless_wrap_with_paired_delimiter(cursorless_wrap_action, cursorless_target, cursorless_wrapper_paired_delimiter)
2626

27-
{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
28-
user.private_cursorless_insert_snippet(cursorless_insertion_snippet)
29-
30-
{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [{user.cursorless_phrase_terminator}]:
31-
user.private_cursorless_insert_snippet_with_phrase(cursorless_insertion_snippet_single_phrase, text)
32-
33-
{user.cursorless_wrapper_snippet} {user.cursorless_wrap_action} <user.cursorless_target>:
34-
user.private_cursorless_wrap_with_snippet(cursorless_wrap_action, cursorless_target, cursorless_wrapper_snippet)
35-
3627
{user.cursorless_show_scope_visualizer} <user.cursorless_scope_type> [{user.cursorless_visualization_type}]:
3728
user.private_cursorless_show_scope_visualizer(cursorless_scope_type, cursorless_visualization_type or "content")
3829
{user.cursorless_hide_scope_visualizer}:

src/snippet_cursorless.talon

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mode: command
2+
mode: user.cursorless_spoken_form_test
3+
tag: user.cursorless
4+
and not tag: user.cursorless_use_community_snippets
5+
-
6+
7+
{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
8+
user.private_cursorless_insert_snippet(cursorless_insertion_snippet)
9+
10+
{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [{user.cursorless_phrase_terminator}]:
11+
user.private_cursorless_insert_snippet_with_phrase(cursorless_insertion_snippet_single_phrase, text)
12+
13+
{user.cursorless_wrapper_snippet} {user.cursorless_wrap_action} <user.cursorless_target>:
14+
user.private_cursorless_wrap_with_snippet(cursorless_wrap_action, cursorless_target, cursorless_wrapper_snippet)

src/snippets.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ class InsertionSnippet:
1616
destination: CursorlessDestination
1717

1818

19+
@dataclass
20+
class CommunityInsertionSnippet:
21+
body: str
22+
scopes: list[str] = None
23+
24+
25+
@dataclass
26+
class CommunityWrapperSnippet:
27+
body: str
28+
variable_name: str
29+
scope: str = None
30+
31+
1932
mod = Module()
2033

2134
mod.list("cursorless_insert_snippet_action", desc="Cursorless insert snippet action")
@@ -27,6 +40,11 @@ class InsertionSnippet:
2740
desc="tag for enabling experimental snippet support",
2841
)
2942

43+
mod.tag(
44+
"cursorless_use_community_snippets",
45+
"If active use community snippets instead of Cursorless snippets",
46+
)
47+
3048
mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")
3149
mod.list(
3250
"cursorless_insertion_snippet_no_phrase",
@@ -181,3 +199,21 @@ def cursorless_wrap_with_snippet(
181199
snippet_arg,
182200
target,
183201
)
202+
203+
def private_cursorless_insert_community_snippet(
204+
name: str, destination: CursorlessDestination
205+
):
206+
"""Cursorless: Insert community snippet <name>"""
207+
snippet: CommunityInsertionSnippet = actions.user.get_insertion_snippet(name)
208+
actions.user.cursorless_insert_snippet(
209+
snippet.body, destination, snippet.scopes
210+
)
211+
212+
def private_cursorless_wrap_with_community_snippet(
213+
name: str, target: CursorlessTarget
214+
):
215+
"""Cursorless: Wrap target with community snippet <name>"""
216+
snippet: CommunityWrapperSnippet = actions.user.get_wrapper_snippet(name)
217+
actions.user.cursorless_wrap_with_snippet(
218+
snippet.body, target, snippet.variable_name, snippet.scope
219+
)

src/snippets_community.talon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mode: command
2+
mode: user.cursorless_spoken_form_test
3+
tag: user.cursorless
4+
and tag: user.cursorless_use_community_snippets
5+
-
6+
7+
# These snippets are defined in community
8+
9+
{user.cursorless_insert_snippet_action} {user.snippet} <user.cursorless_destination>:
10+
user.private_cursorless_insert_community_snippet(snippet, cursorless_destination)
11+
12+
{user.snippet_wrapper} {user.cursorless_wrap_action} <user.cursorless_target>:
13+
user.private_cursorless_wrap_with_community_snippet(snippet_wrapper, cursorless_target)

0 commit comments

Comments
 (0)