1

I'm a happy Magit user, and at commit time, I am accustomed to editing a commit message and then finishing the edit with C-c C-c. But sometimes that key sequence winds up bound to the compile function, as indeed my emacs init file contains the line

(global-set-key "\C-c\C-c" 'compile)

My init file also sets that key locally in a number of modes including c-mode, sml-mode, lua-mode, and so on. However, none of those modes is displayed on the mode line in the commit-edit window. And when emacs is working correctly, C-c C-c finishes the edit and returns to git as expected. However, every so often it gets wacky and insists on being bound to compile.

Following a trail of emacs lisp leads a very short distance to where Magit invokes git with $EMACSCLIENT set appropriately. Beyond that point I have been unable to diagnose how that buffer is created or where its keybindings are determined.

The problem I'm trying to solve is to set the keybindings in the commit-message edit buffer so that C-c C-c terminates the edit and returns control to git. At the moment, the only way I can do this is to exit emacs and start over. That workaround doesn't last long, and it grows tiresome.

I would welcome answers to any or all of the following questions:

  1. Where are the keybindings set for that window?

  2. What function is C-c C-c bound to by default?

  3. Is there a mode or other hook where I can just reach in with a hammer and bind C-c C-c to the right function?


Addendum: the buffer's major mode is text-mode. Here is the response to C-h v major-mode RET:

Its value is text-mode
Original value was fundamental-mode
Local in buffer COMMIT_EDITMSG; global value is fundamental-mode
4

1 Answer 1

1

Thanks to commenters, this is what I was able to learn:

  1. Some keybindings were set by an overeager after-change-major-mode-hook, which doubtless was a workaround for a legacy bug somewhere. (The question of where the correct keybinding is set remains unanswered.)

  2. The function bound by default is with-editor-finish, which I eventually discovered by starting with emacs -q

  3. I reached in with the hammer of after-change-major-mode-hook, or rather, I made the hammer that I already found there hit with a little less force.

Of the resources named in the comments, How can I find out in which keymap a key is bound? provided no useful information—lots of things were set to nil. But looking at the major and minor modes were most excellent hints!

2
  • 2
    locate-key-binding from the linked question got me Minor-mode: with-editor-mode: with-editor-finish (in addition to the nils), but that's starting from emacs -Q.
    – npostavs
    Apr 12, 2016 at 19:53
  • 2
    "The question of where the correct keybinding is set remains unanswered." - with-editor.el:324
    – npostavs
    Apr 12, 2016 at 19:55

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.