unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Keymap priorities - how do define a global, low-priority binding from a minor mode?
@ 2006-04-11  9:04 David Reitter
  0 siblings, 0 replies; 3+ messages in thread
From: David Reitter @ 2006-04-11  9:04 UTC (permalink / raw)


I have defined a global minor mode which gives me a bunch of key  
bindings, among them bindings for `up' and `down'.

Turns out that the global minor mode overrides local key maps, at  
least minibuffer-local-map, which defines its own bindings for these  
keys (which I would prefer).

How do I specify priorities for key bindings? Can I define a minor  
mode key map that does not override the minibuffer map? Is using the  
global key map from a global minor mode a clean solution??

In this particular case, defining a key for [remap 'next-line] does  
the job, but is semantically different - it doesn't allow me to  
distinguish between C-n and `down', so I'm trying to get rid of it.

Thanks,
David

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

* Re: Keymap priorities - how do define a global, low-priority binding from a minor mode?
       [not found] <mailman.282.1144746248.9609.help-gnu-emacs@gnu.org>
@ 2006-04-11 15:54 ` Stefan Monnier
  2006-04-12  8:54   ` david.reitter
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2006-04-11 15:54 UTC (permalink / raw)


> I have defined a global minor mode which gives me a bunch of key  bindings,
> among them bindings for `up' and `down'.

> Turns out that the global minor mode overrides local key maps, at  least
> minibuffer-local-map, which defines its own bindings for these keys (which
> I would prefer).

> How do I specify priorities for key bindings? Can I define a minor mode key
> map that does not override the minibuffer map?

No.  Please report it as a feature request.  I think a good change would be
for minor-mode-map-alist entries to have higher or lower priority depending
on whether the minor mode's variable is buffer-local or global.  This way,
global minor mode would get lower priority than buffer-local maps (there's
still emulation-mode-map-alist if you want something or higher priority),
which seem like The Right Thing.

> Is using the global key map from a global minor mode a clean solution??

It's not great, but it's the best we have.


        Stefan

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

* Re: Keymap priorities - how do define a global, low-priority binding from a minor mode?
  2006-04-11 15:54 ` Keymap priorities - how do define a global, low-priority binding from a minor mode? Stefan Monnier
@ 2006-04-12  8:54   ` david.reitter
  0 siblings, 0 replies; 3+ messages in thread
From: david.reitter @ 2006-04-12  8:54 UTC (permalink / raw)


Stefan,
Thanks, I'll put together a suggestion at some point - but probably
after the release.

>> Is using the global key map from a global minor mode a clean solution??
>It's not great, but it's the best we have.

For the record, here's an alternative, certainly somewhat ugly. The
`down' key is bound to the below function, which then looks up what the
binding would be if the global minor mode was switched off.
This stops short of advising `next-line' (which would affect a lot of
code). Modifying the global map would have been the alternative, but I
didn't do it because people using my mode like to override its key map
in their .emacs, and they couldn't do that if I hardcoded additional
bindings to be set when the mode is switched on and off.

(defun osxkeys-visual-line-down-in-buffers ()
"Moves the cursor down one (visual) line.
If the `down' key would normally be bound to something else than
`next-line' (as it is the case in minibuffers), the other binding
is called."
  (interactive)
  (let* (osx-key-mode  ;; turn off mode temporarily
	 (binding (key-binding [down])))
    (if (eq binding 'next-line)
	(call-interactively (function visual-line-down))
      (call-interactively binding))))

;; mark functions for CUA
(dolist (cmd
	 '( beginning-of-visual-line
	    end-of-visual-line
	    visual-line-down visual-line-up
	    osxkeys-visual-line-up-in-buffers
	    osxkeys-visual-line-down-in-buffers))
  (put cmd 'CUA 'move))

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

end of thread, other threads:[~2006-04-12  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.282.1144746248.9609.help-gnu-emacs@gnu.org>
2006-04-11 15:54 ` Keymap priorities - how do define a global, low-priority binding from a minor mode? Stefan Monnier
2006-04-12  8:54   ` david.reitter
2006-04-11  9:04 David Reitter

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).