Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar checking in source code comments #22

Open
mattiasdrp opened this issue Sep 30, 2022 · 4 comments · May be fixed by #25
Open

Grammar checking in source code comments #22

mattiasdrp opened this issue Sep 30, 2022 · 4 comments · May be fixed by #25
Labels
enhancement New feature or request

Comments

@mattiasdrp
Copy link

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.

@jcs090218
Copy link
Member

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.

@jcs090218 jcs090218 added the enhancement New feature or request label Oct 19, 2022
@mattiasdrp
Copy link
Author

mattiasdrp commented Oct 19, 2022

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 ;-)

@jcs090218
Copy link
Member

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!

@mattiasdrp
Copy link
Author

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants