emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Patch to fix `org-test-with-temp-text'
@ 2014-04-09 22:39 York Zhao
  2014-04-10  9:57 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: York Zhao @ 2014-04-09 22:39 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi list,

I've just found a bug in `org-test-with-temp-text' and have fixed it. Please
find attached my patch for the fix. Here's the description from git commit
message:

According to the docstring, if the string "<point>" appears in TEXT then the
string "<point>" is removed and point is placed there. The problem was that
after string "<point>" was removed, the point was *not* placed at the position
of the removed text, rather, it was placed one character before that position
which is wrong. The reason is that Emacs buffer position is a number started
from 1, instead of 0, in other words, the value of `(point-min)' is 1 not 0. The
problem is addressed by adding 1 to the calculated position.

I'm going to report another bug together with a reproducer written as an
"org-test". But my test relies on my fix in `org-test-with-temp-text'. Therefor,
I will appreciate it if this patch can be taken care of as soon as possible.

Thank you,

York

[-- Attachment #2: 0001-testing-org-test.el-org-test-with-temp-text-Fix-poin.patch --]
[-- Type: text/x-diff, Size: 1676 bytes --]

From 9bbfc37ab059e923c57eaa99e3a2d81144c80218 Mon Sep 17 00:00:00 2001
From: York Zhao <gtdplatform@gmail.com>
Date: Wed, 9 Apr 2014 13:39:16 -0400
Subject: [PATCH] testing/org-test.el (org-test-with-temp-text): Fix point
 position

According to the docstring, if the string "<point>" appears in TEXT
then the string "<point>" is removed and point is placed there. The
problem was that after string "<point>" was removed, the point
was *not* placed at the position of the removed text, rather, it was
placed one character before that position which is wrong. The reason
is that Emacs buffer position is a number started from 1, instead of
0, in other words, the value of `(point-min)' is 1 not 0. The problem
is addressed by adding 1 to the calculated position.

TINYCHANGE
---
 testing/org-test.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/testing/org-test.el b/testing/org-test.el
index 879d45e..983c012 100644
--- a/testing/org-test.el
+++ b/testing/org-test.el
@@ -209,11 +209,12 @@ otherwise place the point at the beginning of the inserted text."
      (with-temp-buffer
        (org-mode)
        (let ((point (string-match (regexp-quote "<point>") inside-text)))
-	  (if point
-	      (progn (insert (replace-match "" nil nil inside-text))
-		     (goto-char (match-beginning 0)))
-	    (progn (insert inside-text)
-		   (goto-char (point-min)))))
+	 (if point
+	     (progn
+	       (insert (replace-match "" nil nil inside-text))
+	       (goto-char (1+ (match-beginning 0))))
+	   (progn (insert inside-text)
+		  (goto-char (point-min)))))
        ,@body)))
 (def-edebug-spec org-test-with-temp-text (form body))
 
-- 
1.8.4


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

* Re: Patch to fix `org-test-with-temp-text'
  2014-04-09 22:39 Patch to fix `org-test-with-temp-text' York Zhao
@ 2014-04-10  9:57 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2014-04-10  9:57 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

Hello,

York Zhao <gtdplatform@gmail.com> writes:

> I've just found a bug in `org-test-with-temp-text' and have fixed it. Please
> find attached my patch for the fix. Here's the description from git commit
> message:

Applied. Thank you.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2014-04-10  9:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09 22:39 Patch to fix `org-test-with-temp-text' York Zhao
2014-04-10  9: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).