Skip to content
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

Add Leader key->Sequence to generate arbitrary action #97

Closed
jtroo opened this issue Aug 7, 2022 · 1 comment · Fixed by #103
Closed

Add Leader key->Sequence to generate arbitrary action #97

jtroo opened this issue Aug 7, 2022 · 1 comment · Fixed by #103
Labels
enhancement New feature or request

Comments

@jtroo
Copy link
Owner

jtroo commented Aug 7, 2022

Feature description

This feature is inspired by abbr in Vim and in the fish shell as well as Vim's map commands, e.g. imap or nnoremap. It also makes use of Vim's <leader> key concept that's used in the map commands.

Without the fake keys feature, this was not feasible because the keyberon library is used to process actions. To easily generate an arbitrary action, a key needs to be pressed since kanata doesn't have any knowledge of how to process non-Custom actions. Now that fake keys are added, this feature seems feasible since a fake key is guaranteed to not interact with physical keypresses and thus a tap of a fake key is a good way to execute arbitrary actions.

The proposed changes are:

  • add a new definition item defseq
    • this will take a fake key name as the first parameter
    • the following parameter is a list of normal keys (e.g. (lctl a b c))
  • add a new special action similar to live reload's lrld: sequence leader sldr.
  • If sldr is pressed and followed by normal keys in the correct order, the fake key gets tapped

Example configuration entries:

(defseq git-status (g s t))
(deffakekeys git-status (macro g i t spc s t a t u s)
(defalias als (tap-hold 200 200 sldr ralt))

Tapping the keys in order: ralt g s t will result in git status being typed by kanata.


Implementation details

  • all defseq sequences are parsed into a trie
  • for simplicity, a non-leaf node is not allowed to have an action associated with it
    • this is not how Vim *map commands work
    • e.g. (defseq fk1 a b c) and (defseq fk2 a b) will be rejected
  • when a sequence leader key sldr is pressed, switch the processing loop mode to a sequence mode where it does not send key inputs and instead traverse the trie using key inputs
    • when a sequence not in the trie is encountered, exit sequence mode
    • when a sequence in the trie ends up on a leaf node, tap the fake key and exit sequence mode
    • defcfg configurable timeout for sequence timeout?
@jtroo jtroo added the enhancement New feature or request label Aug 7, 2022
@jtroo
Copy link
Owner Author

jtroo commented Aug 7, 2022

For a trie, seems like one of these two libraries is the most promising for the use case:

https://docs.rs/radix_trie/0.2.1/radix_trie/index.html
https://docs.rs/qp-trie/0.8.0/qp_trie/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant