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?

Bas Peeters
  • 193
  • 5
  • 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`: https://magit.vc/ – MTS Feb 06 '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 06:12

1 Answers1

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.

Stefan
  • 26,154
  • 3
  • 46
  • 84