[WiP] Added a prog mode to flycheck-languagetool#25
Open
mattiasdrp wants to merge 1 commit intoemacs-languagetool:masterfrom
Open
[WiP] Added a prog mode to flycheck-languagetool#25mattiasdrp wants to merge 1 commit intoemacs-languagetool:masterfrom
mattiasdrp wants to merge 1 commit intoemacs-languagetool:masterfrom
Conversation
0956ef3 to
95a0ae3
Compare
jcs090218
reviewed
Nov 26, 2022
| (flycheck-languagetool-flycheck-add-mode major-mode) | ||
| (add-to-list 'flycheck-checkers 'languagetool) | ||
| (setq flycheck-languagetool--text-mode nil) | ||
| (flycheck-add-next-checker (flycheck-get-checker-for-buffer) 'languagetool)) |
Member
There was a problem hiding this comment.
Few comments:
- Maybe we should get rid of the
(require 'flycheck-mode)here since we already have it at the very top. - I don't think enabling
flycheck-modeand such a setup is a good idea, we usually let the user decide weather theflycheck-modeis enabled or not. Of course, we can still expose a function for that but we need to clarify so the user don't get confuse betweenflycheck-languagetool-flycheck-enableandflycheck-languagetool-setup. (Might need to update the README for this) - Should the variable
flycheck-languagetool--text-modebedefvar-local? Anyway, I think it's better if we reuseflycheck-languagetool-setupfor prog-mode as well. For example,
(defcustom flycheck-languagetool-prog-modes
'(actionscript-mode haxe-mode nxml-mode yaml-mode)
"List of extra `prog-mode'.")
(defun flycheck-languagetool-prog-mode-p ()
"Return non-nil if current buffer is programming mode."
(or (derived-mode-p 'prog-mode)
(memq major-mode flycheck-languagetool-prog-modes)))then
(defun flycheck-languagetool-setup ()
"Setup flycheck-package."
(interactive)
(when (flycheck-languagetool-prog-mode-p)
(flycheck-languagetool-flycheck-add-mode major-mode)
(flycheck-add-next-checker (flycheck-get-checker-for-buffer) 'languagetool))
;; do it whenever this is programming mode or not
(add-to-list 'flycheck-checkers 'languagetool))
;;;###autoload
(defun flycheck-languagetool-flycheck-enable ()
"Enable flycheck languagetool integration for the current buffer.
This adds languagetool as the next checker of the main checker
of the current buffer"
(interactive)
(flycheck-mode 1)
(flycheck-stop)
(setq flycheck-languagetool--text-mode nil) ; still not quite sure what this does
(flycheck-languagetool-setup)) ; reuse itThis way, user wouldn't need to do extra configuration for prog-mode support. BTW, above code is an example, so please change it to make it work! ;)
Author
There was a problem hiding this comment.
Thanks for the review! This is clearly a work in progress, I needed to do something minimal that worked to start the process of iterating over it. I'll look into your suggestions :-)
This is done by filtering out the errors that don't point to a place that has not
a comment, a string or a doc face. The checker is added as the next checker of
the main flycheck checker for the current mode
I still have some issues as to when the function `flycheck-languagetool-flycheck-enable` has to be used
In my current setup what I did is:
```elisp
(use-package flycheck-languagetool
:load-path "lisp/flycheck-languagetool/"
;; :custom ((flycheck-languagetool-active-modes
;; '(text-mode latex-mode org-mode markdown-mode message-mode prog-mode)))
:hook ((text-mode . flycheck-languagetool-setup)
(lsp-mode . (lambda () (lsp-diagnostics-mode 1)
(require 'flycheck-languagetool)
(flycheck-languagetool-flycheck-enable))))
;; :ensure-system-package
;; ("LanguageTool-5.9-stable/languagetool-commandline.jar" . "curl -L https://raw.githubusercontent.com/languagetool-org/languagetool/master/install.sh | sudo bash -a")
:init
(setq flycheck-languagetool-server-jar (expand-file-name "~/.emacs.d/LanguageTool-5.9-stable/languagetool-server.jar"))
)
```
But this is not really good.
The issue is that if languagetool is added as a checker before the main-mode
finished loading, it's not added as a next checker for the main one and the
function needs to be called again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is done by filtering out the errors that don't point to a place that has not a comment, a string or a doc face. The checker is added as the next checker of the main flycheck checker for the current mode
I still have some issues as to when the function
flycheck-languagetool-flycheck-enablehas to be usedIn my current setup what I did is:
But this is not really good.
The issue is that if languagetool is added as a checker before the main-mode finished loading, it's not added as a next checker for the main one and the function needs to be called again.
Fixes #22
If this seems good for you, I think an improvement would be to define a predicate function
This would allow to define different predicates for different modes (prog-mode don't have the same predicates as org-mode or markdown-mode for example)