Is there a function that will validate internal fuzzy links in org-mode
? I would like to see which links resolve to headers (fontified in blue) and which ones are broke (fontified in red).
John Kitchin had a good solution for external links:
(org-link-set-parameters
"file"
:face (lambda (path) (if (file-exists-p path) 'org-link 'org-warning)))
and I found this code, as part of org-lint
:
(defun org-lint-invalid-fuzzy-link (ast)
(let ((info (list :parse-tree ast)))
(org-element-map ast 'link
(lambda (link)
(and (equal (org-element-property :type link) "fuzzy")
(not (ignore-errors (org-export-resolve-fuzzy-link link info)))
(list (org-element-property :begin link)
(format "Unknown fuzzy location \"%s\""
(let ((path (org-element-property :path link)))
(if (string-prefix-p "*" path)
(substring path 1)
path)))))))))
Is there is a way to marry these together?
org-set-link-parameters
not the right path.org-link-set-parameters
is for named link types. Fuzzy links don't belong to that class.org-open-at-point
usesorg-element-type
to identify fuzzy links andorg-link-search
with(org-link-unescape (org-element-property :path context))
as search string andAVOID-POS = (+ 2 (org-element-property :begin context))
to determine the destination.org-lint-invalid-fuzzy-link
would needorg-element-parse-buffer
to calculate the argumentast
("ast" == "abstract syntax tree" of the org buffer). That function is not appropriate for just-in-time font locking because it is too heavy.org-link-search
would also be too slow for jit. One needs to cache the search results somehow and to keep the cache up-to-date when the destination is edited. That task is not so easy. Note that I did not ignore your question after you asked it. But that task is not as easy as it may appear at first sight of the question.org-link-search
be too slow if it is only triggered when a link (or header) is created or updated?