Grammar checking in source code comments
mattiasdrp opened this issue ยท 4 comments
Hi,
Thanks a lot for this package!
I wondered if it was possible to have a mode similar to flyspell-prog-mode to check grammars in source code comments, doc and strings.
Sorry for the late reply. Being busy with something else! ๐
This require a parser to parse things correctly. Does flyspell do that already? But this indeed a nice feature to have.
Flyspell already does it with a simple trick:
First they set a predicate: (that's used here for example)
flyspell-generic-check-word-predicate
And when in prog-mode they set it to:
(setq flyspell-generic-check-word-predicate
#'flyspell-generic-progmode-verify)
With flyspell-generic-progmode-verify
being:
(defun flyspell-generic-progmode-verify ()
"Used for `flyspell-generic-check-word-predicate' in programming modes."
(unless (eql (point) (point-min))
;; (point) is next char after the word. Must check one char before.
(let ((f (get-text-property (1- (point)) 'face)))
(memq f flyspell-prog-text-faces))))
And flyspell-prog-text-faces
uses font-lock
:
(defcustom flyspell-prog-text-faces
'(font-lock-string-face font-lock-comment-face font-lock-doc-face)
"Faces corresponding to text in programming-mode buffers."
:type '(set (const font-lock-string-face)
(const font-lock-comment-face)
(const font-lock-doc-face))
:version "28.1")
(this variable needs to be customised when using tree-sitter by adding
tree-sitter-hl-face:comment
tree-sitter-hl-face:doc
tree-sitter-hl-face:string
)
No worries for the late reply ;-)
Thanks for the information!
Just to let you know, PRs are welcome if you got any idea implementing this feature! I would take a harder look once I have time for this package!
Yes, I was thinking about doing a PR but like you I have other things to do first ;-)
I'll come with a proposal when I can :-)