2

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.

3
  • See Eligible snippets, git-commit-mode is a minor mode.
    – npostavs
    Oct 19, 2016 at 22:18
  • @npostavs, Thank you. This is strange... Because on some minor mode, Yasnippet does work. For example I use a minor mode called "beancount" under org-mode, and it works with Yasnippets just fine...
    – MetroWind
    Oct 19, 2016 at 22:29
  • If you mean your org-mode snippets work just fine, then that's expected. If you mean your beancount snippets work too, then perhaps beancount has some code to enable them?
    – npostavs
    Oct 20, 2016 at 13:36

2 Answers 2

3

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.

1
  • I had to use 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
0

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.

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.