Skip to content

Commit

Permalink
Added reformat action to public api (#2358)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
1 parent 6d3c244 commit 4c6fc54
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions changelog/2024-05-reformatPublicAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
tags: [enhancement]
pullRequest: 2358
---

- Added public `user.cursorless_reformat` action to the Cursorless api
eg: `user.cursorless_reformat(cursorless_target, "ALL_CAPS")`
2 changes: 1 addition & 1 deletion cursorless-talon/src/actions/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@mod.action_class
class Actions:
def private_cursorless_reformat(
def cursorless_reformat(
target: CursorlessExplicitTarget, # pyright: ignore [reportGeneralTypeIssues]
formatters: str,
):
Expand Down
2 changes: 1 addition & 1 deletion cursorless-talon/src/cursorless.talon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tag: user.cursorless
user.private_cursorless_paste(cursorless_destination)

{user.cursorless_reformat_action} <user.formatters> at <user.cursorless_target>:
user.private_cursorless_reformat(cursorless_target, formatters)
user.cursorless_reformat(cursorless_target, formatters)

{user.cursorless_call_action} <user.cursorless_target> on <user.cursorless_target>:
user.private_cursorless_call(cursorless_target_1, cursorless_target_2)
Expand Down
13 changes: 13 additions & 0 deletions docs/user/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ Cursorless exposes a couple talon actions and captures that you can use to defin
- `user.cursorless_insert(destination: CursorlessDestination, text: Union[str, List[str]])`:
Insert text at destination.
eg: `user.cursorless_insert(cursorless_destination, "hello")`
- `user.cursorless_reformat(target: CursorlessTarget, formatters: str)`
Reformat target with specified formatters.
eg: `user.cursorless_reformat(cursorless_target, "ALL_CAPS")`

#### Snippet actions

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

### Example of custom formatter command

The below command will allow you to say `camel form blue air`.
_You can disable the default Cursorless reformat command by prefixing the spoken form in `actions.csv` with a dash. `-format, applyFormatter`_

```talon
<user.formatters> form <user.cursorless_target>:
user.cursorless_reformat(cursorless_target, formatters)
```

### Disable legacy destination grammar

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 comments on commit 4c6fc54

Please sign in to comment.