From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eshel Yaron <me@eshelyaron.com>
Cc: 74492@debbugs.gnu.org, Sean Whitton <spwhitton@spwhitton.name>
Subject: bug#74492: 31.0.50; [FR] explicit minor mode precedence
Date: Sat, 23 Nov 2024 22:35:53 -0500 [thread overview]
Message-ID: <jwvo725pbaq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <m15xoeawm4.fsf@macbookpro.home> (Eshel Yaron's message of "Sat, 23 Nov 2024 14:49:23 +0100")
>> 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
prev parent reply other threads:[~2024-11-24 3:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvo725pbaq.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=74492@debbugs.gnu.org \
--cc=me@eshelyaron.com \
--cc=monnier@iro.umontreal.ca \
--cc=spwhitton@spwhitton.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).