1

I have set Git's "core.editor" config to "emacsclient" and have an Emacs session running with a server started. When I run "git commit" from a terminal, it opens a new buffer in my Emacs as expected, but this buffer is always in "fundamental mode". It used to open in whatever mode that magit uses to edit commit messages but this is a new computer and I am just not sure how all the pieces work together. It's not even clear to me what mode magit is using since it's a collection of minor modes not a major mode. So I'm a bit stumped how to fix this.

Any help appreciated!

okonomichiyaki
  • 8,355
  • 39
  • 51
  • Magit uses `git-commit mode` to write commit messages. You can check if that is installed – TheGeorgeous May 26 '16 at 04:06
  • 1
    That's not what I see when I commit from magit, I think it's in text mode with a bunch of minor modes. This is what describe-mode says: "Enabled minor modes: Async-Bytecomp-Package Auto-Composition Auto-Compression Auto-Encryption Auto-Fill Blink-Cursor Diff-Auto-Refine Electric-Indent File-Name-Shadow Font-Lock Git-Commit Global-Font-Lock Global-Git-Commit Ido-Everywhere Line-Number Magit-Auto-Revert Menu-Bar Mouse-Wheel Shell-Dirtrack Tooltip Transient-Mark With-Editor" – okonomichiyaki May 26 '16 at 15:36
  • Hmm this is weird. I was going to add that "git commit mode" didn't seem to be installed or available, but it actually is available only AFTER I start using magit in a particular session – okonomichiyaki May 26 '16 at 15:39

4 Answers4

3

I'm not sure what magit uses, but vc should use a variant of log-edit-mode.

(require 'log-edit)
(require 'vc-git)
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG\\'" . vc-git-log-edit-mode))

It's really weird that I need the requires; there's either a bug in Emacs or I'm doing something weird (though it doesn't seem the least bit weird to me).

jpkotta
  • 9,237
  • 3
  • 29
  • 34
1

I had the same problem and found solution here:

https://emacs.stackexchange.com/a/17733/12560

Actually I just had to add

(global-git-commit-mode)

to my init and it worked.

Community
  • 1
  • 1
bingen
  • 1,191
  • 11
  • 9
1

As an extension to @bingen's answer, if you are a use-package user,

(use-package git-commit
  :init
  (global-git-commit-mode)
  )

which works even with lazy loading turned on:

(setq
 use-package-always-defer t
 use-package-always-ensure t
 )
Community
  • 1
  • 1
0

The reason for this is that git-commit.el has not been loaded yet and/or that the server has not been started yet. These things have always already been taken care of when you commit from Magit because in order to do so, Magit has to be loaded and doing that involves loading git-commit and starting the server.

You can add the following to your ~/.emacs or init.el to enable git-commit-mode:

(require 'git-commit)
(server-mode)

Reference: git-commit-mode isn’t used when committing from the command-line

Jake Ireland
  • 543
  • 4
  • 11