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

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

Re: Overriding major mode key bindings


From: Yuri Khan
Subject: Re: Overriding major mode key bindings
Date: Mon, 5 Sep 2016 20:14:41 +0600

On Mon, Sep 5, 2016 at 7:02 AM, Tim Johnson <tim@akwebsoft.com> wrote:

> I have keybindings established using 'global-set-key.
> Some are being clobbered by a major mode (python and elpy).
>
> I've tried the following with a mode-hook function:
> 1) unsetting those key sequences
> or
> 2) defining those key sequences as 'nil
> 3) remapping the mode functions to a keymap of my own device:
> i.e. a C-c n prefix.
>
> After some research, it looks like what I really should do is
> to create my own minor mode and and bind the keys the I want to
> "protect" to that minor mode.

If the bindings you are defining make sense as a toggleable
self-contained set, a minor mode is the way to go.

However, if they are just a random collection of bindings you find
more convenient than what the major modes offer, you also have an
option of 4) removing the conflicting bindings from the offending
major modes’ maps:

    (global-set-key (kbd "C-c C-c") 'compile)
    (defun my-python-keymap ()
      (local-set-key (kbd "C-c C-c") nil))
    (eval-after-load 'python
      (add-hook 'python-mode-hook 'my-python-keymap))

or 5) duplicating your bindings in their maps:

    (global-set-key (kbd "C-c C-c") 'compile)
    (defun my-python-keymap ()
      (local-set-key (kbd "C-c C-c") 'compile))
    (eval-after-load 'python
      (add-hook 'python-mode-hook 'my-python-keymap))



reply via email to

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