mhayashi1120/Emacs-langtool

being aware of the environment

Opened this issue ยท 8 comments

When typing something else than just text, let's say a LaTeX document, langtool is not aware of the LaTeX syntaxe and found a lot of small errors due to that. It would be great if it would deal with environments only and ignore LaTeX commands for example.

Actually, I don't really think it's possible since LanguageTool isn't aware of the syntax... so, it's more a question: is that possible without too much work or not really ?

Very difficult for me ;-)

But, sometimes I am considering some ways of to solve this problem.
Programming comment, quoted string and etc..

For LaTeX, one could just use 'detex -c' on the current buffer before passing it on to langtool. This command strips away all latex markup. 'detex' is included in TeXLive package (texlive-extra-utils on Debian). An example to follow can be found here: http://ftp.sunet.se/pub/gnu/emacs-lisp/archive/diction.el

This is also an issue with org-mode files, as initial indentation, code in BEGIN..END blocks and properties are all flagged.

Same here with asciidoc and code blocks. Maybe ignoring some warnings if the incriminated hunk matches a regex would do the trick

The LanguageTool API provides the AnnotatedTextBuilder class to check text with markup (https://languagetool.org/development/api/org/languagetool/markup/AnnotatedTextBuilder.html). I'm not sure how this would integrate with Emacs, though.

I would love to see this implemented ๐Ÿ˜„

The problem with detex is that I couldn't make him replace non-text thing with spaces, losing the correct word positions...
But I made it work by copying the buffer, replacing the non-text parts with spaces using regex, launching langtool and this modified buffer and displaying the results on the original buffer.
Proper implementation should include a user-defined list of regexp to clean the file.
Does it look like a good solution for you ?

I also wanted Langtool to ignore LaTeX so I implemented a small package that allows you to tell Langtool to ignore certain regions of text based on their font. I used this effectively to stop Langtool from complaining about stuff in LaTeX math-mode and also LaTeX comments. See here https://github.com/cjl8zf/langtool-ignore-fonts. Perhaps one day this could be added to the Emacs Langtool package.