GNU bug report logs -
#54074
29.0.50; Feature request emacs keymap-set and minor-modes
Previous Next
Full log
View this message in rfc822 format
> 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)))))
```
This bug report was last modified 3 years and 113 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.