emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggestion for improving ergonomics of repeat-maps: define-repeat-ma


From: Juri Linkov
Subject: Re: Suggestion for improving ergonomics of repeat-maps: define-repeat-map
Date: Thu, 09 Sep 2021 20:50:52 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> 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.

Thanks, this would be a nice addition.

> (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'.")

The reason why currently in Emacs core repeat-maps are defined this way
is because this is a standard way to define a keymap.

If normal keymaps were defined with a macro similar to the macro
that you created, it would be easier to migrate the existing repeat-maps
to your macro.  I mean if we had a macro `define-keymap' that defines
normal keymaps and that is similar to your `define-repeat-map',
then creating a repeat-map from the normal map would require just
changing the macro name `define-keymap' to `define-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))

I'd like to hear more opinions whether the above macro is a better
way to define repeat-maps in Emacs core.  I'm sure this macro is nice
to use in a personal customization init file, but the question is
about using it in Emacs core.  If this will be preferable for Emacs core,
then it could be included in repeat.el.  Otherwise, GNU ELPA is a better place.
Then for Emacs core I'd suggest at least to add another macro
'define-repeat-key' that will remove the need of adding manually
`(put command 'repeat-map 'case-repeat-map)`, e.g.:

(defvar case-repeat-map
  (let ((map (make-sparse-keymap)))
    (define-repeat-key map "c" #'capitalize-word)
    (define-repeat-key map "u" #'upcase-word)
    (define-repeat-key map "l" #'downcase-word)
    ;; movement
    (define-repeat-key map "f" #'forward-word-with-case)
    (define-repeat-key map "b" #'backward-word-with-case)
    map)

Then it will preserve the same style already used in core.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]