emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org: Prevent loss of `re-search-forward' results
@ 2019-08-29 18:03 Max Mouratov
  2019-09-16 16:57 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Max Mouratov @ 2019-08-29 18:03 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello!

I got burned by this issue while implementing a custom link handler.

[-- Attachment #2: 0001-org-Prevent-loss-of-re-search-forward-results.patch --]
[-- Type: application/octet-stream, Size: 1590 bytes --]

From e0a39a6c264a2e9d7e11967da470fa806df1ceb7 Mon Sep 17 00:00:00 2001
From: Max Mouratov <mmouratov@gmail.com>
Date: Thu, 29 Aug 2019 22:48:22 +0500
Subject: [PATCH] org: Prevent loss of `re-search-forward' results

* org.el (org-activate-links): `match-beginning' and `match-end` should
be called shortly after `re-search-forward'. Otherwise, they may return
values corresponding to a different invocation of `re-search-forward'.

TINYCHANGE
---
 lisp/org.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index db957a112..53cc6966f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5151,6 +5151,8 @@ This includes angle, plain, and bracket links."
     (while (re-search-forward org-link-any-re limit t)
       (let* ((start (match-beginning 0))
 	     (end (match-end 0))
+	     (visible-start (or (match-beginning 4) (match-beginning 2)))
+	     (visible-end (or (match-end 4) (match-end 2)))
 	     (style (cond ((eq ?< (char-after start)) 'angle)
 			  ((eq ?\[ (char-after (1+ start))) 'bracket)
 			  (t 'plain))))
@@ -5200,9 +5202,7 @@ This includes angle, plain, and bracket links."
 		     (append `(invisible
 			       ,(or (org-link-get-parameter type :display)
 				    'org-link))
-			     properties))
-		    (visible-start (or (match-beginning 3) (match-beginning 2)))
-		    (visible-end (or (match-end 3) (match-end 2))))
+			     properties)))
 		(add-text-properties start visible-start hidden)
 		(add-text-properties visible-start visible-end properties)
 		(add-text-properties visible-end end hidden)
-- 
2.17.1


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

* Re: [PATCH] org: Prevent loss of `re-search-forward' results
  2019-08-29 18:03 [PATCH] org: Prevent loss of `re-search-forward' results Max Mouratov
@ 2019-09-16 16:57 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2019-09-16 16:57 UTC (permalink / raw)
  To: Max Mouratov; +Cc: emacs-orgmode

Hello,

Max Mouratov <mmouratov@gmail.com> writes:

> * org.el (org-activate-links): `match-beginning' and `match-end` should
> be called shortly after `re-search-forward'. Otherwise, they may return
> values corresponding to a different invocation of `re-search-forward'.

Applied. Thank you!

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2019-09-16 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-29 18:03 [PATCH] org: Prevent loss of `re-search-forward' results Max Mouratov
2019-09-16 16:57 ` Nicolas Goaziou

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).