Skip to content

Commit 278f188

Browse files
AndreasArvidssonpre-commit-ci-lite[bot]pokey
authored
Move default spoken forms to json file (#1738)
` 2713 passing (6s)` Fixes #1737 ## 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) - [x] 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 16973f8 commit 278f188

23 files changed

+508
-667
lines changed

cursorless-talon/src/actions/actions.py

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,62 @@
1-
from talon import Module, actions, app
1+
from talon import Module, actions
22

3-
from ..csv_overrides import init_csv_and_watch_changes
43
from ..targets.target_types import CursorlessTarget, ImplicitDestination
5-
from .actions_callback import callback_action_defaults, callback_action_map
6-
from .actions_simple import (
7-
no_wait_actions,
8-
no_wait_actions_post_sleep,
9-
simple_action_defaults,
10-
)
114
from .bring_move import BringMoveTargets
5+
from .call import cursorless_call_action
126
from .execute_command import cursorless_execute_command_action
7+
from .homophones import cursorless_homophones_action
138

149
mod = Module()
1510

1611

17-
mod.list("cursorless_experimental_action", "Experimental actions")
12+
mod.list(
13+
"cursorless_simple_action",
14+
desc="Cursorless internal: simple actions",
15+
)
16+
17+
mod.list(
18+
"cursorless_callback_action",
19+
desc="Cursorless internal: actions implemented via a callback function",
20+
)
21+
22+
mod.list(
23+
"cursorless_custom_action",
24+
desc="Cursorless internal: user-defined custom actions",
25+
)
26+
27+
mod.list(
28+
"cursorless_experimental_action",
29+
desc="Cursorless internal: experimental actions",
30+
)
31+
32+
ACTION_LIST_NAMES = [
33+
"simple_action",
34+
"callback_action",
35+
"paste_action",
36+
"bring_move_action",
37+
"swap_action",
38+
"wrap_action",
39+
"insert_snippet_action",
40+
"reformat_action",
41+
"experimental_action",
42+
]
43+
44+
callback_actions = {
45+
"callAsFunction": cursorless_call_action,
46+
"findInDocument": actions.user.private_cursorless_find,
47+
"nextHomophone": cursorless_homophones_action,
48+
}
49+
50+
# Don't wait for these actions to finish, usually because they hang on some kind of user interaction
51+
no_wait_actions = [
52+
"generateSnippet",
53+
"rename",
54+
]
55+
56+
# These are actions that we don't wait for, but still want to have a post action sleep
57+
no_wait_actions_post_sleep = {
58+
"rename": 0.3,
59+
}
1860

1961

2062
@mod.capture(
@@ -42,8 +84,8 @@ def cursorless_action_or_ide_command(m) -> dict:
4284
class Actions:
4385
def cursorless_command(action_name: str, target: CursorlessTarget):
4486
"""Perform cursorless command on target"""
45-
if action_name in callback_action_map:
46-
callback_action_map[action_name](target)
87+
if action_name in callback_actions:
88+
callback_actions[action_name](target)
4789
elif action_name in ["replaceWithTarget", "moveToTarget"]:
4890
actions.user.cursorless_bring_move(
4991
action_name, BringMoveTargets(target, ImplicitDestination())
@@ -79,33 +121,3 @@ def private_cursorless_action_or_ide_command(
79121
actions.user.cursorless_command(value, target)
80122
elif type == "ide_command":
81123
actions.user.cursorless_ide_command(value, target)
82-
83-
84-
default_values = {
85-
"simple_action": simple_action_defaults,
86-
"callback_action": callback_action_defaults,
87-
"paste_action": {"paste": "pasteFromClipboard"},
88-
"bring_move_action": {"bring": "replaceWithTarget", "move": "moveToTarget"},
89-
"swap_action": {"swap": "swapTargets"},
90-
"wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"},
91-
"insert_snippet_action": {"snippet": "insertSnippet"},
92-
"reformat_action": {"format": "applyFormatter"},
93-
}
94-
95-
96-
ACTION_LIST_NAMES = list(default_values.keys()) + ["experimental_action"]
97-
98-
99-
def on_ready() -> None:
100-
init_csv_and_watch_changes("actions", default_values)
101-
init_csv_and_watch_changes(
102-
"experimental/experimental_actions",
103-
{
104-
"experimental_action": {
105-
"-from": "experimental.setInstanceReference",
106-
}
107-
},
108-
)
109-
110-
111-
app.register("ready", on_ready)

cursorless-talon/src/actions/actions_callback.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

cursorless-talon/src/actions/actions_custom.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

cursorless-talon/src/actions/actions_simple.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

cursorless-talon/src/actions/wrap.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from talon import Module, actions
22

3-
from ..paired_delimiter import PairedDelimiter
43
from ..targets.target_types import CursorlessTarget
54

65
mod = Module()
@@ -11,7 +10,7 @@
1110
@mod.action_class
1211
class Actions:
1312
def private_cursorless_wrap_with_paired_delimiter(
14-
action_name: str, target: CursorlessTarget, paired_delimiter: PairedDelimiter
13+
action_name: str, target: CursorlessTarget, paired_delimiter: list[str]
1514
):
1615
"""Execute Cursorless wrap/rewrap with paired delimiter action"""
1716
if action_name == "rewrap":
@@ -20,8 +19,8 @@ def private_cursorless_wrap_with_paired_delimiter(
2019
actions.user.private_cursorless_command_and_wait(
2120
{
2221
"name": action_name,
23-
"left": paired_delimiter.left,
24-
"right": paired_delimiter.right,
22+
"left": paired_delimiter[0],
23+
"right": paired_delimiter[1],
2524
"target": target,
2625
}
2726
)

cursorless-talon/src/connective.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

cursorless-talon/src/marks/lines_number.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
from dataclasses import dataclass
33
from typing import Any
44

5-
from talon import Context, Module
5+
from talon import Module
66

77
from ..targets.range_target import RangeConnective
88

99
mod = Module()
10-
ctx = Context()
1110

1211
mod.list("cursorless_line_direction", desc="Supported directions for line modifier")
1312

1413

1514
@dataclass
1615
class CustomizableTerm:
17-
defaultSpokenForm: str
1816
cursorlessIdentifier: str
1917
type: str
2018
formatter: Callable
@@ -23,17 +21,12 @@ class CustomizableTerm:
2321
# NOTE: Please do not change these dicts. Use the CSVs for customization.
2422
# See https://www.cursorless.org/docs/user/customization/
2523
directions = [
26-
CustomizableTerm(
27-
"row", "lineNumberModulo100", "modulo100", lambda number: number - 1
28-
),
29-
CustomizableTerm("up", "lineNumberRelativeUp", "relative", lambda number: -number),
30-
CustomizableTerm(
31-
"down", "lineNumberRelativeDown", "relative", lambda number: number
32-
),
24+
CustomizableTerm("lineNumberModulo100", "modulo100", lambda number: number - 1),
25+
CustomizableTerm("lineNumberRelativeUp", "relative", lambda number: -number),
26+
CustomizableTerm("lineNumberRelativeDown", "relative", lambda number: number),
3327
]
3428

3529
directions_map = {d.cursorlessIdentifier: d for d in directions}
36-
DEFAULT_DIRECTIONS = {d.defaultSpokenForm: d.cursorlessIdentifier for d in directions}
3730

3831

3932
@mod.capture(

0 commit comments

Comments
 (0)