* bug#74492: 31.0.50; [FR] explicit minor mode precedence
@ 2024-11-23 13:49 Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24 3:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 2+ messages in thread
From: Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-11-23 13:49 UTC (permalink / raw)
To: 74492; +Cc: Stefan Monnier, Sean Whitton
Hi,
I'm creating this feature request to track an idea that Stefan brought
up in bug#74404:
> BTW, maybe we should add some notion of minor mode precedence since such
> problems are actually fairly common. We could do something similar to
> what we do with `add-hook`, so `add-minor-mode` takes care of obeying
> the ordering constraints.
Currently, the last minor mode to be defined takes precedence over
previously defined minor modes, at least in terms of keybindings. This
makes it hard-to-impossible for minor modes that need high precedence to
"guard" their keybindings from minor modes defined at any later time.
An explicit mechanism for specifying minor mode precedence could help.
Best,
Eshel
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#74492: 31.0.50; [FR] explicit minor mode precedence
2024-11-23 13:49 bug#74492: 31.0.50; [FR] explicit minor mode precedence Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-24 3:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-11-24 3:35 UTC (permalink / raw)
To: Eshel Yaron; +Cc: 74492, Sean Whitton
>> BTW, maybe we should add some notion of minor mode precedence since such
>> problems are actually fairly common. We could do something similar to
>> what we do with `add-hook`, so `add-minor-mode` takes care of obeying
>> the ordering constraints.
>
> Currently, the last minor mode to be defined takes precedence over
> previously defined minor modes, at least in terms of keybindings. This
> makes it hard-to-impossible for minor modes that need high precedence to
> "guard" their keybindings from minor modes defined at any later time.
> An explicit mechanism for specifying minor mode precedence could help.
We should first try and figure out what it is that's really needed, tho.
So I took a quick look at Emacs's own code and so far I found:
;; Define-minor-mode added our keymap to minor-mode-map-alist, but we want it
;; on minor-mode-overriding-map-alist instead.
(setq minor-mode-map-alist
(delq (assq 'completion-in-region-mode minor-mode-map-alist)
minor-mode-map-alist))
in `minibuffer.el` which is related but can't just use a precedence
because we want to change the keymap dynamically anyway.
;; Add a custom keymap for `visual-line-mode' so that activating
;; this minor mode does not override Org's keybindings.
;; FIXME: Probably `visual-line-mode' should take care of this.
(let ((oldmap (cdr (assoc 'visual-line-mode minor-mode-map-alist)))
(newmap (make-sparse-keymap)))
(set-keymap-parent newmap oldmap)
(define-key newmap [remap move-beginning-of-line] nil)
(define-key newmap [remap move-end-of-line] nil)
(define-key newmap [remap kill-line] nil)
(make-local-variable 'minor-mode-overriding-map-alist)
(push `(visual-line-mode . ,newmap) minor-mode-overriding-map-alist))
in `org.el` which is related but couldn't just use a precedence either.
;; Make sure we are first in minor-mode-map-alist
(let ((c (assq 'orgtbl-mode minor-mode-map-alist)))
;; FIXME: maybe it should use emulation-mode-map-alists?
(and c (setq minor-mode-map-alist
(cons c (delq c minor-mode-map-alist)))))
in `org-table.el` should could definitely use a precedence.
and that's it. There used to be more for things like IDO or Viper, but
IIRC that was solved with the introduction of `emulation-mode-map-alists`.
I know there are more cases of "minor mode precedence" issues.
E.g. I remember seeing recently an issue in VM where the `w3m` minor
mode bindings used when rendering some HTML email body shadowed the
buffer's major mode, but again a case where precedence between minor
modes wouldn't help.
I don't think the examples above justify adding the kind of precedences
I suggested. Maybe if we find more examples out there in the wild, the
picture might change. Otherwise, maybe we should look for something
else that would solve the kinds of problems listed here.
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-24 3:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-23 13:49 bug#74492: 31.0.50; [FR] explicit minor mode precedence Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24 3:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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).