A style-check.rb flycheck checker in Emacs

Posted on December 29, 2018

This post shows how to integrate style-check.rb with flycheck in the Emacs text editor.

style-check.rb checks:

Example screenshot

When the style-check.rb flychecker checker is functional, an example Flycheck Errors buffer is:

style-check.rb installation

Download from https://www.cs.umd.edu/~nspring/software/style-check-readme.html.

To test style-check.rb, create a test.tex file containing:

The way in which.

Then test style-check.rb (use the correct filepath):

/path/to/style-check.rb test.tex

It should output:

test.tex:4:1: The way in which. (The way in which)

flycheck integration

Put the following in your ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el (or whatever) file.

Edit the path to style-check.rb.

(require 'flycheck)
(flycheck-define-checker style-check
  "A linter for style-check.rb"
  :command ("/path/to/style-check.rb"
  ((warning line-start (file-name) ":" line ":" column ": "
            (message (one-or-more not-newline)
                     (zero-or-more "\n" (any " ") (one-or-more not-newline)))
  :modes latex-mode
(add-to-list 'flycheck-checkers 'style-check)

Enable flycheck for latex-mode:

(add-hook 'latex-mode-hook 'flycheck-mode)

style-check.rb will be executed against the latex content when you open a .tex file. Each time you save changes, style-check.rb will be executed.

Display the textlint warnings for file.txt in a Flycheck errors buffer with: C-c ! l .

Debugging If flycheck errors buffer shows no warnings, debug style-check.rb by running C-c ! C-c which will run style-check.rb in a new buffer, showing the raw output from style-check.rb.

Chaining other latex checkers

Flycheck can execute multiple checkers on a single file. For example, using the textlint flycheck check in conjunction with this style-check.rb checker. To do this in your Emacs init file (e.g. ~/.init.el), define the textlint checker then modify the style-check.rb checker to include:

:next-checkers ((warning . textlint))

Flycheck will now list warnings from both checkers.

A potential drawback of chaining checkers is multiple warnings about the same error from different checkers, e.g. spelling, phrasing or capitalisation.


Thanks to Blair Archibald for feedback on a draft of this post.