all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Overriding major mode key bindings
@ 2016-09-05  0:02 Tim Johnson
  2016-09-05 14:14 ` Yuri Khan
  2016-09-05 14:15 ` Grant Rettke
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Johnson @ 2016-09-05  0:02 UTC (permalink / raw)
  To: Emacs


using GNU Emacs 24.3. on ubuntu 14.04

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.

1) and 2) fail to override the elpy bindings
3) works.

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.

See
http://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings/358#358

Am I on the right track? I am soliciting a second opinion.

If that's the way to go, I'm game to procede...

thanks
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Overriding major mode key bindings
  2016-09-05  0:02 Overriding major mode key bindings Tim Johnson
@ 2016-09-05 14:14 ` Yuri Khan
  2016-09-05 21:37   ` Tim Johnson
  2016-09-05 14:15 ` Grant Rettke
  1 sibling, 1 reply; 5+ messages in thread
From: Yuri Khan @ 2016-09-05 14:14 UTC (permalink / raw)
  To: Emacs

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))



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Overriding major mode key bindings
  2016-09-05  0:02 Overriding major mode key bindings Tim Johnson
  2016-09-05 14:14 ` Yuri Khan
@ 2016-09-05 14:15 ` Grant Rettke
  2016-09-05 15:16   ` Tim Johnson
  1 sibling, 1 reply; 5+ messages in thread
From: Grant Rettke @ 2016-09-05 14:15 UTC (permalink / raw)
  To: Emacs

On Sun, Sep 4, 2016 at 7:02 PM, Tim Johnson <tim@akwebsoft.com> wrote:
> 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.
>
> See
> http://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings/358#358
>
> Am I on the right track? I am soliciting a second opinion.

Yes because `global-set-key' bindings can easily get stomped on to
your point. The caveat is that it is fine if you only use it for
virtually never used keys. For example I use `f9' because it is a
long-reach and no one every binds to it. Sounds like you are bindings
keys that do get used often, and you aren't OK with that and that is
exactly why you would use a minor mode.

Happy hacking.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Overriding major mode key bindings
  2016-09-05 14:15 ` Grant Rettke
@ 2016-09-05 15:16   ` Tim Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Johnson @ 2016-09-05 15:16 UTC (permalink / raw)
  To: help-gnu-emacs

* Grant Rettke <gcr@wisdomandwonder.com> [160905 06:29]:
> On Sun, Sep 4, 2016 at 7:02 PM, Tim Johnson <tim@akwebsoft.com> wrote:
> > 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.
> >
> > See
> > http://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings/358#358
> >
> > Am I on the right track? I am soliciting a second opinion.
> 
> Yes because `global-set-key' bindings can easily get stomped on to
> your point. The caveat is that it is fine if you only use it for
> virtually never used keys. For example I use `f9' because it is a
> long-reach and no one every binds to it. Sounds like you are bindings
> keys that do get used often, and you aren't OK with that and that is
> exactly why you would use a minor mode.
> 
> Happy hacking.
  Thank you Grant. I will procede.
  (HHKL2-and-qisan-magicforce)
  :)

-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Overriding major mode key bindings
  2016-09-05 14:14 ` Yuri Khan
@ 2016-09-05 21:37   ` Tim Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Johnson @ 2016-09-05 21:37 UTC (permalink / raw)
  To: help-gnu-emacs

* Yuri Khan <yuri.v.khan@gmail.com> [160905 09:07]:
> 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:
<...> 
Good point:

I'm evaluating whether to use the minor mode approach. Because the
current mapping in a 'dolist operating on a (sequence . function)
alist, (hence eliminating redundant calls) it is easy enough to
switch over. 

however, since I also have a hook function for python-mode, a quick
fix is something like

(defun tj-python-mode-keys ()
  "Additional key bindings and rebindings for python-mode
  functions."
  ;; the following overrides of all of Jurgen's bindings
  ;; that conflict with mine.
  (define-key elpy-mode-map (kbd "C-c s") nil)
  (define-key elpy-mode-map (kbd "<C-return>") nil)
  (define-key elpy-mode-map (kbd "<S-return>") nil)
  (define-key elpy-mode-map (kbd "<C-S-return>") nil)
  (define-key elpy-mode-map (kbd "C-c C-b") nil)
  ; ...
  )
;; This code is after elpy is loaded and precedes my global
;; bindings.   

:) so many choices ...

thanks very much
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-05 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-05  0:02 Overriding major mode key bindings Tim Johnson
2016-09-05 14:14 ` Yuri Khan
2016-09-05 21:37   ` Tim Johnson
2016-09-05 14:15 ` Grant Rettke
2016-09-05 15:16   ` Tim Johnson

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.