emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-core: Fix indented cached result returning nil
@ 2015-05-20 15:22 Bjarte Johansen
  2015-05-20 22:19 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-20 15:22 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bjarte Johansen

Fix a problem where a source block would return nil if the result was
cached and it was indented.

* lisp/ob-core.el (org-babel-execute-src-block): Move point to the the
  first character of the result instead of the beginning of the line.

* testing/lisp/test-ob.el
  (test-org-babel/indented-cached-org-bracket-link): Added test to
  to see if the indented cached result returns what it should return.
---
 lisp/ob-core.el         |  2 +-
 testing/lisp/test-ob.el | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 91bbde4..e7e029d 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -652,7 +652,7 @@ block."
 	 (cache-current-p
 	  (save-excursion ;; return cached result
 	    (goto-char (org-babel-where-is-src-block-result nil info))
-	    (end-of-line 1) (forward-char 1)
+	    (end-of-line 1) (forward-char (1+ (current-indentation)))
 	    (let ((result (org-babel-read-result)))
 	      (message (replace-regexp-in-string
 			"%" "%%" (format "%S" result))) result)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index f52ff24..ae61b0c 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -20,6 +20,23 @@

 ;;; Code:

+(ert-deftest test-org-babel/indented-cached-org-bracket-link ()
+  "When the result of a source block is indentend, a link and
+cached it should still return the link."
+  (let ((test-block (concat "* Test\n"
+			    "  #+BEGIN_SRC sh :file test.txt :cache yes\n"
+			    "    echo 'text'\n"
+			    "  #+END_SRC\n"
+			    "\n"
+			    "  #+RESULTS[be4fa2f5922220a6bc5b6c1f2a6747a067404506]:\n"
+			    "  [[file:test.txt]]")))
+    (with-temp-buffer
+      (insert test-block)
+      (search-backward "BEGIN_SRC")
+      (org-mode)
+      (should (string= (concat default-directory "test.txt")
+		       (org-babel-execute-src-block))))))
+
 (ert-deftest test-org-babel/multi-line-header-regexp ()
   (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
 		org-babel-multi-line-header-regexp))
--
2.3.2 (Apple Git-55)

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-20 15:22 Bjarte Johansen
@ 2015-05-20 22:19 ` Nicolas Goaziou
  2015-05-21 10:34   ` Bjarte Johansen
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2015-05-20 22:19 UTC (permalink / raw)
  To: Bjarte Johansen; +Cc: emacs-orgmode

Hello,

Bjarte Johansen <bjarte.johansen@gmail.com> writes:

> Fix a problem where a source block would return nil if the result was
> cached and it was indented.

Thank you. Some comments follow.

> * lisp/ob-core.el (org-babel-execute-src-block): Move point to the the
>   first character of the result instead of the beginning of the line.
>
> * testing/lisp/test-ob.el
>   (test-org-babel/indented-cached-org-bracket-link): Added test to
>   to see if the indented cached result returns what it should return.

You need to add TINYCHANGE at the end of the commit message if you
haven't signed FSF papers yet.

> -	    (end-of-line 1) (forward-char 1)
> +	    (end-of-line 1) (forward-char (1+ (current-indentation)))

Slightly better: 

  (forward-line)
  (forward-char (current-indentation))
  
> +(ert-deftest test-org-babel/indented-cached-org-bracket-link ()
> +  "When the result of a source block is indentend, a link and
                                           ^^^^^^^^
"a cached indented link"

> +cached it should still return the link."
> +  (let ((test-block (concat "* Test\n"
> +			    "  #+BEGIN_SRC sh :file test.txt :cache yes\n"
> +			    "    echo 'text'\n"
> +			    "  #+END_SRC\n"
> +			    "\n"
> +			    "  #+RESULTS[be4fa2f5922220a6bc5b6c1f2a6747a067404506]:\n"
> +			    "  [[file:test.txt]]")))
> +    (with-temp-buffer
> +      (insert test-block)
> +      (search-backward "BEGIN_SRC")
> +      (org-mode)
> +      (should (string= (concat default-directory "test.txt")
> +		       (org-babel-execute-src-block))))))

You should use `org-test-with-temp-text' instead, and avoid "sh" as it
might not be active.  OTOH, emacs-lisp is always available:

--8<---------------cut here---------------start------------->8---
(should
 (org-test-with-temp-text
     "* Test
  #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
    (message \"text\")
  #+END_SRC

  #+RESULTS[c9828cf13461ca9ccb31e76ba4aee02ec6d7a4e7]:
  [[file:test.txt]]"
   (string= (concat default-directory "test.txt")
            (org-babel-execute-src-block))))
--8<---------------cut here---------------end--------------->8---


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-20 22:19 ` Nicolas Goaziou
@ 2015-05-21 10:34   ` Bjarte Johansen
  0 siblings, 0 replies; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-21 10:34 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Thank you for your comments. 

> You need to add TINYCHANGE at the end of the commit message if you
> haven't signed FSF papers yet.
I have already signed the FSF papers when I sent some changes to a 
different Emacs project.

I will shortly send a new patch with the proposed changes.

Regards,
Bjarte

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

* [PATCH] ob-core: Fix indented cached result returning nil
@ 2015-05-21 10:38 Bjarte Johansen
  2015-05-23 19:50 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-21 10:38 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bjarte Johansen

Fix a problem where a source block would return nil oif the result was
cached and it was indented.

* lisp/ob-core.el (org-babel-execute-src-block): Move point to the the
  first character of the result instead of the beginning of the line.

* testing/lisp/test-ob.el
  (test-org-babel/indented-cached-org-bracket-link): Added test to
  to see if the indented cached result returns what it should return.
---
 lisp/ob-core.el         |  3 ++-
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 91bbde4..1f21685 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -652,7 +652,8 @@ block."
 	 (cache-current-p
 	  (save-excursion ;; return cached result
 	    (goto-char (org-babel-where-is-src-block-result nil info))
-	    (end-of-line 1) (forward-char 1)
+	    (end-of-line 1)
+	    (forward-char (1+ (current-indentation)))
 	    (let ((result (org-babel-read-result)))
 	      (message (replace-regexp-in-string
 			"%" "%%" (format "%S" result))) result)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index f52ff24..55b45ad 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -20,6 +20,22 @@
 
 ;;; Code:
 
+(ert-deftest test-org-babel/indented-cached-org-bracket-link ()
+  "When the result of a source block is a cached indented link it
+should still return the link."
+  (should
+   (org-test-with-temp-text
+    "
+* Test
+  #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
+    (message \"test\")
+  #+END_SRC
+
+  #+RESULTS[f82e11feb0f46907bc5a256a27e9dd81a3876d14]:
+  [[file:test.txt]]"
+    (string= (concat default-directory "test.txt")
+	     (org-babel-execute-src-block)))))
+
 (ert-deftest test-org-babel/multi-line-header-regexp ()
   (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
 		org-babel-multi-line-header-regexp))
-- 
2.3.2 (Apple Git-55)

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-21 10:38 [PATCH] ob-core: Fix indented cached result returning nil Bjarte Johansen
@ 2015-05-23 19:50 ` Nicolas Goaziou
  2015-05-24  9:49   ` Bjarte Johansen
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2015-05-23 19:50 UTC (permalink / raw)
  To: Bjarte Johansen; +Cc: emacs-orgmode

Bjarte Johansen <bjarte.johansen@gmail.com> writes:

> Fix a problem where a source block would return nil oif the result was
> cached and it was indented.

Thank you. 

However, the test you provide fails. I suggest to create "test.txt" in
`temporary-file-directory' instead of `default-directory'.

Regards,

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-23 19:50 ` Nicolas Goaziou
@ 2015-05-24  9:49   ` Bjarte Johansen
  2015-05-24  9:53     ` Bjarte Johansen
  0 siblings, 1 reply; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-24  9:49 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


> On 23 May 2015, at 21:50, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> 
> Bjarte Johansen <bjarte.johansen@gmail.com> writes:
> 
>> Fix a problem where a source block would return nil oif the result was
>> cached and it was indented.
> 
> Thank you. 
> 
> However, the test you provide fails. I suggest to create "test.txt" in
> `temporary-file-directory' instead of `default-directory'.
> 
> Regards,


Ah, it was not supposed to actually run the code in the source block; only get the cached result. I might know an easier test of it. I’ll send a revised version later.

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-24  9:49   ` Bjarte Johansen
@ 2015-05-24  9:53     ` Bjarte Johansen
  2015-05-24 11:41       ` Bjarte Johansen
  0 siblings, 1 reply; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-24  9:53 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


> On 24 May 2015, at 11:49, Bjarte Johansen <bjarte.johansen@gmail.com> wrote:
> 
> 
>> On 23 May 2015, at 21:50, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>> 
>> Bjarte Johansen <bjarte.johansen@gmail.com> writes:
>> 
>>> Fix a problem where a source block would return nil oif the result was
>>> cached and it was indented.
>> 
>> Thank you. 
>> 
>> However, the test you provide fails. I suggest to create "test.txt" in
>> `temporary-file-directory' instead of `default-directory'.
>> 
>> Regards,
> 
> 
> Ah, it was not supposed to actually run the code in the source block; only get the cached result. I might know an easier test of it. I’ll send a revised version later.

Actually, I saw now that it should be (message “test.txt”), notice the added extension. The hash is also therefore most likely wrong. I will fix it.

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-24  9:53     ` Bjarte Johansen
@ 2015-05-24 11:41       ` Bjarte Johansen
  0 siblings, 0 replies; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-24 11:41 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


> On 24 May 2015, at 11:53, Bjarte Johansen <bjarte.johansen@gmail.com> wrote:
> 
> 
>> On 24 May 2015, at 11:49, Bjarte Johansen <bjarte.johansen@gmail.com> wrote:
>> 
>> 
>>> On 23 May 2015, at 21:50, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>>> 
>>> Bjarte Johansen <bjarte.johansen@gmail.com> writes:
>>> 
>>>> Fix a problem where a source block would return nil oif the result was
>>>> cached and it was indented.
>>> 
>>> Thank you. 
>>> 
>>> However, the test you provide fails. I suggest to create "test.txt" in
>>> `temporary-file-directory' instead of `default-directory'.
>>> 
>>> Regards,
>> 
>> 
>> Ah, it was not supposed to actually run the code in the source block; only get the cached result. I might know an easier test of it. I’ll send a revised version later.
> 
> Actually, I saw now that it should be (message “test.txt”), notice the added extension. The hash is also therefore most likely wrong. I will fix it.

No, this was wrong. I have a more robust fix and do as you suggest. Create the file in temporary-file-directory and run the execution of the source block twice to get the cache. This way, if org-mode changes its hashing function later, the test will still work. Sending the patch shortly.

Regards,
Bjarte

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

* [PATCH] ob-core: Fix indented cached result returning nil
@ 2015-05-24 11:42 Bjarte Johansen
  2015-05-26  8:20 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bjarte Johansen @ 2015-05-24 11:42 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bjarte Johansen

Fix a problem where a source block would return nil oif the result was
cached and it was indented.

* lisp/ob-core.el (org-babel-execute-src-block): Move point to the the
 first character of the result instead of the beginning of the line.

* testing/lisp/test-ob.el
 (test-org-babel/indented-cached-org-bracket-link): Added test to
 to see if the indented cached result returns what it should return.
---
 lisp/ob-core.el         |  3 ++-
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index d25bb7c..9575096 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -653,7 +653,8 @@ block."
 	 (cache-current-p
 	  (save-excursion ;; return cached result
 	    (goto-char (org-babel-where-is-src-block-result nil info))
-	    (end-of-line 1) (forward-char 1)
+	    (end-of-line 1)
+	    (forward-char (1+ (current-indentation)))
 	    (let ((result (org-babel-read-result)))
 	      (message (replace-regexp-in-string
 			"%" "%%" (format "%S" result))) result)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index f52ff24..83b4d00 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -20,6 +20,22 @@
 
 ;;; Code:
 
+(ert-deftest test-org-babel/indented-cached-org-bracket-link ()
+  "When the result of a source block is a cached indented link it
+should still return the link."
+  (should
+   (let ((default-directory temporary-file-directory))
+     (org-test-with-temp-text
+      "
+* Test
+  #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
+    (message \"test\")
+  #+END_SRC"
+      ;; Execute twice as the first time creates the cache.
+      (org-babel-execute-src-block)
+      (string= (concat default-directory "test.txt")
+	       (org-babel-execute-src-block))))))
+
 (ert-deftest test-org-babel/multi-line-header-regexp ()
   (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
 		org-babel-multi-line-header-regexp))
-- 
2.3.2 (Apple Git-55)

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

* Re: [PATCH] ob-core: Fix indented cached result returning nil
  2015-05-24 11:42 Bjarte Johansen
@ 2015-05-26  8:20 ` Nicolas Goaziou
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2015-05-26  8:20 UTC (permalink / raw)
  To: Bjarte Johansen; +Cc: emacs-orgmode

Bjarte Johansen <bjarte.johansen@gmail.com> writes:

> Fix a problem where a source block would return nil oif the result was
> cached and it was indented.
>
> * lisp/ob-core.el (org-babel-execute-src-block): Move point to the the
>  first character of the result instead of the beginning of the line.
>
> * testing/lisp/test-ob.el
>  (test-org-babel/indented-cached-org-bracket-link): Added test to
>  to see if the indented cached result returns what it should return.

Applied. Thank you.

Regards,

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

end of thread, other threads:[~2015-05-26  8:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-21 10:38 [PATCH] ob-core: Fix indented cached result returning nil Bjarte Johansen
2015-05-23 19:50 ` Nicolas Goaziou
2015-05-24  9:49   ` Bjarte Johansen
2015-05-24  9:53     ` Bjarte Johansen
2015-05-24 11:41       ` Bjarte Johansen
  -- strict thread matches above, loose matches on Subject: below --
2015-05-24 11:42 Bjarte Johansen
2015-05-26  8:20 ` Nicolas Goaziou
2015-05-20 15:22 Bjarte Johansen
2015-05-20 22:19 ` Nicolas Goaziou
2015-05-21 10:34   ` Bjarte Johansen

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