summaryrefslogtreecommitdiff
path: root/lisp/org
diff options
context:
space:
mode:
authorIhor Radchenko <yantar92@gmail.com>2022-06-12 13:06:47 +0800
committerEli Zaretskii <eliz@gnu.org>2022-06-16 10:52:36 +0300
commit3236dedc2de5975afde877f7460bd012da89a98d (patch)
treef7a6461c73e823d202aa7597c918e1e508bf1905 /lisp/org
parent5b3d4e7bf0b6a1eb576e1c6e6592028e3589f792 (diff)
downloademacs-3236dedc2de5975afde877f7460bd012da89a98d.tar.gz
emacs-3236dedc2de5975afde877f7460bd012da89a98d.tar.bz2
emacs-3236dedc2de5975afde877f7460bd012da89a98d.zip
org-export-resolve-fuzyy-link: Pre-cache all possible search cells
* lisp/org/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.
Diffstat (limited to 'lisp/org')
-rw-r--r--lisp/org/ox.el22
1 files changed, 16 insertions, 6 deletions
diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index 7f90dc36f71..4a9387519f5 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -4346,17 +4346,27 @@ 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 #'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)
table)))
(cached (gethash search-cells link-cache 'not-found)))
(if (not (eq cached 'not-found)) cached
(let ((matches
- (org-element-map (plist-get info :parse-tree)
- (append pseudo-types '(target) org-element-all-elements)
- (lambda (datum)
- (and (org-export-match-search-cell-p datum search-cells)
- datum)))))
+ (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