Git's editor config is set to launch emacs in no-window mode and to execute lisp function diff-mode:

git config --global core.editor "emacs -nw -f diff-mode"

However, when I execute git commit -v to edit a commit message (the -v flag provides the diff to the editor), diff-mode is not activated:

enter image description here

Manually activating the mode by executing the function (Mod+X diff-mode) does work at this point:

enter image description here

Why does the mode not get activated when I supply -f diff-mode on the command line?

  • Of course, if your setup works for you, that's great. But! If you're using both emacs and git, I would very much suggest that you try out the excellent package magit: magit.vc – MTS Feb 6 '20 at 20:08
  • 1
    @MTS I finally got around to testing magit out in my workflow, due to your comment. It has completely replaced my need for git outside of emacs. Thank you so much! – Bas Peeters May 10 '20 at 6:12

Command line arguments are processed in-order. So your -f diff-mode will put into diff-mode whichever buffer happens to be current right after Emacs has started (most likely it will be the *scratch* buffer). The next argument will probbaly look like /.../COMMIT_EDITMSG and will cause Emacs to load that file into some new buffer using some other major mode, determined by auto-mode-alist.

So your better option is probably to add to your ~/.emacs a rule

(add-to-list 'auto-mode-alist '("/COMMIT_EDITMSG\\'" . diff-mode))

where /COMMIT_EDITMSG\' is a regexp which recognizes specifically the name of the temp files used by git commit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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