Skip to content

Commit

Permalink
git subrepo pull --remote=file:///Users/pokey/src/cursorless-talon-de…
Browse files Browse the repository at this point in the history
…velopment --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"
  • Loading branch information
pokey committed Apr 25, 2022
1 parent ec1a5aa commit e6eb3f9
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 47 deletions.
1 change: 1 addition & 0 deletions cursorless-talon/src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def vscode_command_no_wait(command_id: str, target: dict, command_options: dict
"swap_action": {"swap": "swapTargets"},
"move_bring_action": {"bring": "replaceWithTarget", "move": "moveToTarget"},
"wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"},
"insert_snippet_action": {"snippet": "insertSnippet"},
"reformat_action": {"format": "applyFormatter"},
}

Expand Down
40 changes: 1 addition & 39 deletions cursorless-talon/src/actions/wrap.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
from typing import Any

from talon import Context, Module, actions, app
from talon import Module, actions

from ..csv_overrides import init_csv_and_watch_changes
from ..paired_delimiter import paired_delimiters_map

mod = Module()

mod.tag(
"cursorless_experimental_snippets",
desc="tag for enabling experimental snippet support",
)

mod.list("cursorless_wrap_action", desc="Cursorless wrap action")
mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")

experimental_snippets_ctx = Context()
experimental_snippets_ctx.matches = r"""
tag: user.cursorless_experimental_snippets
"""


# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/cursorless-dev/cursorless-vscode/blob/main/docs/user/customization.md
wrapper_snippets = {
"else": "ifElseStatement.alternative",
"if else": "ifElseStatement.consequence",
"if": "ifStatement.consequence",
"try": "tryCatchStatement.body",
"link": "link.text",
}


@mod.capture(
Expand Down Expand Up @@ -72,18 +49,3 @@ def cursorless_wrap(action_type: str, targets: dict, cursorless_wrapper: dict):
actions.user.cursorless_single_target_command_with_arg_list(
action, targets, cursorless_wrapper["extra_args"]
)


def on_ready():
init_csv_and_watch_changes(
"experimental/wrapper_snippets",
{
"wrapper_snippet": wrapper_snippets,
},
allow_unknown_values=True,
default_list_name="wrapper_snippet",
ctx=experimental_snippets_ctx,
)


app.register("ready", on_ready)
19 changes: 11 additions & 8 deletions cursorless-talon/src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from talon import Module, actions, speech_system

from .primitive_target import IMPLICIT_TARGET

mod = Module()

last_phrase = None
Expand Down Expand Up @@ -46,18 +48,19 @@ def cursorless_single_target_command_no_wait(
action, [target], arg1, arg2, arg3
)

def cursorless_single_target_command_with_arg_list(
action: str, target: str, args: list[Any]
def cursorless_this_command(
action: str,
arg1: Any = NotSet,
arg2: Any = NotSet,
arg3: Any = NotSet,
):
"""Execute single-target cursorless command with argument list"""
actions.user.cursorless_single_target_command(
action,
target,
*args,
"""Execute cursorless command, passing `this` as single target"""
actions.user.cursorless_multiple_target_command(
action, [IMPLICIT_TARGET], arg1, arg2, arg3
)

def cursorless_single_target_command_with_arg_list(
action: str, target: str, args: list[Any]
action: str, target: dict, args: list[Any]
):
"""Execute single-target cursorless command with argument list"""
actions.user.cursorless_single_target_command(
Expand Down
12 changes: 12 additions & 0 deletions cursorless-talon/src/cursorless-snippets.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
app: vscode
tag: user.cursorless_experimental_snippets
-

{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet>:
user.cursorless_this_command(cursorless_insert_snippet_action, cursorless_insertion_snippet)

{user.cursorless_insert_snippet_action} <user.cursorless_insertion_snippet> <user.cursorless_target>:
user.cursorless_single_target_command(cursorless_insert_snippet_action, cursorless_target, cursorless_insertion_snippet)

{user.cursorless_insert_snippet_action} {user.cursorless_insertion_snippet_single_phrase} <user.text> [halt]:
user.cursorless_insert_snippet_with_phrase(cursorless_insert_snippet_action, cursorless_insertion_snippet_single_phrase, text)
109 changes: 109 additions & 0 deletions cursorless-talon/src/snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from talon import Module, actions, app, Context
from .csv_overrides import init_csv_and_watch_changes

mod = Module()
mod.list("cursorless_insert_snippet_action", desc="Cursorless insert snippet action")

mod.tag(
"cursorless_experimental_snippets",
desc="tag for enabling experimental snippet support",
)

mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet")
mod.list(
"cursorless_insertion_snippet_no_phrase",
desc="Cursorless insertion snippets that don't accept a phrase",
)
mod.list(
"cursorless_insertion_snippet_single_phrase",
desc="Cursorless insertion snippet that can accept a single phrase",
)


@mod.capture(
rule="{user.cursorless_insertion_snippet_no_phrase} | {user.cursorless_insertion_snippet_single_phrase}"
)
def cursorless_insertion_snippet(m) -> str:
try:
return m.cursorless_insertion_snippet_no_phrase
except AttributeError:
pass

return m.cursorless_insertion_snippet_single_phrase.split(".")[0]


experimental_snippets_ctx = Context()
experimental_snippets_ctx.matches = r"""
tag: user.cursorless_experimental_snippets
"""


# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
wrapper_snippets = {
"else": "ifElseStatement.alternative",
"funk": "functionDeclaration.body",
"if else": "ifElseStatement.consequence",
"if": "ifStatement.consequence",
"try": "tryCatchStatement.body",
"link": "link.text",
}

# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
insertion_snippets_no_phrase = {
"if": "ifStatement",
"if else": "ifElseStatement",
"try": "tryCatchStatement",
}

# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md
insertion_snippets_single_phrase = {
"funk": "functionDeclaration.name",
}


@mod.action_class
class Actions:
def cursorless_insert_snippet_with_phrase(
action: str, snippet_description: str, text: str
):
"""Perform cursorless wrap action"""
snippet_name, snippet_variable = snippet_description.split(".")
actions.user.cursorless_this_command(
action, snippet_name, {snippet_variable: text}
)


def on_ready():
init_csv_and_watch_changes(
"experimental/wrapper_snippets",
{
"wrapper_snippet": wrapper_snippets,
},
allow_unknown_values=True,
default_list_name="wrapper_snippet",
ctx=experimental_snippets_ctx,
)
init_csv_and_watch_changes(
"experimental/insertion_snippets",
{
"insertion_snippet_no_phrase": insertion_snippets_no_phrase,
},
allow_unknown_values=True,
default_list_name="insertion_snippet_no_phrase",
ctx=experimental_snippets_ctx,
)
init_csv_and_watch_changes(
"experimental/insertion_snippets_single_phrase",
{
"insertion_snippet_single_phrase": insertion_snippets_single_phrase,
},
allow_unknown_values=True,
default_list_name="insertion_snippet_single_phrase",
ctx=experimental_snippets_ctx,
)


app.register("ready", on_ready)

0 comments on commit e6eb3f9

Please sign in to comment.