Add a Flycheck rule for Org (using org-lint)
This commit is contained in:
parent
d84560702d
commit
4e02b8e3be
70
config.org
70
config.org
|
@ -6794,6 +6794,76 @@ cause issues. Let's make their failure less eventful.
|
|||
:around #'org-superstar-mode
|
||||
(ignore-errors (apply orig-fn args)))
|
||||
#+end_src
|
||||
**** Flycheck with org-lint
|
||||
|
||||
Flycheck doesn't currently support Org, and there's aren't any packages to do so
|
||||
☹. However, in an issue on ~org-lint~ there is [[https://github.com/flycheck/flycheck/issues/1757#issuecomment-759546940][some code]] which apparently works.
|
||||
Surely this is what the clipboard was invented for? With that said, let's
|
||||
regurgitate the code, cross our fingers, and hope it works.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defconst flycheck-org-lint-form
|
||||
(flycheck-prepare-emacs-lisp-form
|
||||
(require 'org)
|
||||
(require 'org-attach)
|
||||
(let ((source (car command-line-args-left))
|
||||
(process-default-directory default-directory))
|
||||
(with-temp-buffer
|
||||
(insert-file-contents source 'visit)
|
||||
(setq buffer-file-name source)
|
||||
(setq default-directory process-default-directory)
|
||||
(delay-mode-hooks (org-mode))
|
||||
(setq delayed-mode-hooks nil)
|
||||
(dolist (err (org-lint))
|
||||
(let ((inf (cl-second err)))
|
||||
(princ (elt inf 0))
|
||||
(princ ": ")
|
||||
(princ (elt inf 2))
|
||||
(terpri)))))))
|
||||
|
||||
(defconst flycheck-org-lint-variables
|
||||
'(org-directory
|
||||
org-id-locations
|
||||
org-id-locations-file
|
||||
org-attach-id-dir
|
||||
org-attach-use-inheritance
|
||||
org-attach-id-to-path-function-list)
|
||||
"Variables inherited by the org-lint subprocess.")
|
||||
|
||||
(defun flycheck-org-lint-variables-form ()
|
||||
(require 'org-attach) ; Needed to make variables available
|
||||
`(progn
|
||||
,@(seq-map (lambda (opt) `(setq-default ,opt ',(symbol-value opt)))
|
||||
(seq-filter #'boundp flycheck-org-lint-variables))))
|
||||
|
||||
(flycheck-define-checker org-lint
|
||||
"Org buffer checker using `org-lint'."
|
||||
:command ("emacs" (eval flycheck-emacs-args)
|
||||
"--eval" (eval (concat "(add-to-list 'load-path \""
|
||||
(file-name-directory (locate-library "org"))
|
||||
"\")"))
|
||||
"--eval" (eval (flycheck-sexp-to-string
|
||||
(flycheck-org-lint-variables-form)))
|
||||
"--eval" (eval flycheck-org-lint-form)
|
||||
"--" source)
|
||||
:error-patterns
|
||||
((error line-start line ": " (message) line-end))
|
||||
:modes org-mode)
|
||||
#+end_src
|
||||
|
||||
Turns out it almost works. Running =M-x flycheck-verify-setup= after running that
|
||||
snippet produces the following:
|
||||
#+begin_example
|
||||
The following syntax checkers are not registered:
|
||||
- org-lint
|
||||
Try adding these syntax checkers to `flycheck-checkers'.
|
||||
#+end_example
|
||||
|
||||
Well that's very nice and helpful. We'll just do that 🙂.
|
||||
#+begin_src emacs-lisp
|
||||
(add-to-list 'flycheck-checkers 'org-lint)
|
||||
#+end_src
|
||||
|
||||
*** Visuals
|
||||
|
||||
Here I try to do two things: improve the styling of the various documents, via
|
||||
|
|
Loading…
Reference in New Issue