reddit / emacs

I'm hitting C-x C-t (transpose-lines) too often when I mean C-c C-t, so I'd like to set the former key binding to nil. I've made several attempts at the proper elisp, but to no avail. Could someone help me?

Status-Detective-783 · 2022-03-11 23:05
Hacked from other examples. 1. (define-key org-mode-map (kbd "C-x C-t") 'nil) 2. (define-key org-mode-map (kbd "C-x C-t") nil) 3. (add-hook 'org-mode-hook '(lambda () (define-key org-mode-map (kbd "C-x C-t") #'nil)) I'll definitely learn elisp, eventually, but I'd sure like to be sure that I don't unknowingly mess up my org file in the meantime!
Illiamen · 2022-03-11 23:15
Keys under `C-x` aren't defined by major modes. They are not mode local. They exist globally. Normal options are (define-key ctl-x-map (kbd "C-t") nil) (define-key global-map (kbd "C-x C-t") nil) (global-set-key (kbd "C-x C-t") nil) (global-unset-key (kbd "C-x C-t")) See here: - https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Commands.html - https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Keymaps.html
Status-Detective-783 · 2022-03-11 23:20
I finally got something to work: (with-eval-after-load 'org (bind-key "C-x C-t" #'nil))
[deleted] · 2022-03-11 23:20
[deleted]
Status-Detective-783 · 2022-03-11 23:25
Ahh thanks, that didn't occur to me (though it should have)! I finally got an elisp format that sets the same thing in org-mode: (with-eval-after-load 'org (bind-key "C-x C-t" #'nil)) I'm not sure if that's the best way to do it, but it seems to work. I think I might keep this setting as an org-mode only setting, because the problem only occurs when I'm attempting to use the org-mode function `C-c C-a`. So when I eventually get to editing something in another mode and run across the transpose-lines binding again, it'll still work! (And I'll probably remove it altogether when I stop making that mistake.)
tcbr56 · 2022-03-12 11:45
Another candidate: `(define-key org-mode-map (kbd “C-x C-t”) #'undefined)`
Illiamen · 2022-03-12 15:04
To be clear, what you've written still changes the key binding globally, it just changes it after Org is loaded. I have not used the `bind-key` package, but you might be looking for something like the below: (with-eval-after-load 'org (bind-key "C-x C-t" #'ignore org-mode-map)) The difference with what I posted before is that `ignore` is a command that does nothing. Using `ignore` is not the same as unbinding a key in a keymap. For example, if you were to unbind a key in a mode's map, that key could still be bound to a command in the global map. This is the current situation, as Org mode does not bind a command to `C-x C-t`. Binding the key to `ignore` in the mode's map, which can override bindings in the global map with its own, effectively makes the key sequence do nothing for only that mode.