I have configured git to use emacs as editor for writing commit messages (with (start-server)
in my init.el). I now want to put a template message (e.g. Bug #1234:
) on top of the commit message buffer (so that it's on top of every commit message). How can I detect the opened commit buffer to insert my template string on top of it?
Asked
Active
Viewed 103 times
0

Student
- 103
- 3
1 Answers
1
You'll want to adapt this to your needs:
(add-hook 'server-visit-hook
(defun my/git-commit-preflight ()
(when (search-forward "# Changes to be committed:")
(goto-char (point-min))
(insert "Bug #1234: "))))
Note the use of defun
rather than anonymous lambda
. This results in a tractable, human-readable server-visit-hook
.

Phil Hudson
- 1,741
- 10
- 13
defun
: "The return value is undefined.". Hence, it would be better to define the function separately and add it as(add-hook 'server-visit-hook #'my/git-commit-preflight)
. – Lindydancer Apr 24 '22 at 19:06