Last active
June 17, 2020 19:04
-
-
Save rntz/94db3c665d4837d58cc1dee763a5dadc to your computer and use it in GitHub Desktop.
Uniform handling of delimiters in talon
This file contains 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
from talon import Module, Context, actions | |
delimiters = {x[0]: x[1] for x in "() [] {} <> “”".split()} | |
mod = Module() | |
@mod.action_class | |
class Actions: | |
def delimiter_close(delimiter: str) -> str: | |
"""Turns a delimiter into its corresponding closing delimiter.""" | |
return delimiters.get(delimiter, delimiter) |
This file contains 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
# Inserts a closing delimiter, e.g. "close paren" -> ")". | |
# Kind of redundant if you already have names for those. | |
# Symbols it doesn't recognize it will leave alone, e.g. "close quote" -> "'". | |
close <user.symbol>: | |
key(user.delimiter_close(symbol)) | |
# Insert a matched pair of delimiters, e.g. | |
# empty paren -> () | |
# empty angle -> <> | |
# empty quote -> '' | |
empty <user.symbol>: | |
insert(symbol) | |
insert(user.delimiter_close(symbol)) | |
# The same thing, but leaves the cursor between the delimiters afterwards. | |
(in|between) <user.symbol>: | |
insert(symbol) | |
insert(user.delimiter_close(symbol)) | |
edit.left() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment