org-lint: don't complain about #+include URL

* lisp/org-lint.el (org-lint-wrong-include-link-parameter): When the
included file is a URL, skip the usual file checks.
This commit is contained in:
TEC 2022-06-05 22:28:39 +08:00
parent e3bf83fe82
commit ae168d5c8c
Signed by: tec
GPG key ID: 779591AFDB81F06C

View file

@ -649,39 +649,40 @@ in description"
(org-element-map ast 'keyword (org-element-map ast 'keyword
(lambda (k) (lambda (k)
(when (equal (org-element-property :key k) "INCLUDE") (when (equal (org-element-property :key k) "INCLUDE")
(let* ((value (org-element-property :value k)) (let* ((value (org-element-property :value k))
(path (path
(and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value) (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value)
(save-match-data (save-match-data
(org-strip-quotes (match-string 1 value)))))) (org-strip-quotes (match-string 1 value))))))
(if (not path) (if (not path)
(list (org-element-property :post-affiliated k) (list (org-element-property :post-affiliated k)
"Missing location argument in INCLUDE keyword") "Missing location argument in INCLUDE keyword")
(let* ((file (org-string-nw-p (let* ((file (org-string-nw-p
(if (string-match "::\\(.*\\)\\'" path) (if (string-match "::\\(.*\\)\\'" path)
(substring path 0 (match-beginning 0)) (substring path 0 (match-beginning 0))
path))) path)))
(search (and (not (equal file path)) (search (and (not (equal file path))
(org-string-nw-p (match-string 1 path))))) (org-string-nw-p (match-string 1 path)))))
(if (and file (unless (org-url-p file)
(not (file-remote-p file)) (if (and file
(not (file-exists-p file))) (not (file-remote-p file))
(list (org-element-property :post-affiliated k) (not (file-exists-p file)))
"Non-existent file argument in INCLUDE keyword") (list (org-element-property :post-affiliated k)
(let* ((visiting (if file (find-buffer-visiting file) "Non-existent file argument in INCLUDE keyword")
(current-buffer))) (let* ((visiting (if file (find-buffer-visiting file)
(buffer (or visiting (find-file-noselect file))) (current-buffer)))
(org-link-search-must-match-exact-headline t)) (buffer (or visiting (find-file-noselect file)))
(unwind-protect (org-link-search-must-match-exact-headline t))
(with-current-buffer buffer (unwind-protect
(when (and search (with-current-buffer buffer
(not (ignore-errors (when (and search
(org-link-search search nil t)))) (not (ignore-errors
(list (org-element-property :post-affiliated k) (org-link-search search nil t))))
(format (list (org-element-property :post-affiliated k)
"Invalid search part \"%s\" in INCLUDE keyword" (format
search)))) "Invalid search part \"%s\" in INCLUDE keyword"
(unless visiting (kill-buffer buffer)))))))))))) search))))
(unless visiting (kill-buffer buffer)))))))))))))
(defun org-lint-obsolete-include-markup (ast) (defun org-lint-obsolete-include-markup (ast)
(let ((regexp (format "\\`\\(?:\".+\"\\|\\S-+\\)[ \t]+%s" (let ((regexp (format "\\`\\(?:\".+\"\\|\\S-+\\)[ \t]+%s"