15

I've got a heap of org-mode files which I publish into HTML for a knowledge base, sometimes the publishing crashes out due to a broken link or something and it's hard to find the problem.

I've been recently using org-lint to find the problems. Is there a way to run this automatically through flycheck?

map7
  • 503
  • 3
  • 15
  • 1
    why not run it via org-export-before-processing-hook? I think to use flycheck you need an external program for linting. It looks like it might be possible to write elisp functions in flycheck-define-generic-checker that would work with org-lint and do what you want in flycheck. – John Kitchin Dec 22 '16 at 18:41
  • Maybe running it before you export would be good enough? If you check every time you save it would be too expensive. – xji Jan 06 '17 at 17:05
  • @JohnKitchin: External programs are common but not needed, though in this case the natural external program to run would be emacs itself :) – Clément May 06 '20 at 13:14

1 Answers1

8

I tried to restrict the linting to one checker with (org-lint '(link-to-local-file)), however the parsing is still going to induce a noticable delay. Maybe limiting the linter to the current subtree or using the async library can improve the performance. Anyways, below is a rather simple flycheck setup for org-lint:

(flycheck-define-generic-checker 'org-lint
  "Syntax checker for org-lint."
  :start 'flycheck-org-lint-start
  :modes '(org-mode))

(defun flycheck-org-lint-start (checker callback)
    (funcall
     callback 'finished
     (save-excursion
       (mapcar
        (lambda (err)
          (goto-char (car err))
          (flycheck-error-new-at
           (org-current-line) (1+ (current-column))
           'warning (cadr err) :checker checker))
        (org-lint-link-to-local-file (org-element-parse-buffer))))))

(add-to-list 'flycheck-checkers 'org-lint)
mutbuerger
  • 3,434
  • 14
  • 22
  • 1
    I get this error when using this code; Error while checking syntax automatically: (void-function org-lint-link-to-local-file). I had to change that line to (org-lint '(link-to-local-file)) and it works. Thanks – map7 Jan 13 '17 at 03:07