1

I was using following answer: https://emacs.stackexchange.com/a/57535/18414 to set markdown on the .git/COMMIT_EDITMSG file.

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

My .gitconfig file, to open commit message with emacs:

[core]
    editor = TERM=xterm-256color emacsclient -t -q

On my emacs-daemon magit-git was enable.

Now during the commit (due to some squash operations in git), I see the commit messag along with the opened magit-diff: window.

Example image:

enter image description here

When I check the major-mode it became Local in buffer COMMIT_EDITMSG; global value is fundamental-mode.

Afterwards, when I added into COMMIT_EDITMSG file and do C-s C-x, commit fails and I get following message:

fatal: could not read commit message: No such file or directory

But instead if I re-enable markdown-mode, save and exit there would be no error.

[Q] Is it possible to force markdown-mode during git commit?

alper
  • 1,238
  • 11
  • 30

1 Answers1

2

You're using a package which is very opinionated about how things with Git should work, so don't be surprised if related Emacs configuration which works without Magit gets clobbered when you do use Magit.

In this instance, Magit uses git-commit.el which provides the variable git-commit-major-mode for controlling this.

If you want to control how things happen in Magit, you want to be checking the Magit documentation firstly.

phils
  • 48,657
  • 3
  • 76
  • 115
  • I am little bit lost about how to set `markdown-mode` under `magit-mode-hook`, or is it even possible. If I can't accomplish it, my only option is seems like `Type C-c C-c to finish, or C-c C-k to cancel` – alper Jul 01 '20 at 21:01
  • No need to use a hook to set this variable -- it's not buffer-local. Just use the `customize` link from `C-h v git-commit-major-mode`, or `setq` it in your init file. – phils Jul 01 '20 at 21:02
  • From customization I only have two options: `0 = text-mode 1= No major mode` . I setted to no major mode but didn't help – alper Jul 01 '20 at 21:06
  • 1
    Yep, just noticed that myself. That's pretty weird. You'll have to use this in your init file: `(setq git-commit-major-mode 'markdown-mode)` – phils Jul 01 '20 at 21:08
  • Now `markdown-mode` is enables on the file but still it generates a error `fatal: could not read commit message: No such file or directory`. But even mark-down mode seems on when I do `M-x mardown-mode` save and close error is seems gone – alper Jul 01 '20 at 21:11
  • And `major-mode` still seems as `fundamental-mode` :-( – alper Jul 01 '20 at 21:14
  • I don't know what the error issue is, sorry, but I suspect it's nothing to do with setting the major mode. Re your last comment, if you're referring to the global value then note that `major-mode`'s *global* value will always be `fundamental-mode` -- but the global value of this variable is irrelevant. – phils Jul 01 '20 at 21:29
  • You are right its mode became `markdown-mode`. But i have to do `markdown-mode` under M-x to handle the error. If I will able to solve it , i will update – alper Jul 01 '20 at 21:39
  • 1
    Tangentially, I see that the current version of Magit has fixed that `customize` issue for `git-commit-major-mode` (and even includes markdown as a default option). That alone won't change anything else, but I felt it was worth noting. – phils Jul 01 '20 at 22:26
  • When `emacs` started clean during commit `with-editor-finish` is not detected. I had to run `magit-status` but still `C-c C-c` won't bind to `with-editor-finish` on the buffer for `COMMIT_EDITMSG` – alper Jul 05 '20 at 23:20