talonhub / community

Voice command set for Talon, community-supported.
MIT License
634 stars 781 forks source link

More generic editing commands #814

Open rntz opened 2 years ago

rntz commented 2 years ago

A lot of our editing commands are verb-noun with fairly generic verbs & nouns, eg. verbs are go, select, cut, copy, clear; nouns are line 42, line 3 until 7, line start, top, word left, up, all. This requires quadratically many rules and makes adding new verbs or nouns annoying. Examples of new verbs/nouns one might want:

  1. In emacs I can move/select by sentences or paragraphs. Talon has actions which support this (edit.select_paragraph, edit.sentence_next, etc), but I'd need to define (go/select/cut/copy/clear) (paragraph/sentence) (start/end/next/previous) ≈ 40 new voice commands to handle this alone.

  2. I have commands for selecting/clearing N lines below/above the current one, with variants including & excluding current line. I've manually added some verbs for these (selecting & deleting) but not others (cut, copy, indent, comment).

  3. Besides select/cut/copy/clear there are loads of commands that make sense to apply to chunks of text, eg. indent/comment/google/pastebin/reformat/rot13/phones.

Moreover, specific editors can sometimes provide optimized ways of performing certain editing sequences. Eg. in emacs many commands take a "prefix" that repeats them: instead of doing key(alt-left:9) to move left 9 words I can do key(alt-9 alt-left). It would be nice to allow editors to implement optimized versions of:

  1. Repeated movement commands, since many editors have optimized ways of doing this.
  2. Select-followed-by-an-action commands, like "cut line" and "copy line", since many editors have keybindings for things like this.

I see at least two approaches here:

  1. Code generation: To solve the quadratically-many-voice-commands problem, we just generate voice commands from a template. Talon files are easy to generate; we check in both the script that generates them and the files themselves into knausj. To solve the optimization problem, we'd need to declare additional talon actions for repeated motion and select-followed-by-{cut,copy,clear,etc}, which we could also code-generate.

  2. Generic editing actions: Make actions which are generic enough and customizable enough to support these use-cases. I've mocked up a prototype of what this might look like for motion commands alone: https://gist.github.com/rntz/5575959604198bceb0be4762d38a8612. It needs to be extended to handle region-commands like select, cut, copy, etc. It works by defining a capture user.edit_motion of "cursor motions" (eg. top, line start, 4 words left) that produce plain old data that gets interpreted by user.edit_go into talon actions. It involves a fair amount of reflection. Editors can override an action user.edit_go_faster to optimize movement commands. Haven't implemented cut/copy commands yet.

See also #670.

rntz commented 2 years ago

Might also be worth taking a look at cursorless' approach here.