2

I have C-RET set to other-window globally. For modes that would override this I manually add a hook to the mode's key map, e.g.

(add-hook 'magit-log-mode-hook (lambda () (local-unset-key (kbd "<C-return>"))))

This doesn't work for magit-status-mode-hook.

I've also tried

(define-key magit-status-mode-map (kbd "<C-return>") nil)

which has no effect either.

How do I tell magit-status-mode-hook to not interfere with my global setting?

1

1 Answer 1

6

First a general remark about un-/setting key bindings. Don't use a hook, instead do it on "library load time". That way you only do it once, which also helps if you later change the binding interactively for the current session. If you had used the hook to change the binding in your configuration, then that binding would be re-established every time you open a new buffer which uses the same major-mode, overriding your other binding again. Also local-unset-key is mostly intended for interactive use, I think. So use

(with-eval-after-load 'magit-log
  (define-key magit-log-mode-map (kbd "<C-return>") nil))

The reason unbinding C-RET doesn't appear to work in the status buffer is that Magit also uses text-property key bindings, bindings that only have an effect for certain parts of the buffer and that are established in keymap different from the mode keymap.

So you will need to search the source for keymaps that establish such bindings. Of course different syntaxes can be used for this particular key binding, but I think I used [C-return] in all cases (but did not double check). Which leads to the keymaps magit-file-section-map and magit-hunk-section-map, both defined in magit-diff.el.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.