3

I recently updated magit to 20151025.1115, which gave me a message about git-commit-mode incompatibility. I now, instead, have a package git-commit at version 20151022.933 (from the magit project) installed alongside magit, both through the M-x list-packages interface). In my global git config, core.editor=emacs -nw. My emacs is version 24.5, compiled from source (Gentoo linux).

Before this update when I ran git commit from a terminal (outside of emacs), I would get an emacs instance in a mode aware of git commits -- "syntax" highlighting and C-c C-c to commit.

After this update when I run git commit, the emacs window is in Fundamental mode. I can still commit with C-s C-x but the mode is not git aware and I lose helpful text coloring of my commit message.

What do I need to change to get my terminal-launched commits to use a git-aware mode for commiting? Commiting within magit works as expected, I am just trying to "fix" the behavior from a git-launched emacs -nw session.

3

The problem is that the code which makes this happen has not been loaded yet. Maybe that code should be autoloaded, but currently it is not. (Unfortunately one can be fairly sure that if I did start to autoload the relevant code, that then someone complains about that.)

This is the code which causes git-commit-mode to be used in buffers visiting commit message buffers:

(add-to-list 'with-editor-server-window-alist
             (cons git-commit-filename-regexp 'switch-to-buffer))

So all you have to do is to add this to your init file:

(package-initialize) ; otherwise Emacs doesn't know were to find it
(setq package-initialize-at-startup nil) ; don't do it again

(global-git-commit-mode)

Additionally you might want to consider using core.editor=emacsclient.

  • Fwiw, the (require 'git-commit) did work. – casey Oct 29 '15 at 23:22
-1

This builds a bit from what @tarsius mentioned above but is less convoluted. git-commit-setup hasn't been loaded yet.

I wonder if it has to do with changes in the latest update to magit, but you have to (??) manually load it.

You could do all that @tarsius mentioned or just add

(global-git-commit-mode t) to your startup

  • You cannot enable global-git-commit-mode if Emacs doesn't know where it is defined. That's why I provided a "convolved" explanation, which also explains how to tell Emacs about the package/library (by calling package-initialize). – tarsius Dec 30 '15 at 0:35
  • You also should not call a minor-mode with t as argument. To turn on the mode no argument is required. In older Emacsen the argument was required, and one usually used 1 (one), not t. t appears to work as you intend for this particular mode, but there most certainly are modes which would fail with that argument. – tarsius Dec 30 '15 at 0:43

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.