vim has a really great feature for defining keybindings.
from the vim docs:
:cno[remap] {lhs} {rhs} |mapmode-c| *:cno* *:cnoremap*
Map the key sequence {lhs} to {rhs} for the modes
where the map command applies. Disallow mapping of
{rhs}, to avoid nested and recursive mappings. Often
used to redefine a command.
Basically, the :cnoremap
command creates a keybinding, but forbids any further redefinitions of it. This made defining keybindings in vim always easy for me. However, in emacs i don't know such a command - currently I use commands like (global-set-key [f8] 'my/copy-to-clipboard)
to define my keybindings. Unfortunately, this is really a pain, because other packages can easily remap that (in my case, the evil
package).
How can i define a keybinding in emacs, which can't be modified, once it is set?
Important edit: I don't want to restrict what can be done to lhs
- I want just prevent a redefinition/modification of rhs
.
helm-find-files-map
, I expect you can make helm use in its place a custom keymap which inherits from the original keymap. Other code will modify the original by name, while you can define custom bindings in the new map where they will always take precedence. – phils Jul 02 '16 at 08:51rhs
part is taken into account "as is" - but anyone can create another remap and override thelhs
(i.e. the command you created). So, what do you want in Emacs, to know thatF8
is mapped to a certain sequence, sequence that has a certain/fixed meaning, or that nobody else shouldn't be able to remapF8
? These are two different things, as I see it. – VanLaser Jul 02 '16 at 09:06F8
(or any other key or key sequence of course) to execute a certain function, exactly like I've defined it. (And for me, this implies that nobody else/no package can prevent me from doing that - which means, my keybinding should overwrite all keybindings defined by other packages) – uuu Jul 02 '16 at 09:36C-c m
or any other.) – uuu Jul 02 '16 at 09:37lhs
to some other command. I'm saying, you want X, but quote Y, and that is confusing. Basically, one can makeF8
run another command, yes, but also one can simply re-write the commandF8
is calling (so it has the same name, but it does something else) - and that is a 2nd problem, not related to the 1st, and closer to the original vim help quote (!). – VanLaser Jul 02 '16 at 12:01rhs
. I didn't thought about what I want withlhs
to do first, but now to not restrict modification/redefinition/whatever oflhs
at all. Good point, i'll explain that in my question. – uuu Jul 02 '16 at 12:22<f8>
is not "forbidden". But it is, by convention, reserved for users (as you say). (2) The OP might be a user, and the use here might be for a user ("to define my keybindings"). It is good to remind library authors that<f5>
to<f9>
are reserved for users, but I wouldn't put this so categorically. Just one opinion. – Drew Jul 02 '16 at 14:30