Function: org-export-resolve-fuzzy-link

org-export-resolve-fuzzy-link is a byte-compiled function defined in ox.el.gz.

Signature

(org-export-resolve-fuzzy-link LINK INFO &rest PSEUDO-TYPES)

Documentation

Return LINK destination.

INFO is a plist holding contextual information.

Return value can be an object or an element:

- If LINK path matches a target object (i.e. <<path>>) return it.

- If LINK path exactly matches the name or results affiliated keyword
  (i.e. #+NAME: path or #+RESULTS: name) of an element, return that
  element.

- If LINK path exactly matches any headline name, return that
  element.

- Otherwise, throw an error.

PSEUDO-TYPES are pseudo-elements types, i.e., elements defined specifically in an export backend, that could have a name affiliated keyword.

Assume LINK type is "fuzzy". White spaces are not significant.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export-resolve-fuzzy-link (link info &rest pseudo-types)
  "Return LINK destination.

INFO is a plist holding contextual information.

Return value can be an object or an element:

- If LINK path matches a target object (i.e. <<path>>) return it.

- If LINK path exactly matches the name or results affiliated keyword
  (i.e. #+NAME: path or #+RESULTS: name) of an element, return that
  element.

- If LINK path exactly matches any headline name, return that
  element.

- Otherwise, throw an error.

PSEUDO-TYPES are pseudo-elements types, i.e., elements defined
specifically in an export backend, that could have a name
affiliated keyword.

Assume LINK type is \"fuzzy\".  White spaces are not
significant."
  (let* ((search-cells (org-export-string-to-search-cell
			(org-element-property :path link)))
	 (link-cache (or (plist-get info :resolve-fuzzy-link-cache)
			 (let ((table (make-hash-table :test #'equal)))
                           ;; Cache all the element search cells.
                           (org-element-map (plist-get info :parse-tree)
                               (append pseudo-types '(target) org-element-all-elements)
                             (lambda (datum)
                               (dolist (cell (org-export-search-cells datum))
                                 (if (gethash cell table)
                                     (push datum (gethash cell table))
                                   (puthash cell (list datum) table)))))
			   (plist-put info :resolve-fuzzy-link-cache table)
			   table)))
	 (cached (gethash search-cells link-cache 'not-found)))
    (if (not (eq cached 'not-found)) cached
      (let ((matches
             (let (result)
               (dolist (search-cell search-cells)
                 (setq result
                       (nconc
                        result
                        (gethash search-cell link-cache))))
               (delq nil result))))
	(unless matches
	  (signal 'org-link-broken (list (org-element-property :path link))))
	(puthash
	 search-cells
	 ;; There can be multiple matches for un-typed searches, i.e.,
	 ;; for searches not starting with # or *.  In this case,
	 ;; prioritize targets and names over headline titles.
	 ;; Matching both a name and a target is not valid, and
	 ;; therefore undefined.
	 (or (cl-some (lambda (datum)
			(and (not (org-element-type-p datum 'headline))
			     datum))
		      matches)
	     (car matches))
	 link-cache)))))