(fix): fix org-roam-doctor broken-link checker (#624)

The checker originally returns reports of wrong format when there are no
errors
This commit is contained in:
Jethro Kuan
2020-05-14 13:51:35 +08:00
committed by GitHub
parent 80bc19cbda
commit e55a38530d

View File

@ -71,18 +71,22 @@
(defun org-roam-doctor-broken-links (ast) (defun org-roam-doctor-broken-links (ast)
"Checker for detecting broken links. "Checker for detecting broken links.
AST is the org-element parse tree." AST is the org-element parse tree."
(org-element-map ast 'link (let (reports)
(lambda (l) (org-element-map ast 'link
(when (equal "file" (org-element-property :type l)) (lambda (l)
(let ((file (org-element-property :path l))) (when (equal "file" (org-element-property :type l))
(or (file-exists-p file) (let ((file (org-element-property :path l)))
(file-remote-p file) (or (file-exists-p file)
`(,(org-element-property :begin l) (file-remote-p file)
,(format (if (org-element-lineage l '(link)) (push
"Link to non-existent image file \"%s\"\ `(,(org-element-property :begin l)
,(format (if (org-element-lineage l '(link))
"Link to non-existent image file \"%s\"\
in link description" in link description"
"Link to non-existent local file \"%s\"") "Link to non-existent local file \"%s\"")
file)))))))) file))
reports))))))
reports))
(defun org-roam-doctor--check (buffer checkers) (defun org-roam-doctor--check (buffer checkers)
"Check BUFFER for errors. "Check BUFFER for errors.
@ -216,8 +220,7 @@ If CHECKALL, run the check only for all Org-roam files."
(let ((existing-buffers (org-roam--get-roam-buffers))) (let ((existing-buffers (org-roam--get-roam-buffers)))
(dolist (f files) (dolist (f files)
(let ((buf (find-file-noselect f))) (let ((buf (find-file-noselect f)))
(with-current-buffer buf (org-roam-doctor--check buf checkers)
(org-roam-doctor--check buf checkers))
(unless (memq buf existing-buffers) (unless (memq buf existing-buffers)
(save-buffer buf) (save-buffer buf)
(kill-buffer buf)))))) (kill-buffer buf))))))