unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* low priority minor mode keymap?
@ 2018-10-31 17:08 Yang Zhao
  2018-11-02 15:22 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Zhao @ 2018-10-31 17:08 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 493 bytes --]

Hi,

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.

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?

[-- Attachment #2: Type: text/html, Size: 636 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: low priority minor mode keymap?
  2018-10-31 17:08 low priority minor mode keymap? Yang Zhao
@ 2018-11-02 15:22 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2018-11-02 15:22 UTC (permalink / raw)
  To: emacs-devel

> 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-02 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-31 17:08 low priority minor mode keymap? Yang Zhao
2018-11-02 15:22 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).