0

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:

[core]
    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 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 <!--. – Keith Pinson Sep 30 at 19:22
  • @tarsius even if I just eval (setq-local comment-start "!") in that buffer, which does set comment-start, nothing changes. – Keith Pinson Sep 30 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 at 0:08
  • @tarsius yeah, that makes sense; that is what I would expect. My git-commit version is 20200828.1753 though: very new. – Keith Pinson Oct 6 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.