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.

MetroWind
  • 165
  • 7
  • See [Eligible snippets](http://joaotavora.github.io/yasnippet/snippet-expansion.html#sec-2-1), `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

2 Answers2

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.

tarsius
  • 25,298
  • 4
  • 69
  • 109
  • I had to use ```git-commit-setup-hook``` instead of ```git-commit-mode```, as shown [here](https://emacs.stackexchange.com/questions/32983/insert-and-expand-snippet-when-committing-with-magit). Adding a hook to ```git-commit-mode``` somehow caused the standard Magit keybinds to be ignored. – unvarnished May 02 '22 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.

CodyChan
  • 2,599
  • 1
  • 19
  • 33