I frequently source the body of my GitHub PRs from my commits, and thus is makes sense to consider my commits to be made in Markdown (it is nice to have a markup language for commits anyway). Thus I customized Magit's git-commit-major-mode to be markdown-mode, but then all the # comment lines that Git inserts get formatted like markdown headers---highly undesirable! So I switched away from # as Git's comment delimiter. Somewhat randomly, I picked !, and added to my .gitconfig:

    commentChar = !

This keeps them from being formatted like headers, but I previously enjoyed the way that Magit had some understanding of these lines and would syntax-highlight them. I was hoping that there was some intelligence in the Git commit mode that would be able to mesh markdown mode with the original abilities of Magit, so that above the comment lines would be highlighted with Markdown, and the comment lines themselves would be highlighted by Magit (which is already aware of core.commentChar, because when I set commit buffers to have no major mode, it properly highlights the comments that use !).

My current configuration is usable, but with Emacs (and Magit especially) I always shoot for the stars. How do I achieve this?

  • 1
    Try setting the comment-start variable using git-commit-setup-hook.
    – tarsius
    Sep 30, 2020 at 19:06
  • @tarsius Thanks for the hint. I tried it haven't gotten the setting of comment-start to take. I added (defun kazark/!-as-comment-char () (setq-local comment-start "!")) to my .spacemacs and then used customize to add that to git-commit-setup-hook. However, it makes no difference, and when I check the value of comment-start in that buffer, it is still <!--. Sep 30, 2020 at 19:22
  • @tarsius even if I just eval (setq-local comment-start "!") in that buffer, which does set comment-start, nothing changes. Sep 30, 2020 at 19:27
  • Actually this is supposed to work without you doing anything except setting the git variable core.commentChar. That's implemented in git-commit-setup-font-lock. I just tested it and it works for me. I don't know why it doesn't work for you. Maybe you are using a very old version of the git-commit package.
    – tarsius
    Oct 4, 2020 at 0:08
  • @tarsius yeah, that makes sense; that is what I would expect. My git-commit version is 20200828.1753 though: very new. Oct 6, 2020 at 14:14

1 Answer 1


This is supposed to already work. Figuring out why it doesn't work for you will require a debugging effort on your part and I am afraid I won't be able to help you any more with that because I do not know enough about Spacemacs to do so. I suggest you ask for help from some other Spacemacs users.

  • A coworker who has his own Emacs configuration confirmed your results, and I submitted a Spacemacs issue. Because this appears to be a Spacemacs bug, I think it is reasonable to consider this the accepted answer. Thanks for the help. Dec 8, 2020 at 15:03
  • I have a fix for Spacemacs. Turns out mmm-mode was clobbering the correct behavior. Dec 9, 2020 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.