GNU bug report logs -
#72624
31.0.50; minor-mode-overriding-map-alist doesn't have higher priority than local map, which differs from docs
Previous Next
Reported by: mr.meowking <at> tutamail.com
Date: Wed, 14 Aug 2024 15:51:02 UTC
Severity: normal
Found in version 31.0.50
Done: Eli Zaretskii <eliz <at> gnu.org>
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 72624 in the body.
You can then email your comments to 72624 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72624
; Package
emacs
.
(Wed, 14 Aug 2024 15:51:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
mr.meowking <at> tutamail.com
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 14 Aug 2024 15:51:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
NOTE: please view
https://codeberg.org/meow_king/typst-ts-mode/issues/6#issuecomment-2174390
for rendered markdown view.
According to docs `(elisp) Active Keymaps` :
> Emacs contains many keymaps, but at any time only a few keymaps are
“active”. When Emacs receives user input, it translates the input event
(*note Translation Keymaps::), and looks for a key binding in the active
keymaps.
>
> Usually, the active keymaps are: (i) the keymap specified by the
‘keymap’ property, (ii) the keymaps of enabled minor modes, (iii) the
current buffer's local keymap, and (iv) the global keymap, in that
order. Emacs searches for each input key sequence in all these keymaps.
>
> Of these usual keymaps, the highest-precedence one is specified by
the ‘keymap’ text or overlay property at point, if any. (For a mouse
input event, Emacs uses the event position instead of point; *note
Searching Keymaps::.)
>
> Next in precedence are keymaps specified by enabled minor modes.
These keymaps, if any, are specified by the variables
‘emulation-mode-map-alists’, ‘minor-mode-overriding-map-alist’, and
‘minor-mode-map-alist’. *Note Controlling Active Maps::.
>
> Next in precedence is the buffer's “local keymap”, containing key
bindings specific to the buffer. The minibuffer also has a local keymap
(*note Intro to Minibuffers::). If there is a ‘local-map’ text or
overlay property at point, that specifies the local keymap to use, in
place of the buffer's default local keymap.
‘minor-mode-overriding-map-alist` should have higher priority than the buffer local keymap.
However, the actual behavior is different than what the docs say.
Here is my test:
```elisp
;;;###autoload
(defvar-keymap typst-ts-mode-map
;; ..
"RET" #'typst-ts-mode-return)
(defvar-keymap mk/test-map
"RET" #'(lambda () (interactive) (message "mk/test-map")))
;;;###autoload
(define-derived-mode typst-ts-mode text-mode "Typst"
"Major mode for editing Typst, powered by tree-sitter."
:group 'typst
:syntax-table typst-ts-mode-syntax-table
:after-hook
(typst-ts-mode-after-hook-function)
(setq minor-mode-overriding-map-alist '((outline-minor-mode . nil)))
(setcdr (assq #'outline-minor-mode minor-mode-overriding-map-alist) mk/test-map)
;; ...
)
```
In this situation, `typst-ts-mode-return` will be executed.
If we execute this elisp code and then re-enter `typst-ts-mode`
```elisp
(keymap-set outline-minor-mode-map "<return>" #'(lambda () (interactive) (message "outline-minor-mode-map")))
```
it will still execute `typst-ts-mode-return` function.
However, in addition of the previous code, if we then remove the following code in `typst-ts-mode` setup process:
```elisp
(setq minor-mode-overriding-map-alist '((outline-minor-mode . nil)))
(setcdr (assq #'outline-minor-mode minor-mode-overriding-map-alist) mk/test-map)
```
then the lambda function in `outline-minor-mode-map` will be executed.
---
In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.43, cairo version 1.18.0)
Repository revision: 643b564bd38cf037c55dba1a160b7d0c4c8355a9
Repository branch: master
System Description: NixOS 24.11 (Vicuna)
Configured using:
'configure
--prefix=/nix/store/dj6bh0vp6gzqdmb3ilri3aw5kcq62myf-emacs-pgtk-20240811.0
--disable-build-details --with-modules --with-pgtk
--with-compress-install --with-toolkit-scroll-bars
--with-native-compilation --without-imagemagick --with-mailutils
--without-small-ja-dic --with-tree-sitter --without-xinput2
--with-xwidgets --with-dbus --with-selinux'
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72624
; Package
emacs
.
(Sat, 17 Aug 2024 10:06:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 72624 <at> debbugs.gnu.org (full text, mbox):
> Date: Wed, 14 Aug 2024 17:45:03 +0200 (CEST)
> From: mr.meowking--- via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> NOTE: please view
> https://codeberg.org/meow_king/typst-ts-mode/issues/6#issuecomment-2174390
> for rendered markdown view.
>
> According to docs `(elisp) Active Keymaps` :
>
> > Emacs contains many keymaps, but at any time only a few keymaps are
> “active”. When Emacs receives user input, it translates the input event
> (*note Translation Keymaps::), and looks for a key binding in the active
> keymaps.
> >
> > Usually, the active keymaps are: (i) the keymap specified by the
> ‘keymap’ property, (ii) the keymaps of enabled minor modes, (iii) the
> current buffer's local keymap, and (iv) the global keymap, in that
> order. Emacs searches for each input key sequence in all these keymaps.
> >
> > Of these usual keymaps, the highest-precedence one is specified by
> the ‘keymap’ text or overlay property at point, if any. (For a mouse
> input event, Emacs uses the event position instead of point; *note
> Searching Keymaps::.)
> >
> > Next in precedence are keymaps specified by enabled minor modes.
> These keymaps, if any, are specified by the variables
> ‘emulation-mode-map-alists’, ‘minor-mode-overriding-map-alist’, and
> ‘minor-mode-map-alist’. *Note Controlling Active Maps::.
> >
> > Next in precedence is the buffer's “local keymap”, containing key
> bindings specific to the buffer. The minibuffer also has a local keymap
> (*note Intro to Minibuffers::). If there is a ‘local-map’ text or
> overlay property at point, that specifies the local keymap to use, in
> place of the buffer's default local keymap.
>
> ‘minor-mode-overriding-map-alist` should have higher priority than the buffer local keymap.
> However, the actual behavior is different than what the docs say.
>
> Here is my test:
>
> ```elisp
> ;;;###autoload
> (defvar-keymap typst-ts-mode-map
> ;; ..
> "RET" #'typst-ts-mode-return)
>
> (defvar-keymap mk/test-map
> "RET" #'(lambda () (interactive) (message "mk/test-map")))
>
> ;;;###autoload
> (define-derived-mode typst-ts-mode text-mode "Typst"
> "Major mode for editing Typst, powered by tree-sitter."
> :group 'typst
> :syntax-table typst-ts-mode-syntax-table
> :after-hook
> (typst-ts-mode-after-hook-function)
>
> (setq minor-mode-overriding-map-alist '((outline-minor-mode . nil)))
> (setcdr (assq #'outline-minor-mode minor-mode-overriding-map-alist) mk/test-map)
>
> ;; ...
> )
> ```
> In this situation, `typst-ts-mode-return` will be executed.
>
> If we execute this elisp code and then re-enter `typst-ts-mode`
> ```elisp
> (keymap-set outline-minor-mode-map "<return>" #'(lambda () (interactive) (message "outline-minor-mode-map")))
> ```
> it will still execute `typst-ts-mode-return` function.
>
> However, in addition of the previous code, if we then remove the following code in `typst-ts-mode` setup process:
> ```elisp
> (setq minor-mode-overriding-map-alist '((outline-minor-mode . nil)))
> (setcdr (assq #'outline-minor-mode minor-mode-overriding-map-alist) mk/test-map)
> ```
> then the lambda function in `outline-minor-mode-map` will be executed.
Stefan, any comments or suggestions?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72624
; Package
emacs
.
(Mon, 19 Aug 2024 14:54:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 72624 <at> debbugs.gnu.org (full text, mbox):
> ‘minor-mode-overriding-map-alist` should have higher priority than the
> buffer local keymap.
According to my tests, it does.
> (defvar-keymap mk/test-map
> "RET" #'(lambda () (interactive) (message "mk/test-map")))
[...]
> (keymap-set outline-minor-mode-map "<return>" #'(lambda () (interactive)
> (message "outline-minor-mode-map")))
Binding a command to "<return>" is generally a bug.
You should bind it to "RET" instead, unless you really know what
you're doing.
The way the bug manifests itself is exactly in the way you show here.
Emacs will first look for a binding for `return` and if it finds one
it'll use it in preference to a binding for `RET`, regardless of the
relative precedence of the keymaps involved.
[ Side note:
> ```elisp
[...]
> (setq minor-mode-overriding-map-alist '((outline-minor-mode . nil)))
[...]
> ```
`minor-mode-overriding-map-alist` is automatically buffer-local, so
setting it at the toplevel of an ELisp file doesn't make much sense: it
will set it only in the buffer that happens to be current when you load
that ELisp file. ]
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#72624
; Package
emacs
.
(Mon, 19 Aug 2024 17:18:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 72624 <at> debbugs.gnu.org (full text, mbox):
> Emacs will first look for a binding for `return` and if it finds one
> it'll use it in preference to a binding for `RET`, regardless of the
> relative precedence of the keymaps involved.
Thanks! After correctly bound keys, issues related to Corfu resolved, and I see `minor-mode-overriding-map-alist` works well and behave in order.
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 31 Aug 2024 08:12:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
mr.meowking <at> tutamail.com
:
bug acknowledged by developer.
(Sat, 31 Aug 2024 08:12:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 72624-done <at> debbugs.gnu.org (full text, mbox):
> Cc: 72624 <72624 <at> debbugs.gnu.org>
> Date: Mon, 19 Aug 2024 17:16:50 +0200 (CEST)
> From: Meow King via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> > Emacs will first look for a binding for `return` and if it finds one
> > it'll use it in preference to a binding for `RET`, regardless of the
> > relative precedence of the keymaps involved.
>
> Thanks! After correctly bound keys, issues related to Corfu resolved, and I see `minor-mode-overriding-map-alist` works well and behave in order.
No further comments, so I assume the problem is solved, and I'm
therefore closing this bug.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 28 Sep 2024 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 321 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.