all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: mr.meowking--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 72624@debbugs.gnu.org
Subject: bug#72624: 31.0.50; minor-mode-overriding-map-alist doesn't have higher priority than local map, which differs from docs
Date: Wed, 14 Aug 2024 17:45:03 +0200 (CEST)	[thread overview]
Message-ID: <O4GZ54W--3-9@tutamail.com> (raw)

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'






             reply	other threads:[~2024-08-14 15:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 15:45 mr.meowking--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-08-17 10:05 ` bug#72624: 31.0.50; minor-mode-overriding-map-alist doesn't have higher priority than local map, which differs from docs Eli Zaretskii
2024-08-19 14:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-19 15:16   ` Meow King via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-31  8:10     ` Eli Zaretskii

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=O4GZ54W--3-9@tutamail.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=72624@debbugs.gnu.org \
    --cc=mr.meowking@tutamail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.