Skip to content

Commit fcca9ae

Browse files
AndreasArvidssonpre-commit-ci-lite[bot]auscompgeekpokey
authored
Added argument to call action (#1900)
`call air on bat` ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] 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: David Vo <[email protected]> Co-authored-by: Pokey Rule <[email protected]>
1 parent 1f21a49 commit fcca9ae

File tree

6 files changed

+43
-15
lines changed

6 files changed

+43
-15
lines changed

src/actions/actions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
ImplicitDestination,
99
)
1010
from .bring_move import BringMoveTargets
11-
from .call import cursorless_call_action
1211
from .execute_command import cursorless_execute_command_action
1312
from .homophones import cursorless_homophones_action
1413
from .replace import cursorless_replace_action
@@ -44,11 +43,11 @@
4443
"wrap_action",
4544
"insert_snippet_action",
4645
"reformat_action",
46+
"call_action",
4747
"experimental_action",
4848
]
4949

5050
callback_actions: dict[str, Callable[[CursorlessTarget], None]] = {
51-
"callAsFunction": cursorless_call_action,
5251
"findInDocument": actions.user.private_cursorless_find,
5352
"nextHomophone": cursorless_homophones_action,
5453
}
@@ -70,6 +69,7 @@
7069
"{user.cursorless_simple_action} |"
7170
"{user.cursorless_experimental_action} |"
7271
"{user.cursorless_callback_action} |"
72+
"{user.cursorless_call_action} |"
7373
"{user.cursorless_custom_action}"
7474
)
7575
)
@@ -96,6 +96,8 @@ def cursorless_command(action_name: str, target: CursorlessTarget):
9696
actions.user.private_cursorless_bring_move(
9797
action_name, BringMoveTargets(target, ImplicitDestination())
9898
)
99+
elif action_name == "callAsFunction":
100+
actions.user.private_cursorless_call(target)
99101
elif action_name in no_wait_actions:
100102
action = {"name": action_name, "target": target}
101103
actions.user.private_cursorless_command_no_wait(action)

src/actions/call.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
from talon import actions
1+
from talon import Module, actions
22

33
from ..targets.target_types import CursorlessTarget, ImplicitTarget
44

5+
mod = Module()
6+
mod.list("cursorless_call_action", desc="Cursorless call action")
57

6-
def cursorless_call_action(target: CursorlessTarget):
7-
actions.user.private_cursorless_command_and_wait(
8-
{
9-
"name": "callAsFunction",
10-
"callee": target,
11-
"argument": ImplicitTarget(),
12-
}
13-
)
8+
9+
@mod.action_class
10+
class Actions:
11+
def private_cursorless_call(
12+
callee: CursorlessTarget,
13+
argument: CursorlessTarget = ImplicitTarget(),
14+
):
15+
"""Execute Cursorless call action"""
16+
actions.user.private_cursorless_command_and_wait(
17+
{
18+
"name": "callAsFunction",
19+
"callee": callee,
20+
"argument": argument,
21+
}
22+
)

src/cheatsheet/sections/actions.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def get_actions():
1212
"moveToTarget",
1313
"swapTargets",
1414
"applyFormatter",
15+
"callAsFunction",
1516
"wrapWithPairedDelimiter",
1617
"rewrap",
1718
"pasteFromClipboard",
@@ -34,7 +35,6 @@ def get_actions():
3435
"action",
3536
simple_actions,
3637
{
37-
"callAsFunction": "Call <target> on selection",
3838
"editNewLineAfter": "Edit new line/scope after",
3939
"editNewLineBefore": "Edit new line/scope before",
4040
},
@@ -101,6 +101,20 @@ def get_actions():
101101
}
102102
],
103103
},
104+
{
105+
"id": "callAsFunction",
106+
"type": "action",
107+
"variations": [
108+
{
109+
"spokenForm": f"{complex_actions['callAsFunction']} <target>",
110+
"description": "Call <target> on selection",
111+
},
112+
{
113+
"spokenForm": f"{complex_actions['callAsFunction']} <target 1> on <target 2>",
114+
"description": "Call <target 1> on <target 2>",
115+
},
116+
],
117+
},
104118
{
105119
"id": "wrapWithPairedDelimiter",
106120
"type": "action",

src/cursorless.talon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ tag: user.cursorless
1818
{user.cursorless_reformat_action} <user.formatters> at <user.cursorless_target>:
1919
user.private_cursorless_reformat(cursorless_target, formatters)
2020

21+
{user.cursorless_call_action} <user.cursorless_target> on <user.cursorless_target>:
22+
user.private_cursorless_call(cursorless_target_1, cursorless_target_2)
23+
2124
<user.cursorless_wrapper_paired_delimiter> {user.cursorless_wrap_action} <user.cursorless_target>:
2225
user.private_cursorless_wrap_with_paired_delimiter(cursorless_wrap_action, cursorless_target, cursorless_wrapper_paired_delimiter)
2326

src/spoken_forms.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"unfold": "unfoldRegion"
4444
},
4545
"callback_action": {
46-
"call": "callAsFunction",
4746
"scout": "findInDocument",
4847
"phones": "nextHomophone"
4948
},
@@ -55,7 +54,8 @@
5554
"swap_action": { "swap": "swapTargets" },
5655
"wrap_action": { "wrap": "wrapWithPairedDelimiter", "repack": "rewrap" },
5756
"insert_snippet_action": { "snippet": "insertSnippet" },
58-
"reformat_action": { "format": "applyFormatter" }
57+
"reformat_action": { "format": "applyFormatter" },
58+
"call_action": { "call": "callAsFunction" }
5959
},
6060
"target_connectives.csv": {
6161
"range_connective": {

src/spoken_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def update():
5454
for disposable in disposables:
5555
disposable()
5656

57-
with open(JSON_FILE) as file:
57+
with open(JSON_FILE, encoding="utf-8") as file:
5858
spoken_forms = json.load(file)
5959

6060
handle_csv = auto_construct_defaults(spoken_forms, init_csv_and_watch_changes)

0 commit comments

Comments
 (0)