emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ol: Fix org-link-search
@ 2022-04-20 16:10 tony aldon
  2022-04-21  5:39 ` Ihor Radchenko
  2022-04-21 13:00 ` Ihor Radchenko
  0 siblings, 2 replies; 4+ messages in thread
From: tony aldon @ 2022-04-20 16:10 UTC (permalink / raw)
  To: emacs-orgmode


[-- 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ol: Fix org-link-search
  2022-04-20 16:10 [PATCH] ol: Fix org-link-search tony aldon
@ 2022-04-21  5:39 ` Ihor Radchenko
       [not found]   ` <CACWitSA6eYp68L3u3HFxA-U-EE=s9ZDQxKaHmaFPdL+UxXVEOw@mail.gmail.com>
  2022-04-21 13:00 ` Ihor Radchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2022-04-21  5:39 UTC (permalink / raw)
  To: tony aldon; +Cc: emacs-orgmode

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ol: Fix org-link-search
       [not found]   ` <CACWitSA6eYp68L3u3HFxA-U-EE=s9ZDQxKaHmaFPdL+UxXVEOw@mail.gmail.com>
@ 2022-04-21 10:25     ` tony aldon
  0 siblings, 0 replies; 4+ messages in thread
From: tony aldon @ 2022-04-21 10:25 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ol: Fix org-link-search
  2022-04-20 16:10 [PATCH] ol: Fix org-link-search tony aldon
  2022-04-21  5:39 ` Ihor Radchenko
@ 2022-04-21 13:00 ` Ihor Radchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2022-04-21 13:00 UTC (permalink / raw)
  To: emacs-orgmode

Patch marked as cancelled.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-21 13:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 16:10 [PATCH] ol: Fix org-link-search tony aldon
2022-04-21  5:39 ` Ihor Radchenko
     [not found]   ` <CACWitSA6eYp68L3u3HFxA-U-EE=s9ZDQxKaHmaFPdL+UxXVEOw@mail.gmail.com>
2022-04-21 10:25     ` tony aldon
2022-04-21 13:00 ` Ihor Radchenko

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).