1

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.

  • See Eligible snippets, git-commit-mode is a minor mode. – npostavs Oct 19 '16 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 '16 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 '16 at 13:36
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.

Your Answer

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

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