3

Possible Duplicate:
Override Ctrl-TAB in EMACS org.mode

I'm trying to rebind C-y to redo. I've tried all possible options:

(global-unset-key (kbd "C-y")), outside and inside a org mode hook, and (define-key org-mode-map (kbd "C-y") nil).

Yet nothing. Outside of OrgMode it acts perfectly fine, but inside? it yanks. This is actually not to first KeyBinding that doesn't work whenever I'm inside OrgMode, and it boggles me.

Help, please.

Community
  • 1
  • 1
Devon Ville
  • 2,001
  • 2
  • 19
  • 32
  • 1
    If you've "tried all possible options", there's not much point in asking the question, surely? :) – phils Oct 15 '12 at 22:41
  • Fair enough;) I've tried all options I'm currently aware of. – Devon Ville Oct 15 '12 at 22:42
  • Is this a duplicate of: http://stackoverflow.com/questions/4333467/override-ctrl-tab-in-emacs-org-mode ? (it's not clear whether you were trying to set the `org-mode-map` binding before or after org mode had loaded). You can also use this approach: http://stackoverflow.com/questions/2736087/eval-after-load-vs-mode-hook – phils Oct 15 '12 at 22:42
  • I've tried both loading before and after. And oddly enough, for local-set-key it does work. Do you have any explanation as to why it works with local-set-key and not with global-set-key inside a org-mode hook? – Devon Ville Oct 15 '12 at 22:49
  • `global-set-key` affects the global keymap. `local-set-key` affects (usually) the keymap for the major mode of the current buffer. Major mode keymaps take precedence over global keymaps (and minor mode keymaps take precedence over major mode maps). This article is an excellent primer on this (somewhat complex) topic: http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/ – phils Oct 15 '12 at 23:00
  • Thanks for the tip. I did stumble upon this site once. I guess now I should give it its credit;) Eventually I found this to work ATM: http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/1758639 – Devon Ville Oct 15 '12 at 23:14

1 Answers1

3

After quick help from the fabulous phils, I stumbled upon two things: Globally override key binding in Emacs which I currently use, and http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/ which I will surely read ASAP.

Thanks Phils;)

My current setup is this:

(defvar custom-keys-mode-map (make-keymap) "custom-keys-mode keymap.")
(define-minor-mode custom-keys-mode
  "A minor mode so that my key settings override annoying major modes."
  t " my-keys" 'custom-keys-mode-map)
(custom-keys-mode 1)

(defun my-minibuffer-setup-hook ()
  (custom-keys-mode 0))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)

(defadvice load (after give-my-keybindings-priority)
  "Try to ensure that my keybindings always have priority."
  (if (not (eq (car (car minor-mode-map-alist)) 'custom-keys-mode))
      (let ((mykeys (assq 'custom-keys-mode minor-mode-map-alist)))
        (assq-delete-all 'custom-keys-mode minor-mode-map-alist)
        (add-to-list 'minor-mode-map-alist mykeys))))
(ad-activate 'load)
(define-key custom-keys-mode-map (kbd "<C-key>") 'some-command)
Community
  • 1
  • 1
Devon Ville
  • 2,001
  • 2
  • 19
  • 32
  • Thank you very much -- greatly appreciated. I found this answer useful to set several keys in org-mode, when prior attempts at global-unset-key had no effect. – lawlist Jul 07 '13 at 03:48