[Top][All Lists]

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

Re: Making a key undefined again

From: Stefan Monnier
Subject: Re: Making a key undefined again
Date: Tue, 26 Oct 2021 15:33:13 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jonas Bernoulli [2021-10-26 18:11:53] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> There always is a (EVENT) entry in the keymap itself because of this line
>>> further up:
>>>              (define-key keymap key nil)
>>> (At which point KEY still has the form [EVENT], not (EVENT).)
>> Actually, it's not guaranteed.  Try it with:
>>     (let ((parent (make-sparse-keymap))
>>           (child (make-keymap)))
>>       (set-keymap-parent child parent)
>>       (define-key parent [?a] nil)
>>       (define-key child  [?a] 'bar)
>>       child)
>> :-(
> That can be fixed too.

Of course.  I think what I'm getting at is that the best fix is to
implement it inside `define-key` such that (define-key map
<k> :remove-nonparent-binding) does that you want.   It's probably easy
to implement there.

[ Where `:remove-nonparent-binding` is a candidate for a better name,
  of course.  ]

>>> but that breaks when `foo-next-thing' is renamed to `foo-forward'.
>>> And even if that never happens, it still complicates `foobar-mode-map',
>>> which now has a binding for `foo-next-thing', which isn't actually
>>> necessary because an identical binding exists in the parent keymap
>>> `foo-mode-map'.
>> How common is this case?
> When implementing an alternative set of key bindings across all of Emacs
> that diverge from the "standard Emacs key bindings" a lot (up to the
> scale of Vim but possibly not quite *that* drastically different), then
> it might be needed for essentially every keymap.

Interesting.  Maybe such scenarios would also benefit from a more
general "rewrite-keymap" operation, maybe by combining `map-keymap` and
a new `keymap-clear` operation that just empties a keymap completely.

>> So your notion of "no binding at all" can also be described as something
>> like "use the binding of the parent".
> Yes. (Or the default binding, or ...)
> remove(add(MAP KEY) KEY) == MAP

Do we need to distinguish

    (let ((map (make-sparse-keymap)))
      (define-key map [?a ?b] 'foo)
      (define-key map [?a ?b] :remove-nonparent-binding)


    (let ((map (make-sparse-keymap)))
      (define-key map [?a] (make-sparse-keymap))
      (define-key map [?a ?b] 'foo)
      (define-key map [?a ?b] :remove-nonparent-binding)



reply via email to

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