GNU bug report logs - #74492
31.0.50; [FR] explicit minor mode precedence

Previous Next

Package: emacs;

Reported by: Eshel Yaron <me <at> eshelyaron.com>

Date: Sat, 23 Nov 2024 13:50:02 UTC

Severity: normal

Found in version 31.0.50

Fixed in version 31.1

Done: Eshel Yaron <me <at> eshelyaron.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 74492 in the body.
You can then email your comments to 74492 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, spwhitton <at> spwhitton.name, bug-gnu-emacs <at> gnu.org:
bug#74492; Package emacs. (Sat, 23 Nov 2024 13:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eshel Yaron <me <at> eshelyaron.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, spwhitton <at> spwhitton.name, bug-gnu-emacs <at> gnu.org. (Sat, 23 Nov 2024 13:50:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eshel Yaron <me <at> eshelyaron.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; [FR] explicit minor mode precedence
Date: Sat, 23 Nov 2024 14:49:23 +0100

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




bug marked as fixed in version 31.1, send any further explanations to 74492 <at> debbugs.gnu.org and Eshel Yaron <me <at> eshelyaron.com> Request was from Eshel Yaron <me <at> eshelyaron.com> to control <at> debbugs.gnu.org. (Sat, 23 Nov 2024 14:04:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74492; Package emacs. (Sun, 24 Nov 2024 03:37:02 GMT) Full text and rfc822 format available.

Message #10 received at 74492 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eshel Yaron <me <at> eshelyaron.com>
Cc: 74492 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#74492: 31.0.50; [FR] explicit minor mode precedence
Date: Sat, 23 Nov 2024 22:35:53 -0500
>> 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





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 22 Dec 2024 12:24:17 GMT) Full text and rfc822 format available.

This bug report was last modified 230 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.