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: Thu, 24 Nov 2016 00:23:39 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux)

Stefan Monnier (2016-11-23 08:42 -0500) wrote:

>> 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:
>
> I see, yes, that makes sense.  I suggest you `M-x report-emacs-bug` and
> ask for this feature.

Thanks, but there are tons of Emacs bugs, and I wouldn't like to bother
you and other contributors with just another feature request.

>> 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)
>
> That's the obvious workaround, yes.  It's not that terrible, but I agree
> it's less satisfactory.
>
> Another approach if you want these `o` and `u` bindings to apply in
> every special-mode buffer, is to do
>
>     (defvar my-special-mode-bindings-map
>         (let ((map (make-sparse-keymap)))
>           (define-key map (kbd "o") 'backward-char)
>           (define-key map (kbd "u") 'forward-char)
>           map))
>
>     (define-minor-mode my-special-mode-bindings "Docstring")
>
>     (add-hook 'special-mode-hook #'my-special-mode-bindings)
>
> so you don't have to go through every derivative of special-mode which
> rebinds those keys and unbind them in their map.

Yes, I thought about this variant some time ago, but it doesn't suit my
needs.  In reality I want something more complex than the described
example.  Like, in a couple of modes (derived from special-mode), I want
to use other commands for "o"/"u" keys, so I can bind them as usual.
But if I used a minor mode, its keys would take precedence over the
major modes, so I would have another problem.  Also I rebind many keys
in many minor modes, and these keys would surely conflict with the keys
from my minor modes that I would define as you suggest.

But thanks for your answers!  I really appreciate that you spent your
time on my question.

-- 
Alex



reply via email to

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