unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Suggestion for improving ergonomics of repeat-maps: define-repeat-map
@ 2021-09-08  3:22 acdw
  2021-09-08 14:54 ` Philip Kaludercic
  2021-09-09 17:50 ` Juri Linkov
  0 siblings, 2 replies; 20+ messages in thread
From: acdw @ 2021-09-08  3:22 UTC (permalink / raw)
  To: emacs-devel

Hi Emacs maintainers!

I've written a package[1] for my own ease of use in defining repeat-maps for Emacs 28, and a few people have told me I should see about adding it to Emacs proper.  So here we are.

The elevator pitch:

The new functionality defined in repeat.el in Emacs 28 is very useful, but usually requires a large amount of configuration, to wit:

~~~
(defalias 'forward-word-with-case 'forward-word
  "Alias for `forward-word' for use in `case-repeat-map'.")
(defalias 'backward-word-with-case 'backward-word
  "Alias for `backward-word for use in `case-repeat-map'.")

(defvar case-repeat-map
  (let ((map (make-sparse-keymap)))
    (define-key map "c" #'capitalize-word)
    (define-key map "u" #'upcase-word)
    (define-key map "l" #'downcase-word)
    ;; movement
    (define-key map "f" #'forward-word-with-case)
    (define-key map "b" #'backward-word-with-case)
    map)
  "A map to repeat word-casing commands.  For use with `repeat-mode'.")
  
(dolist (command '(capitalize-word
                   capitalize-dwim
                   upcase-word
                   upcase-dwim
                   downcase-word
                   downcase-dwim
                   forward-word-with-case
                   backward-word-with-case))
  (put command 'repeat-map 'case-repeat-map))
~~~

I wrote the macro `define-repeat-map' to alleviate this large amount of configuration.  Using this macro, the above turns into this:

~~~
(define-repeat-map case
  ("c" capitalize-word
   "u" upcase-word
   "l" downcase-word)
  (:continue "f" forward-word
             "b" backward-word)
  (:enter downcase-dwim
          upcase-dwim
          capitalize-dwim))
~~~

As you can see, `define-repeat-map' makes it easier to not only define repeating keys for commands, but to define commands that can enter the keymap, keys that are in the keymap and can continue the binds, but not enter the map, and commands that will exit the map when they're pressed.  I was inspired by the repeaters[2] package on GitHub, but wrote my own because I wanted better (to me) ergonomics.

Please let me know what you think about this macro and package.  I've written some elisp for my own enjoyment but never submitted a package to Emacs, or looked into including it in core.  I'm open to any and all suggestions, including simply adding this package to GNU ELPA.

Thanks for all you do!

[1]: https://tildegit.org/acdw/define-repeat-map.el/

-- 
~ acdw (Case Duckworth)
https://www.acdw.net | https://breadpunk.club/~breadw



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-10-04 20:16 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  3:22 Suggestion for improving ergonomics of repeat-maps: define-repeat-map acdw
2021-09-08 14:54 ` Philip Kaludercic
2021-09-08 17:01   ` acdw
2021-09-09 17:50 ` Juri Linkov
2021-09-09 18:06   ` Lars Ingebrigtsen
2021-09-09 20:35     ` Augusto Stoffel
2021-09-09 20:39       ` Lars Ingebrigtsen
2021-09-10  0:53     ` acdw
2021-09-10 10:53       ` Lars Ingebrigtsen
2021-10-04  8:22       ` Lars Ingebrigtsen
2021-10-04  9:05         ` Adam Porter
2021-10-04  9:49           ` Lars Ingebrigtsen
2021-10-04 11:29             ` Adam Porter
2021-10-04 11:33               ` Lars Ingebrigtsen
2021-10-04 18:18             ` Juri Linkov
2021-10-04 19:02               ` Lars Ingebrigtsen
2021-10-04 19:24                 ` Stefan Monnier
2021-10-04 19:54                   ` Lars Ingebrigtsen
2021-10-04 20:16                   ` Lars Ingebrigtsen
2021-09-10  0:53   ` acdw

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).