0

I usually change dictionaries when writing a git commit, however since I have a mapping to to change dictionary and run (flyspell-buffer) right after I see that flyspell goes beyond the commit message to check also comment lines starting with #.

How can I tell "flyspell, please ignore lines starting with # symbol"?

I've read that I can use flyspell-generic-check-word-predicate however my elisp is far from good :(, I came up with this:

(defun flyspell-ignore-comments ()
  "Used for 'flyspell-generic-check-word-predicate' to ignore comments."
  (not (string-match "^ *#" (thing-at-point 'line t))))
(put 'git-commit-mode 'flyspell-mode-predicate 'flyspell-ignore-comments)

However it doesn't work. What I'm doing wrong?

Community
  • 1
  • 1
zzantares
  • 341
  • 3
  • 12
  • 1
    Do you have `git-commit-turn-on-flyspell` in `git-commit-setup-hook`? If so, that should set `flyspell-generic-check-word-predicate` to `git-commit-flyspell-verify`, which ignores comments. – Kyle Meyer May 19 '16 at 22:00
  • Indeed @kyle-meyer, I have that setup, checking `(describe-variable flyspell-generic-check-word-predicate)` gives something like `Its value is git-commit-flyspell-verify Local in buffer COMMIT_EDITMSG; global value is nil` but still commented lines are marked as flyspell errors (filenames, dir names, the `Untracked files` part, etc) – zzantares May 19 '16 at 23:00
  • With `emacs -Q`, Magit 2.7.0, and `(add-hook 'git-commit-setup-hook #'git-commit-turn-on-flyspell)`, I'm not able to reproduce the issue (i.e. comments in commit messages are being ignored, as intended). – Kyle Meyer May 20 '16 at 04:17

1 Answers1

2

Ok, thanks to @KyleMeyer for make me doubt about my configuration, the issue was that I had enabled flyspell in a text-mode-hook, and that was interfering with the config for the git-commit-mode. Removing flyspell for loading in the text-mode-hook solved the problem.

Thanks.

zzantares
  • 341
  • 3
  • 12
  • Thanks for answering your own question. Your solution made me see an issue in my `.emacs`. I ran `flyspell-buffer` in the `flyspell-mode-hook` and this also gave me spelling errors in the comments of the commit buffer. – ppareit Feb 20 '22 at 13:13