all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: low priority minor mode keymap?
Date: Fri, 02 Nov 2018 11:22:19 -0400	[thread overview]
Message-ID: <jwvk1lva6ky.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: CAP2upFXtUn9wv5R27awfAYc-ChEfu5oX8Kewo9QnnBhBD74eGw@mail.gmail.com

> 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	other threads:[~2018-11-02 15:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31 17:08 low priority minor mode keymap? Yang Zhao
2018-11-02 15:22 ` Stefan Monnier [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

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

  git send-email \
    --in-reply-to=jwvk1lva6ky.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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.