emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bjarte Johansen <bjarte.johansen@gmail.com>
To: emacs-orgmode@gnu.org
Cc: Bjarte Johansen <bjarte.johansen@gmail.com>
Subject: [PATCH] ob-core: Fix indented cached result returning nil
Date: Sun, 24 May 2015 13:42:20 +0200	[thread overview]
Message-ID: <1432467740-2692-1-git-send-email-bjarte.johansen@gmail.com> (raw)

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)

             reply	other threads:[~2015-05-24 11:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-24 11:42 Bjarte Johansen [this message]
2015-05-26  8:20 ` [PATCH] ob-core: Fix indented cached result returning nil Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2015-05-21 10:38 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
2015-05-20 15:22 Bjarte Johansen
2015-05-20 22:19 ` Nicolas Goaziou
2015-05-21 10:34   ` Bjarte Johansen

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=1432467740-2692-1-git-send-email-bjarte.johansen@gmail.com \
    --to=bjarte.johansen@gmail.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).