-
-
Notifications
You must be signed in to change notification settings - Fork 43
Snippet wrap #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Snippet wrap #94
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4d9603b
Initial working version
pokey dbfcf54
Working draft
pokey 19e449e
Fixes
pokey c39bbf7
Allow user snippets
pokey 47f6667
Cleanup
pokey be132e1
Add docs and make experimental
pokey 196cdfa
Switch to tag to enable experimental support
pokey 793658b
tweak snippet name
pokey dc7c9f5
Fix docs
pokey 8304aa3
Doc fix
pokey 60e9d5d
More doc
pokey 3b42a2b
Doc
pokey c40b30a
New snippets; fix watcher
pokey 12ba207
Use `.` instead of `/` for snippet placeholders
pokey c5970a7
Update docs
pokey 2fbb93d
Fix link in docs
pokey 3dd0218
Change tag name
pokey 3add362
Update docs
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,61 @@ | ||
from typing import Union | ||
from ..paired_delimiter import paired_delimiters_map | ||
from talon import Module | ||
from talon import Module, actions, app | ||
from ..csv_overrides import init_csv_and_watch_changes | ||
|
||
|
||
mod = Module() | ||
|
||
|
||
mod.list("cursorless_wrap_action", desc="Cursorless wrap action") | ||
mod.list("cursorless_built_in_wrapper_snippet", desc="Cursorless wrapper scope type") | ||
|
||
|
||
@mod.capture(rule=("{user.cursorless_paired_delimiter}")) | ||
def cursorless_wrapper(m) -> list[str]: | ||
paired_delimiter_info = paired_delimiters_map[m.cursorless_paired_delimiter] | ||
return [paired_delimiter_info.left, paired_delimiter_info.right] | ||
# NOTE: Please do not change these dicts. Use the CSVs for customization. | ||
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md | ||
built_in_wrapper_snippet = { | ||
"else state": "ifElseStatementElseBranch", | ||
"if else": "ifElseStatementIfBranch", | ||
"if state": "ifStatement", | ||
"try catch": "tryCatchStatement", | ||
} | ||
|
||
|
||
@mod.capture( | ||
rule=( | ||
"({user.cursorless_paired_delimiter} | {user.cursorless_built_in_wrapper_snippet}) {user.cursorless_wrap_action}" | ||
) | ||
) | ||
def cursorless_wrapper(m) -> Union[list[str], str]: | ||
try: | ||
paired_delimiter_info = paired_delimiters_map[m.cursorless_paired_delimiter] | ||
return { | ||
"action": "wrapWithPairedDelimiter", | ||
"extra_args": [paired_delimiter_info.left, paired_delimiter_info.right], | ||
} | ||
except AttributeError: | ||
return { | ||
"action": "wrapWithSnippet", | ||
"extra_args": [m.cursorless_built_in_wrapper_snippet], | ||
} | ||
|
||
|
||
@mod.action_class | ||
class Actions: | ||
def cursorless_wrap(cursorless_wrapper: dict, targets: dict): | ||
"""Perform cursorless wrap action""" | ||
actions.user.cursorless_single_target_command_with_arg_list( | ||
cursorless_wrapper["action"], targets, cursorless_wrapper["extra_args"] | ||
) | ||
|
||
|
||
def on_ready(): | ||
init_csv_and_watch_changes( | ||
"built_in_snippets", | ||
{ | ||
"built_in_wrapper_snippet": built_in_wrapper_snippet, | ||
}, | ||
) | ||
|
||
|
||
app.register("ready", on_ready) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.