Function: org-lint-wrong-include-link-parameter

org-lint-wrong-include-link-parameter is a byte-compiled function defined in org-lint.el.gz.

Signature

(org-lint-wrong-include-link-parameter AST)

Source Code

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