4

I am trying to create a new key-bind that will work fine in all modes except for one, where it conflicts with another. For example:

(global-set-key (kbd "<C-S-down>") 'move-line-down)

Is there a simple way (without setting it for specific local modes) to make it global excluding a specific mode?

scottyaz
  • 722
  • 7
  • 18
  • 1
    Is the conflicting mode a major or minor mode? In the latter case, you could put your key binding in a minor mode and ensure that `minor-mode-map-alist` gives the correct precedence. – François Févotte Jan 06 '13 at 18:15
  • 2
    Global key bindings *cannot* clobber major or minor mode keybindings. The latter take precedence (minor over major over global). I would avoid referring to a binding as 'global' (and referencing `global-set-key`) if you are not explicitly referring to the global keymap, because it will just confuse matters. Do you actually want to create a binding that takes precedence over all major and minor mode maps (save for one)? – phils Jan 06 '13 at 20:29
  • @Francesco The conflicting key bind is in a major mode. – scottyaz Jan 07 '13 at 02:09

2 Answers2

1

You could add a function to after-change-major-mode-hook that would set the key in the current local keymap, except for the specific modes you would like to avoid.

Lindydancer
  • 25,428
  • 4
  • 49
  • 68
0

If you want to exclude one specific mode, you can do the following:

(global-set-key (kbd "<C-S-down>") 'move-line-down) 

to make it globally available, and

(define-key KEYMAP (kbd "<C-S-down>") nil) 

to exclude one mode where KEYMAP is the name name of the mode, followed by "mode-map" (e.g. ess-mode-map). You could also bind the original thing to the key instead of nil.

PascalVKooten
  • 20,643
  • 17
  • 103
  • 160