[-- Attachment #1.1: Type: text/plain, Size: 304 bytes --] 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 [-- Attachment #1.2: Type: text/html, Size: 357 bytes --] [-- Attachment #2: 0001-ol-Fix-org-link-search.patch --] [-- Type: text/x-patch, Size: 1647 bytes --] From ba4028e71fb41b6e4367d3e85846526dd7577d52 Mon Sep 17 00:00:00 2001 From: tony <tony.aldon.adm@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)))))) \f +;;; 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")))))) + +\f ;;; Link regexps -- 2.17.1
tony aldon <tony.aldon.adm@gmail.com> writes:
> If I'm not wrong, name defined after #+NAME: should be match first
> before trying a fuzzy search in the function `org-link-search`.
> ...
> - (name (org-element-property :name element)))
> + (name (org-element-property :value element)))
I think you are missing something.
A standaline
#+name: some name
is a keyword, not an element name, but a generic keyword element.
Named elements are the elements with affiliated keywords (not ordinary
keywords):
#+name: some other name
Some element that can have affiliated keywords. It may be a paragraph,
like here or e.g. source block. Link search should not try to search
standalone keywords and hence it is sufficient to check for :name
element property. :value will miss e.g. named source blocks.
Try running (org-element-at-point) on the first and second #+name in org
buffer.
Best,
Ihor
[-- Attachment #1: Type: text/plain, Size: 1352 bytes --] On Thu, Apr 21, 2022 at 12:23 PM tony aldon <tony.aldon.adm@gmail.com> wrote: > You're right I was effectively missing affiliated keywords and so my > patch is wrong. > > Thank you for your quick feedback and insight. > > Have a nice day, > Tony Aldon > > On Thu, Apr 21, 2022 at 7:39 AM Ihor Radchenko <yantar92@gmail.com> wrote: > >> tony aldon <tony.aldon.adm@gmail.com> writes: >> >> > If I'm not wrong, name defined after #+NAME: should be match first >> > before trying a fuzzy search in the function `org-link-search`. >> > ... >> > - (name (org-element-property :name element))) >> > + (name (org-element-property :value element))) >> >> I think you are missing something. >> >> A standaline >> >> #+name: some name >> >> is a keyword, not an element name, but a generic keyword element. >> >> Named elements are the elements with affiliated keywords (not ordinary >> keywords): >> >> #+name: some other name >> Some element that can have affiliated keywords. It may be a paragraph, >> like here or e.g. source block. Link search should not try to search >> standalone keywords and hence it is sufficient to check for :name >> element property. :value will miss e.g. named source blocks. >> >> Try running (org-element-at-point) on the first and second #+name in org >> buffer. >> >> Best, >> Ihor >> > [-- Attachment #2: Type: text/html, Size: 2119 bytes --]
Patch marked as cancelled.