help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: unexpected result with keymap inheritance


From: Alex Kost
Subject: Re: unexpected result with keymap inheritance
Date: Wed, 23 Nov 2016 12:51:20 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux)

Stefan Monnier (2016-11-22 20:12 -0500) wrote:

>> Well, yes, I think I do something very unusual: I rebind hundreds and
>> hundreds of default key bindings.
>
> While it's not usual to do that for hundreds of them, rebinding is
> normal, so it's something we want to (and do) support.
>
>> And my use case is: I often want to just remove a key from some map so
>> that a key from its parent map will take precedence.
>
> Do you have a more concrete description of when you want to do that?

Here is an example.  I want to use some strange keys in all the modes
that derive from 'special-mode', so I do this:

  (define-key special-mode-map (kbd "o") 'backward-char)
  (define-key special-mode-map (kbd "u") 'forward-char)

OK, so far so good, but then I face some mode that also binds these
keys:

--8<---------------cut here---------------start------------->8---
(defvar very-special-mode-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map special-mode-map)
    (define-key map (kbd "o") 'find-file)
    (define-key map (kbd "u") 'undo)
    map))

(define-derived-mode very-special-mode special-mode "Very Special")
--8<---------------cut here---------------end--------------->8---

Now what I want is just to remove "o" and "u" from
'very-special-mode-map', so that my keys from 'special-mode-map' will
take precedence, but I can't do it, as with this:

  (define-key very-special-mode-map (kbd "o") nil)
  (define-key very-special-mode-map (kbd "u") nil)

I will get "<key> is undefined", so I have to bind my keys to the same
commands in this new map again:

  (define-key very-special-mode-map (kbd "o") 'backward-char)
  (define-key very-special-mode-map (kbd "u") 'forward-char)

I met the described case pretty often, and I really miss this "remove
key" functionality.  It would be really convenient for me if I could do:

  (remove-key <some-map> <some-key>)

or since I want to unbind many keys:

  (dolist (key <some-list-of-my-keys>)
    (remove-key <some-map> key))

-- 
Alex



reply via email to

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