Skip to content

Commit

Permalink
Community wrapper snippets (#1998)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored Apr 21, 2024
1 parent 67f2920 commit cea952a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/cursorless.talon
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ tag: user.cursorless
<user.cursorless_wrapper_paired_delimiter> {user.cursorless_wrap_action} <user.cursorless_target>:
user.private_cursorless_wrap_with_paired_delimiter(cursorless_wrap_action, cursorless_target, cursorless_wrapper_paired_delimiter)

{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
user.private_cursorless_insert_snippet(cursorless_insertion_snippet)

{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [{user.cursorless_phrase_terminator}]:
user.private_cursorless_insert_snippet_with_phrase(cursorless_insertion_snippet_single_phrase, text)

{user.cursorless_wrapper_snippet} {user.cursorless_wrap_action} <user.cursorless_target>:
user.private_cursorless_wrap_with_snippet(cursorless_wrap_action, cursorless_target, cursorless_wrapper_snippet)

{user.cursorless_show_scope_visualizer} <user.cursorless_scope_type> [{user.cursorless_visualization_type}]:
user.private_cursorless_show_scope_visualizer(cursorless_scope_type, cursorless_visualization_type or "content")
{user.cursorless_hide_scope_visualizer}:
Expand Down
14 changes: 14 additions & 0 deletions src/snippet_cursorless.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mode: command
mode: user.cursorless_spoken_form_test
tag: user.cursorless
and not tag: user.cursorless_use_community_snippets
-

{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
user.private_cursorless_insert_snippet(cursorless_insertion_snippet)

{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [{user.cursorless_phrase_terminator}]:
user.private_cursorless_insert_snippet_with_phrase(cursorless_insertion_snippet_single_phrase, text)

{user.cursorless_wrapper_snippet} {user.cursorless_wrap_action} <user.cursorless_target>:
user.private_cursorless_wrap_with_snippet(cursorless_wrap_action, cursorless_target, cursorless_wrapper_snippet)
36 changes: 36 additions & 0 deletions src/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ class InsertionSnippet:
destination: CursorlessDestination


@dataclass
class CommunityInsertionSnippet:
body: str
scopes: list[str] = None


@dataclass
class CommunityWrapperSnippet:
body: str
variable_name: str
scope: str = None


mod = Module()

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

mod.tag(
"cursorless_use_community_snippets",
"If active use community snippets instead of Cursorless snippets",
)

mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")
mod.list(
"cursorless_insertion_snippet_no_phrase",
Expand Down Expand Up @@ -181,3 +199,21 @@ def cursorless_wrap_with_snippet(
snippet_arg,
target,
)

def private_cursorless_insert_community_snippet(
name: str, destination: CursorlessDestination
):
"""Cursorless: Insert community snippet <name>"""
snippet: CommunityInsertionSnippet = actions.user.get_insertion_snippet(name)
actions.user.cursorless_insert_snippet(
snippet.body, destination, snippet.scopes
)

def private_cursorless_wrap_with_community_snippet(
name: str, target: CursorlessTarget
):
"""Cursorless: Wrap target with community snippet <name>"""
snippet: CommunityWrapperSnippet = actions.user.get_wrapper_snippet(name)
actions.user.cursorless_wrap_with_snippet(
snippet.body, target, snippet.variable_name, snippet.scope
)
13 changes: 13 additions & 0 deletions src/snippets_community.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mode: command
mode: user.cursorless_spoken_form_test
tag: user.cursorless
and tag: user.cursorless_use_community_snippets
-

# These snippets are defined in community

{user.cursorless_insert_snippet_action} {user.snippet} <user.cursorless_destination>:
user.private_cursorless_insert_community_snippet(snippet, cursorless_destination)

{user.snippet_wrapper} {user.cursorless_wrap_action} <user.cursorless_target>:
user.private_cursorless_wrap_with_community_snippet(snippet_wrapper, cursorless_target)

0 comments on commit cea952a

Please sign in to comment.