1

proselint is a prose linter which returns error/warning messages like this:

2020-09-09-still-processing.md:18:14: typography.symbols.curly_quotes Use curly quotes “”, not straight quotes "".

I know there is a proselint checker in Flycheck, but I am trying to configure Flymake. For this task, I am using flymake-easy like this:

(defconst flymake-proselint-err-line-patterns
  '(("^\\(.*\.md\\):\\([0-9]+\\):\\([0-9]+\\): \\(.*\\)$" 1 2 3 4)))

(defvar flymake-proselint-executable "proselint"
  "The proselint executable to use for syntax checking.")

(defun flymake-proselint-command (filename)
  "Construct a command that flymake can use to check Markdown in FILENAME."
  (list flymake-proselint-executable filename))

(defun flymake-proselint-load ()
  "Configure flymake mode to check the current buffer's ruby syntax."
  (interactive)
  (flymake-easy-load 'flymake-proselint-command
                     flymake-proselint-err-line-patterns
                     'tempdir
                     "md"))

(defun flymake-proselint-maybe-load ()
  "Call `flymake-proselint-load' if this file appears to be Markdown."
  (interactive)
  (if (and buffer-file-name
           (string= "md" (file-name-extension buffer-file-name)))
      (flymake-proselint-load)))

I added flymake-proselint-maybe-load to markdown-mode-hook but flymake-show-diagnostics-buffer shows an empty buffer instead of the above-mentioned message from proselint.

My guess is I am setting flymake-proselint-err-line-patterns, but I am not sure if this is the problem.

0

1 Answer 1

2

I took another approach, using flymake-quickdef, so as to leverage flymake-diagnostic-functions:

(require 'flymake-quickdef)
(flymake-quickdef-backend
  flymake-proselint-backend
  :pre-let ((proselint-exec (executable-find "proselint")))
  :pre-check (unless proselint-exec (error "proselint not found on PATH"))
  :write-type 'pipe
  :proc-form (list proselint-exec "-")
  :search-regexp "^.+:\\([[:digit:]]+\\):\\([[:digit:]]+\\): \\(.+\\)$"
  :prep-diagnostic
  (let* ((lnum (string-to-number (match-string 1)))
         (lcol (string-to-number (match-string 2)))
         (msg (match-string 3))
         (pos (flymake-diag-region fmqd-source lnum lcol))
         (beg (car pos))
         (end (cdr pos)))
    (list fmqd-source beg end :warning msg)))

(defun flymake-proselint-setup ()
  "Enable flymake backend."
  (add-hook 'flymake-diagnostic-functions #'flymake-proselint-backend nil t))

Then it's just a matter of adding flymake-proselint-setup to markdown-mode-hook:

(add-hook 'markdown-mode-hook #'flymake-proselint-setup)
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.