16

I'm trying unbind org-cycle-agenda-files which is set by default to C-' and C-,.

My weapon of choice to do so is use-package package.

On github.com/use-package/bind-key.el page I have found following lines:

;; To unbind a key within a keymap (for example, to stop your favorite major ;; mode from changing a binding that you don't want to override everywhere), ;; use `unbind-key': ;; ;; (unbind-key "c-c x" some-other-mode-map) 

This resulted in me unsuccessfully trying following variations:

(unbind-key "C-'" ) (unbind-key "C-," ) (unbind-key "C-'" (org-cycle-agenda-files)) (unbind-key "C-," (org-cycle-agenda-files)) (bind-keys :map org-mode-map :unbind "C-'") (unbind-key "C-'" org-cycle-agenda-files) 

After that fail I triyed some "traditional" solution to the problem.

Information found in gnu.org manual, and some emacs.stackexchange answers resulted in me producing following useless havoc:

(define-key (org-cycle-agenda-files) key nil) (define-key (current-global-map) "C-'" nil) (local-unset-key "C-'") (global-unset-key "C-'") (with-eval-after-load org-mode (unbind-key "C-'" org-mode-map) (unbind-key "C-," org-mode-map)) (global-set-key (kbd "C-'") 'nil) 

Yep.... None these variations vorks. :D

I would love to find use-package based solution, since I'm already using some of it's awesome capabilities.

Any kind of suggestion is welcome.

0

3 Answers 3

18

If you C-h f and enter unbind-key, the help says:

unbind-key is an autoloaded Lisp macro in `bind-key.el'.

(unbind-key KEY-NAME &optional KEYMAP)

Not documented.

The second argument to unbind-key is a key map -- for example org-mode-map.

This works for me:

(require 'bind-key) (unbind-key "C-," org-mode-map) (unbind-key "C-'" org-mode-map) 

A good place to put this would be the :config section of a use-package form.

5

Yeah the unbinding does not look elegant, but that's the main approach according to this answer.

As for use-package, I have been using unbind under :init directive like so:

:init (unbind-key "C-'" org-mode-map) (unbind-key "C-," org-mode-map) 
3
  • 3
    You need to put this inside :config, and not :init, because in :init the keymap may not be loaded yet. Commented Mar 1, 2020 at 10:12
  • :config didn't work for me. According to the use-package docs, you should use :bind with :map Commented Oct 7, 2022 at 7:29
  • The :config option works for me. The option to set nil in mode-map do not remove keys form listing, just set them nil. The :config option clear keys from map Commented Aug 3, 2023 at 21:38
5

Using use-package's :bind by setting the binding to nil worked for me in similar cases, but I use it with :straight org-plus-contrib and I do not know if this approach applies the same with built-in org:

(use-package org :straight org-plus-contrib :bind (:map org-mode-map ("C-," . nil) ("C-'" . nil))) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.