Hey everyone,

If I'm not wrong, name defined after #+NAME: should be match first
before trying a fuzzy search in the function `org-link-search`.

You can find the patch in attachment (hope it feat in Tiny changes
[though I also sent a request today for the FSF agreement]).

Have a nice day.
Tony Aldon
From ba4028e71fb41b6e4367d3e85846526dd7577d52 Mon Sep 17 00:00:00 2001
From: tony <tony.aldon....@gmail.com>
Date: Wed, 20 Apr 2022 17:58:34 +0200
Subject: [PATCH] ol: Fix org-link-search

* lisp/ol.el (org-link-search):  Replace wrong property :name by
  :value.  Name defined after #+NAME: should be match first before
  trying a fuzzy search.
* testing/lisp/test-ol.el (test-ol/search):  New test.

TINYCHANGE
---
 lisp/ol.el              |  2 +-
 testing/lisp/test-ol.el | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 1b2bb9a9a..4554941b6 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1189,7 +1189,7 @@ of matched result, which is either `dedicated' or `fuzzy'."
 	       (goto-char (point-min))
 	       (while (re-search-forward name nil t)
 		 (let* ((element (org-element-at-point))
-			(name (org-element-property :name element)))
+			(name (org-element-property :value element)))
 		   (when (and name (equal words (split-string name)))
 		     (setq type 'dedicated)
 		     (beginning-of-line)
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index ddcc570b3..3e5b9c7cd 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -492,6 +492,18 @@
 	    (buffer-substring (point) (line-end-position))))))
 
 
+;;; Search
+
+(ert-deftest test-ol/search ()
+  "Test `org-link-search'."
+  ;; Look for name defined after #+NAME:
+  (should
+   (equal 'dedicated
+      (org-test-with-temp-text "foo\n#+NAME: foo"
+	(let ((org-link-search-must-match-exact-headline nil))
+          (org-link-search "foo"))))))
+
+
 ;;; Link regexps
 
 
-- 
2.17.1

Reply via email to