0

I'd like to bind jump-to-register with C-', like this: (global-set-key (kbd "C-'") 'jump-to-register.

However, C-' is already bound to org-cycle-agenda-files.

I tried to unbind C-' with (global-unset-key (kbd "C-'")) but it didn't work.

What am I doing wrong?

crocefisso
  • 1,141
  • 7
  • 15
  • `global-set-key` sets the global keymap which is overridden by every other keymap including `org-mode-map`. See this [question](https://emacs.stackexchange.com/questions/75204/stop-later-modes-from-clobbering-a-global-keybinding) (out of many) for a recent discussion. – Fran Burstall Jan 08 '23 at 00:02
  • Is `global-unset-key` also overridden? How to unbind a key bound by `org-mode-map` then? – crocefisso Jan 08 '23 at 00:34
  • Your question is, as you say in your comment, **"How to unbind a key bound by org-mode-map "**. That's no doubt a duplicate question. – Drew Jan 08 '23 at 02:41
  • Yes it does, thank you very much. Here is the proper solution : `(define-key org-mode-map (kbd "C-'") nil)` and `(global-set-key (kbd "C-'") 'jump-to-register)` – crocefisso Jan 08 '23 at 03:07

1 Answers1

1

Solution:

(define-key (current-global-map) [remap org-cycle-agenda-files] 'jump-to-register)

Explanations:

Remapping Commands

You can tell Emacs that you want to replace all keys pointing to a certain command with one of your own choosing by using the remap notation.

You must do this instead of passing a key to the key bind function you are using. This is the best way of replacing existing commands with your own, as Emacs does the hard work of figuring out all the keys it needs to rebind.

Source: Mastering Emacs

EDIT:

Here is a preferable solution:

(define-key org-mode-map (kbd "C-'") nil)
(global-set-key (kbd "C-'") 'jump-to-register)
crocefisso
  • 1,141
  • 7
  • 15