3

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?

2
  • 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, 2020 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! May 10, 2020 at 6:12

1 Answer 1

4

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 and acknowledge you have read our privacy policy.

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