all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: Emacs <Help-gnu-emacs@gnu.org>
Subject: Re: Overriding major mode key bindings
Date: Mon, 5 Sep 2016 20:14:41 +0600	[thread overview]
Message-ID: <CAP_d_8XUP8YmX=G74etm7F7Df71zdt8qxOXzMv+mAN+9=chnOQ@mail.gmail.com> (raw)
In-Reply-To: <20160905000221.GA12566@mail.akwebsoft.com>

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	other threads:[~2016-09-05 14:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05  0:02 Overriding major mode key bindings Tim Johnson
2016-09-05 14:14 ` Yuri Khan [this message]
2016-09-05 21:37   ` Tim Johnson
2016-09-05 14:15 ` Grant Rettke
2016-09-05 15:16   ` Tim Johnson

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='CAP_d_8XUP8YmX=G74etm7F7Df71zdt8qxOXzMv+mAN+9=chnOQ@mail.gmail.com' \
    --to=yuri.v.khan@gmail.com \
    --cc=Help-gnu-emacs@gnu.org \
    /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.