Skip to content

Commit 4c6fc54

Browse files
Added reformat action to public api (#2358)
## Checklist - [/] 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>
1 parent 6d3c244 commit 4c6fc54

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
tags: [enhancement]
3+
pullRequest: 2358
4+
---
5+
6+
- Added public `user.cursorless_reformat` action to the Cursorless api
7+
eg: `user.cursorless_reformat(cursorless_target, "ALL_CAPS")`

cursorless-talon/src/actions/reformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@mod.action_class
1616
class Actions:
17-
def private_cursorless_reformat(
17+
def cursorless_reformat(
1818
target: CursorlessExplicitTarget, # pyright: ignore [reportGeneralTypeIssues]
1919
formatters: str,
2020
):

cursorless-talon/src/cursorless.talon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tag: user.cursorless
1616
user.private_cursorless_paste(cursorless_destination)
1717

1818
{user.cursorless_reformat_action} <user.formatters> at <user.cursorless_target>:
19-
user.private_cursorless_reformat(cursorless_target, formatters)
19+
user.cursorless_reformat(cursorless_target, formatters)
2020

2121
{user.cursorless_call_action} <user.cursorless_target> on <user.cursorless_target>:
2222
user.private_cursorless_call(cursorless_target_1, cursorless_target_2)

docs/user/customization.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ Cursorless exposes a couple talon actions and captures that you can use to defin
158158
- `user.cursorless_insert(destination: CursorlessDestination, text: Union[str, List[str]])`:
159159
Insert text at destination.
160160
eg: `user.cursorless_insert(cursorless_destination, "hello")`
161+
- `user.cursorless_reformat(target: CursorlessTarget, formatters: str)`
162+
Reformat target with specified formatters.
163+
eg: `user.cursorless_reformat(cursorless_target, "ALL_CAPS")`
161164

162165
#### Snippet actions
163166

@@ -180,6 +183,16 @@ push <user.cursorless_target> down:
180183
user.cursorless_ide_command("editor.action.moveLinesDownAction", cursorless_target)
181184
```
182185

186+
### Example of custom formatter command
187+
188+
The below command will allow you to say `camel form blue air`.
189+
_You can disable the default Cursorless reformat command by prefixing the spoken form in `actions.csv` with a dash. `-format, applyFormatter`_
190+
191+
```talon
192+
<user.formatters> form <user.cursorless_target>:
193+
user.cursorless_reformat(cursorless_target, formatters)
194+
```
195+
183196
### Disable legacy destination grammar
184197

185198
The grammar currently supports `paste to before air`. This grammar is considered deprecated/legacy and replaced by `paste before air`. You can today disable this legacy grammar by enabling the tag `user.cursorless_disable_legacy_destination`

0 commit comments

Comments
 (0)