all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: unexpected result with keymap inheritance
Date: Wed, 23 Nov 2016 12:51:20 +0300	[thread overview]
Message-ID: <87fumicynb.fsf@gmail.com> (raw)
In-Reply-To: <jwvy40bf1co.fsf-monnier+gmane.emacs.help@gnu.org> (Stefan Monnier's message of "Tue, 22 Nov 2016 20:12:18 -0500")

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	other threads:[~2016-11-23  9:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21  0:28 unexpected result with keymap inheritance Ernest Adrogué
2016-11-21 14:12 ` Stefan Monnier
2016-11-21 17:12   ` Alex Kost
2016-11-22  2:55     ` Stefan Monnier
2016-11-22 19:07       ` Alex Kost
2016-11-23  1:12         ` Stefan Monnier
2016-11-23  9:51           ` Alex Kost [this message]
2016-11-23 13:42             ` Stefan Monnier
2016-11-23 21:23               ` Alex Kost
2016-11-24  2:20                 ` Stefan Huchler
2016-11-23 10:16           ` Ernest Adrogué
2016-11-23 15:02             ` Stefan Monnier
2016-11-22  0:30   ` Ernest Adrogué
  -- strict thread matches above, loose matches on Subject: below --
2016-11-23  5:43 Edward Flanigan
2016-11-23  9:05 ` Alex Kost
2016-11-23 14:47   ` Stefan Monnier

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=87fumicynb.fsf@gmail.com \
    --to=alezost@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.