emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: low priority minor mode keymap?


From: Stefan Monnier
Subject: Re: low priority minor mode keymap?
Date: Fri, 02 Nov 2018 11:22:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> When configuring god-mode (https://github.com/chrisdone/god-mode) I figure
> that I want to put some keys at a lower priority than the local map, but
> allowing this to be triggered based on the minor mode.  I can simulate this
> imperfectly with elisp code that looks up keymaps manually.

Here's how crisp-mode (in GNU ELPA) does it:

    (define-minor-mode crisp-mode "..."
      :keymap crisp--minor-mode-map
      :global t
      (cond
       (crisp-mode
        ;; Make menu entries show M-u or f14 in preference to C-x u.
        (put 'undo :advertised-binding
             `([?\M-u] [f14] ,@(get 'undo :advertised-binding)))
        (cl-pushnew crisp-mode-map (cdr global-map))
        ...)
       (t ;; not crisp-mode
        (cl-callf (lambda (binds) (delq crisp-mode-map binds))
                  (cdr global-map)))))

where `crisp--minor-mode-map` is a dummy keymap.
If you want it to be buffer-local, you'd have to add crisp-mode-map to
the buffer-local map instead of the global-map, of course, which would
need to be done a bit differently.  Maybe something like:

    (let ((map (current-local-map)))
      (unless (eq crisp-mode-map (keymap-parent map))
        (use-local-map (make-composed-keymap map crisp-mode-map))))
and
    (let ((map (current-local-map)))
      (when (eq crisp-mode-map (keymap-parent map))
        (use-local-map (car (cdr map)))))

> A better solution seems to be a minor-mode-low-priority-map-alist that
> works similar to minor-mode-map-alist, but takes precedence after
> local-map.  Is something like this useful enough to get into Emacs?

The rules deciding which maps are active at a given time are already
pretty long and complex, IMO.  What I'd *really* like is for this rule
to be replaced by something like

    (defun current-active-maps (olp position)
      (funcall current-active-maps-function olp position))

so your mode could tweak the rule any way it likes.

This basically requires to change the C code such that any time it needs
to know/scan all the keymaps it does it by calling Fcurrent_active_maps.
We'd also need to adapt describe-buffer-bindings somehow.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]