jtroo / kanata

Improve keyboard comfort and usability with advanced customization
GNU Lesser General Public License v3.0
3.02k stars 126 forks source link

Feature request: using kanata for text sequence expansion #1305

Open seelaman opened 3 weeks ago

seelaman commented 3 weeks ago

Is your feature request related to a problem? Please describe.

I've been trying to replace Autohotkey or Espanso with Kanata sequences (they've been unreliable for me). So far I was able to put my text expansion onto a key in a layer which is close but I'm wondering if it's possible to expand a typed sequence into a string which also contains numbers directly from sequence loader mode (sldr).

I can almost get there but am running into an issue when trying to have numbers in the macro.

I can add an alias for each number as per the docs but can't use that alias in the macro when it's part of a virtualkey definition.

(defalias
  1 1
  2 2
  3 3
  working_alias (macro @1 @2 @3)
)

(defseq oid (o i d))

;; this throws an error
(defvirtualkeys  oid (macro @1 @2 @3))

(deflayermap custom_layer
  a @working_alias
  ;; entering sldr and typing oid does not work, aliases are not allowed in a macro definition
  ret sldr
)

If there is a simpler way to do this, please let me know, I didn't find anything in the docs.

Describe the solution you'd like.

I would like to enter sldr mode using a key and type any predefined sequence to get it expanded into text.

for example

Describe alternatives you've considered.

I tried putting the macro on a key directly which works. It just limits how many shortcuts I can use and forces me to remember which key each macro is on.

Additional context

Another part (this would go into a separate issue if the numbers question finds a solution) would be to execute a command to replace the output.

for example entering sldr mode, typing "date" and getting today's date expanded as text by running:

date +"%Y-%m-%d"

I'm already using (cmd ) extensively but would love for it to expand text like a sequence does.

I understand if this is out of scope of course.

jtroo commented 3 weeks ago

You can do DigitX instead. E.g. Digit1. https://github.com/jtroo/kanata/blob/main/docs/config.adoc#key-names

gerhard-h commented 3 weeks ago

maybe cmd-output-keys and including the backspace .psiso (cmd-output-keys powershell.exe -Command r#"echo "(" bspc bspc ((Get-Date -Format "yyyy-MM-dd").toCharArray() -join " ") ")""#)

jtroo commented 3 weeks ago

If you're willing to test out a more experimental feature, you could see if zippychord is any better for text expansion: https://github.com/jtroo/kanata/pull/1301

seelaman commented 3 weeks ago

The DigitX suggestion worked, thank you.

I'll give the other suggestions a try as well.

seelaman commented 3 weeks ago

maybe cmd-output-keys and including the backspace .psiso (cmd-output-keys powershell.exe -Command r#"echo "(" bspc bspc ((Get-Date -Format "yyyy-MM-dd").toCharArray() -join " ") ")""#)

This also worked.

If others come across this: The last section of the cmd docs lays out exactly the same use case, complete with date call in bash

  pdb (cmd-output-keys bash -c "date +'%F %R' | sed 's/./& /g' | sed 's/:/S-;/g' | sed 's/\(.\{20\}\)\(.*\)/\(\1 spc \2\)/'")