I have written a snippet for git-commit-mode
. However when I'm writing a commit message (from Magit), the snippet won't trigger. Does anyone know how to fix this?
I have yasnippet version 20160924.2001, and Emacs 24.5.1.
git-commit-mode
is a minor-mode but you have limited the snippets to be used with a major-mode git-commit-mode
. Such a major-mode no longer exists, so you have to use a different mechanism to restrict your snippets to "when I edit a commit message".
The reason git-commit-mode
is a minor-mode is to allow you to choose the major-mode most suitable for commit messages according to the conventions used by the projects you contribute to. By default this is text-mode
, but if some project uses Markdown or Org-Mode for commit messages, then you can configure that on a per project basis.
Assuming you have some snippets that are appropriate for text-mode
+git-commit-mode
, but not just text-mode
or say markdown-mode
+git-commit-mode
, then use something like:
(add-hook 'git-commit-mode
(lambda ()
(when (derived-mode-p 'text-mode)
(yas-activate-extra-mode 'text-mode+git-commit-mode))))
You then have to define your snippets as if there actually existed a major-mode named text-mode+git-commit-mode
.
git-commit-setup-hook
instead of git-commit-mode
, as shown here. Adding a hook to git-commit-mode
somehow caused the standard Magit keybinds to be ignored.
May 2, 2022 at 22:35
By default the major-mode for git-commit-mode
is text-mode
, if your yasnippet
doesn't work in text-mode
, it won't work in git-commit-mode
either, so you may want to change it to other mode like org-mode
using (setq git-commit-major-mode 'org-mode)
org-mode
is my default major-mode for unrecognized files.
git-commit-mode
is a minor mode.