Search code examples
emacshookkey-bindings

Can't use `local-unset-key` in emacs to remove keybindings in org mode


I want to remove the key binding about "C-j" under org mode, then I am using "local-key-unset" to do it, but when I go to org-mode, the key binding is not removed.

My code is as below:

 (add-hook 'org-mode-hook #'(lambda () (local-unset-key (kdb "C-j"))))

the org-mode-hook value is

Value: ((lambda nil (local-unset-key (kdb "C-j"))) #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-fold-show-all append local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes #[0 "\301\211\207" [imenu-create-index-function org-imenu-get-tree] 2] (lambda nil (progn (company-mode -1) (company-box-mode -1))) (lambda nil (set (make-local-variable 'line-spacing) 0.5)) (lambda nil (keymap-local-set (kbd "C-z") 'shell)))

when in the org mode, I use C-h k to find the C-j bindings, its result:

C-j runs the command org-return-and-maybe-indent (found in
org-mode-map)

I try to use C-j to replace C-x, I use this code

(global-set-key (kbd "C-j") ctl-x-map)

It worked very well. but when in the org mode, it seems to be shadowed by the major org-mode-map. I hope I can remove the C-j to unshadowed it.


Solution

  • You named function kbd wrong, as kdb:

    (add-hook 'org-mode-hook #'(lambda () (local-unset-key (kdb "C-j"))))
    

    When the hook function is invoked it in fact raises an error, such as this:

    File mode specification error: (void-function kdb)
    

    And when a hook function raises an error it's removed from the hook, so you see this error only the first time.

    Replace kdb with kbd and try again.