7

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?

  • 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 6 '17 at 17:05
3

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)
  • 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 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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