Backport commit 3236dedc2 from Emacs
* lisp/ox.el (org-export-resolve-fuzzy-link): Before matching LINK,
pre-process and cache all the non-nil search cells in the parse tree.
When matching, use the pre-processed info. Fix the :test function for
the cache hash table.
org-export-resolve-fuzyy-link: Pre-cache all possible search cells
3236dedc2de5975afde877f7460bd012da89a98d
Ihor Radchenko
Thu Jun 16 10:52:36 2022 +0300
[ km: This ported commit comes from main's 792cd4b0a
. I'm applying it
here too for bookkeeping/traceability purposes. ]
This commit is contained in:
parent
303c89350e
commit
07c5d066aa
22
lisp/ox.el
22
lisp/ox.el
|
@ -4348,17 +4348,27 @@ significant."
|
||||||
(let* ((search-cells (org-export-string-to-search-cell
|
(let* ((search-cells (org-export-string-to-search-cell
|
||||||
(org-element-property :path link)))
|
(org-element-property :path link)))
|
||||||
(link-cache (or (plist-get info :resolve-fuzzy-link-cache)
|
(link-cache (or (plist-get info :resolve-fuzzy-link-cache)
|
||||||
(let ((table (make-hash-table :test #'eq)))
|
(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)
|
(plist-put info :resolve-fuzzy-link-cache table)
|
||||||
table)))
|
table)))
|
||||||
(cached (gethash search-cells link-cache 'not-found)))
|
(cached (gethash search-cells link-cache 'not-found)))
|
||||||
(if (not (eq cached 'not-found)) cached
|
(if (not (eq cached 'not-found)) cached
|
||||||
(let ((matches
|
(let ((matches
|
||||||
(org-element-map (plist-get info :parse-tree)
|
(let (result)
|
||||||
(append pseudo-types '(target) org-element-all-elements)
|
(dolist (search-cell search-cells)
|
||||||
(lambda (datum)
|
(setq result
|
||||||
(and (org-export-match-search-cell-p datum search-cells)
|
(nconc
|
||||||
datum)))))
|
result
|
||||||
|
(gethash search-cell link-cache))))
|
||||||
|
(delq nil result))))
|
||||||
(unless matches
|
(unless matches
|
||||||
(signal 'org-link-broken (list (org-element-property :path link))))
|
(signal 'org-link-broken (list (org-element-property :path link))))
|
||||||
(puthash
|
(puthash
|
||||||
|
|
Loading…
Reference in New Issue