From 07ae5456b1736451c803d9f5fb9f2389a49f7767 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 25 Jun 2020 20:58:35 +0200 Subject: [PATCH] lint: Checking local files in links also include attachments * lisp/org-lint.el (org-lint-link-to-local-file): Also check attachment. --- lisp/org-lint.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index 5c5e642ac..520004817 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -567,16 +567,22 @@ Use :header-args: instead" (defun org-lint-link-to-local-file (ast) (org-element-map ast 'link (lambda (l) - (when (equal "file" (org-element-property :type l)) - (let ((file (org-element-property :path l))) - (and (not (file-remote-p file)) - (not (file-exists-p file)) - (list (org-element-property :begin l) - (format (if (org-element-lineage l '(link)) - "Link to non-existent image file \"%s\"\ - in link description" - "Link to non-existent local file \"%s\"") - file)))))))) + (let ((type (org-element-property :type l))) + (pcase type + ((or "attachment" "file") + (let* ((path (org-element-property :path l)) + (file (if (string= type "file") + path + (org-attach-expand path)))) + (and (not (file-remote-p file)) + (not (file-exists-p file)) + (list (org-element-property :begin l) + (format (if (org-element-lineage l '(link)) + "Link to non-existent image file %S \ +in description" + "Link to non-existent local file %S" + file)))))) + (_ nil)))))) (defun org-lint-non-existent-setupfile-parameter (ast) (org-element-map ast 'keyword