Run grammar check on Org buffers automatically with Language-Tool

Published on Mar 6, 2022, by Junji Zhi

I blogged about my LanguageTool setup a while ago. The default workflow is to invoke M-x langtool-check-buffer when I like it. But I find it too manual. So I set it up to run the check automatically right before saving an Org buffer.

The trick is to add it as a before-save-hook for org-mode:

(defun jz/org-mode-hook ()
  ;; Check grammar with langtool before save
  (add-hook 'before-save-hook 'langtool-check-buffer nil 'local))

(add-hook 'org-mode-hook 'jz/org-mode-hook)

With this, every time I save an org buffer, it runs the langtool check. All errors are highlighted, and I can invoke M-x langtool-correct-buffer to fix the errors one by one.

It works nicely alongside my Vale style linter:

Running language-tool automatically on org-mode, alongside Vale prose linter on Emacs and display linting errors