org-lint-invalid-id-link: Only update ID locations if there are ID links

* lisp/org-lint.el (org-lint-invalid-id-link): Avoid running
`org-id-update-id-locations' when there are no ID links in the linted
file.
This commit is contained in:
Ihor Radchenko 2023-08-18 15:18:50 +03:00
parent 83fd03fb6d
commit d560a2d739
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 17 additions and 12 deletions

View File

@ -585,18 +585,23 @@ Use :header-args: instead"
path)))))))))
(defun org-lint-invalid-id-link (ast)
(org-id-update-id-locations nil t)
(org-element-map ast 'link
(lambda (link)
(let ((id (org-element-property :path link)))
(and (equal (org-element-property :type link) "id")
;; The locations are up-to-date with file changes after
;; the call to `org-id-update-id-locations'. We do not
;; need to double-check if recorded ID is still present
;; in the file.
(not (org-id-find-id-file id))
(list (org-element-begin link)
(format "Unknown ID \"%s\"" id)))))))
(let ((id-locations-updated nil))
(org-element-map ast 'link
(lambda (link)
(let ((id (org-element-property :path link)))
(and (equal (org-element-property :type link) "id")
(progn
(unless id-locations-updated
(org-id-update-id-locations nil t)
(setq id-locations-updated t))
t)
;; The locations are up-to-date with file changes after
;; the call to `org-id-update-id-locations'. We do not
;; need to double-check if recorded ID is still present
;; in the file.
(not (org-id-find-id-file id))
(list (org-element-begin link)
(format "Unknown ID \"%s\"" id))))))))
(defun org-lint-confusing-brackets (ast)
(org-element-map ast 'link