org-lint-invalid-id-link: Improve performance

* lisp/org-lint.el (org-lint-invalid-id-link): Do not try to search
for exact position of every ID.  Instead, sync all the ID locations
once and then make use of the up-to-date locations state to query if
an ID is present.
This commit is contained in:
Ihor Radchenko 2023-08-17 12:49:59 +03:00
parent 4cf0b0433d
commit 2cf245810b
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 6 additions and 1 deletions

View File

@ -584,11 +584,16 @@ 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")
(not (org-id-find 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)))))))