bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes


From: Juri Linkov
Subject: bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes
Date: Mon, 21 Feb 2022 10:28:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> 1)
>
> With that then could be trivial to implemented something like
> use-packages :bind, so
>
> (define-minor-mode my-mode
>     :global t
>     :keymap (my-mode-map
>              :map isearch-mode-map my-mode-isearch-map))
>
>
> or similar... I am wondering how nobody have requested this before, when
> it is a very common issue I find in many packages around.

You might be interested in how the composite keymaps are defined here:

```
(define-minor-mode outline-minor-mode
  :keymap (easy-mmode-define-keymap
           `(([menu-bar] . ,outline-minor-mode-menu-bar-map)
             (,outline-minor-mode-prefix . ,outline-mode-prefix-map))
           :inherit outline-minor-mode-cycle-map)
```

Maybe such keymap definitions could be simplified.

> 2)
>
> The best approach for this one is to save the original value in an alist
> and assign with a wrapper around setq...  and use a loop when disabling
> the mode to restore the original values.... it is not perfect, but works
> in many cases...
> [...]
> Does it makes sense??

Yes, this makes sense.  We used the functions copied below
until you proposed to move keybindings to context-menu-mode-map:

```
(defvar context-menu--saved-bindings nil
  "Alist of bindings to restore when `context-menu-mode' is disabled.")

(defun context-menu--bind-mouse (click-sym down-sym)
  "Enable `context-menu-mode' mouse bindings.
CLICK-SYM and DOWN-SYM are the mouse click and down key symbols to use."
  (let ((click (vector click-sym))
        (down (vector down-sym)))
    (push (cons click-sym (global-key-binding click))
          context-menu--saved-bindings)
    (global-unset-key click)
    (push (cons down-sym (global-key-binding down))
          context-menu--saved-bindings)
    (global-set-key down context-menu-entry)))

(defun context-menu--restore-bindings ()
  "Restore saved `context-menu-mode' bindings."
  (pcase-dolist (`(,sym . ,binding) context-menu--saved-bindings)
    (let ((key (vector sym)))
      (if binding
          (global-set-key key binding)
        (global-unset-key key)))))
```





reply via email to

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