0

I configured git so that it uses emacsclient when editing commit messages. The only problem is that these messages are edited in fundamental-mode. Which hook should I use to have these commit messages buffer in markdown-mode?

  • 2
    You could use auto-mode-alist to designate .git/COMMIT_EDITMSG as a file which should be opened with markdown-mode. – DoMiNeLa10 Apr 18 '18 at 9:58
  • Thanks. Adding (add-to-list 'auto-mode-alist '("COMMIT_EDITMSG" . markdown-mode)) solved my problem. – Damian Nadales Apr 18 '18 at 21:06
2

Git uses .git/COMMIT_EDITMSG as the temporary file for the commit message. Since Emacs will be prompted to edit it by git, you can associate that file with markdown-mode by adding something like

(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG" . markdown-mode))

to your init file.

1

Not an answer to the question (@DoMiNeLa10♦ already answered it perfectly), but I thought that it might be useful to point out that markdown is not the best highlighting mode for git commit messages.

There is a perfect mode for this and it is called git-commit, available on Melpa.

Adding (setq global-git-commit-mode t) to your init file will automatically open COMMIT_EDITMSG buffers in git-commit-mode.

There are other highlighting packages for other types of git files (.gitignore, etc.) also on Melpa.

None of these packages require magit (git-commit-mode is actually a minor mode from which the magit git-commit-major-mode is built).

0

I believe this will do what your after, but i have not tested personally

(setq git-commit-major-mode 'markdown-mode)

Looking at the code in the link below its set with defcustom to allow you to override to any mode you like.

https://github.com/magit/magit/blob/31835d1108c951c5ee2744b4ab1b0d8a9e119636/lisp/git-commit.el#L165

  • Doesn't git-commit-major-mode require the use of magit? (which I don't use...) – Damian Nadales Apr 18 '18 at 12:44
  • 1
    yes it does, did not realize magit was not available in which case @DoMiNeLa10 solution maybe what you need. – Oly Apr 18 '18 at 13:05

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.