Skip to content

Commit c2fb509

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 5c069e3 commit c2fb509

File tree

13 files changed

+108
-21
lines changed

13 files changed

+108
-21
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
tags: [enhancement, talon]
3+
pullRequest: 1900
4+
---
5+
6+
- Added optional second target to action `call` to specify argument. eg: `"call air on bat"`.

cursorless-talon/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)

cursorless-talon/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+
)

cursorless-talon/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",

cursorless-talon/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

cursorless-talon/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": {

cursorless-talon/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)

packages/cheatsheet/src/lib/sampleSpokenFormInfos/defaults.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
{
2222
"spokenForm": "call <target>",
2323
"description": "Call <target> on selection"
24+
},
25+
{
26+
"spokenForm": "call <target 1> on <target 2>",
27+
"description": "Call <target 1> on <target 2>"
2428
}
2529
]
2630
},
@@ -1188,6 +1192,16 @@
11881192
}
11891193
]
11901194
},
1195+
{
1196+
"id": "command",
1197+
"type": "scopeType",
1198+
"variations": [
1199+
{
1200+
"spokenForm": "command",
1201+
"description": "Command"
1202+
}
1203+
]
1204+
},
11911205
{
11921206
"id": "comment",
11931207
"type": "scopeType",

packages/cursorless-engine/src/generateSpokenForm/generateSpokenForm.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ function generateSpokenFormComponents(
7676
];
7777

7878
case "callAsFunction":
79-
if (action.argument != null) {
80-
throw new NoSpokenFormError(`Action '${action.name}' with argument`);
79+
if (action.argument.type === "implicit") {
80+
return [actions[action.name], targetToSpokenForm(action.callee)];
8181
}
8282
return [
8383
actions[action.name],
8484
targetToSpokenForm(action.callee),
85-
// targetToSpokenForm(action.argument),
85+
"on",
86+
targetToSpokenForm(action.argument),
8687
];
8788

8889
case "wrapWithPairedDelimiter":

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/callFine.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ command:
77
- type: primitive
88
mark: {type: decoratedSymbol, symbolColor: default, character: f}
99
- {type: primitive, isImplicit: true}
10-
spokenFormError: Action 'callAsFunction' with argument
1110
initialState:
1211
documentContents: |-
1312
foo;

0 commit comments

Comments
 (0)