emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Rudolf Adamkovič" <salutis@me.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Fix shadowed radio targets
Date: Mon, 06 Jun 2022 21:44:59 +0200	[thread overview]
Message-ID: <m2pmjl37b8.fsf@me.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

Hello everyone!

If one defines two radio targets, say <<<peptide bond>>> and
<<<peptide>>>, the first one does not work if defined first.  Please,
see the attached patch.  I have the copyright papers signed.

Rudy


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ol.el-Fix-shadowed-radio-targets.patch --]
[-- Type: text/x-patch, Size: 1869 bytes --]

From f0077a592fbf4ddfde02f5899dc428db4f7ecbf2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com>
Date: Sat, 23 Apr 2022 11:39:33 +0200
Subject: [PATCH] lisp/ol.el: Fix shadowed radio targets

* lisp/ol.el (org-update-radio-target-regexp): Sort radio targets
before building the regexp that matches them.
* testing/lisp/test-org.el: Test shadowed radio targets.  The bug
occurs when two targets share the same prefix and when and the longer
target appears first.
---
 lisp/ol.el               |  3 +++
 testing/lisp/test-org.el | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lisp/ol.el b/lisp/ol.el
index d4bd0e40c..189e31b1e 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -2040,6 +2040,9 @@ Also refresh fontification if needed."
 		  (cl-pushnew (org-element-property :value obj) rtn
 			      :test #'equal))))
 	    rtn))))
+    (sort targets
+        (lambda (a b)
+          (> (length a) (length b))))
     (setq org-target-link-regexp
 	  (and targets
 	       (concat before-re
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 5f13e89a4..121f9efd5 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2915,6 +2915,18 @@ Foo Bar
      (org-open-at-point)
      (eq (org-element-type (org-element-context)) 'radio-target))))
 
+(ert-deftest test-org/open-at-point/radio-target-shadowed ()
+  "Test `org-open-at-point' on shadowed radio targets."
+  (should
+   (org-test-with-temp-text
+       "<<<target shadowed>>> <<<target>>> <point>target shadowed"
+     (org-update-radio-target-regexp)
+     (org-open-at-point)
+     (string=
+      (org-element-property :value
+                            (org-element-radio-target-parser))
+      "target shadowed"))))
+
 (ert-deftest test-org/open-at-point/tag ()
   "Test `org-open-at-point' on tags."
   (should
-- 
2.36.1


[-- Attachment #3: Type: text/plain, Size: 246 bytes --]

-- 
"One can begin to reason only when a clear picture has been formed in
the imagination."
-- Walter Warwick Sawyer, Mathematician's Delight, 1943

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

             reply	other threads:[~2022-06-06 19:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06 19:44 Rudolf Adamkovič [this message]
2022-06-09  8:25 ` [PATCH] Fix shadowed radio targets Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2pmjl37b8.fsf@me.com \
    --to=salutis@me.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).