emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: Andreas Leha <andreas.leha@med.uni-goettingen.de>, emacs-orgmode@gnu.org
Subject: Re: problems with export and :cache
Date: Thu, 29 Oct 2015 13:34:50 +0000	[thread overview]
Message-ID: <87vb9pyf0l.fsf@gmail.com> (raw)
In-Reply-To: <olu4mhak6qc.fsf@med.uni-goettingen.de>

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

Hi Andreas,

2015ko urriak 28an, Andreas Leha-ek idatzi zuen:
> 
> Hi all,
> 
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>> Hi all,
>> 
>> babel's :cache seems to be ignored during export.  At least on #+call
>> lines.
>> 
>> In the example below the caching works fine for interactive evaluation,
>> i.e. C-c C-c on the #+call line returns immediately.
>> 
>> If I export the subtree with the #+call line, however, the code block
>> gets executed and the export is slow.

Export works by making a copy of the org buffer, modifying it in some
ways while executing babel code, then exporting the modified buffer
copy.  The modifications can under some circumstances change the
relevant features for the cache, leading to spurious re-evaluation.

I tried to write a patch that would do the buffer modifications in such
a way that they would not affect the cache.  But I was never happy with
the patch, and also could not find a nice simple test case for the
re-evaluation bug.  So this work never went anywhere.  (It was also 2
years ago, so things could have changed quite a bit.)  The simple patch
attached to this message fixes a bug that my testing indicated was
responsible for erroneous re-evaluations at least some of the time.

I personally regard the babel cache as dangerous and unpredictable in
its present form.  You’re much better off using language-specific
caching/memoization features and/or a disciplined regime of manual
reevaluation.

>> 
>> I'd expect no evaluation even during export.
>> 
>> Is this a bug or am I missing something?
>> 
>> Regards,
>> Andreas
>> 
>> PS: The example:
>> 
>> * Test Cached Export
>> ** A long running code block.
>> #+name: foo
>> #+begin_src emacs-lisp :var bar="baz"
>> (sit-for 15)
>> (message "bar=%S" bar)
>> #+end_src
>> 
>> #+RESULTS: foo
>> : bar="baz"
>> 
>> ** Calling
>> 
>> Exporting this subtree will demonstrate my problem.  I expect the call
>> line below to not execute anything.  This works for interactive
>> execution (C-c C-c).  But if I export this subtree only, the code is
>> executed.
>> 
>> This returns immediately thanks to the cached result.
>> #+call: foo("qux") :cache yes
>> 
>> #+results[f2b650eb5296f72a1f7237c2a65b7fb3443acf5f]:
>> : bar="qux"
> 
> 
> I should have added that adding :eval no-export to the #+call line does
> not help either.

There are two places you could add the :eval option.  See
(info "(org) Evaluating code blocks") .  You may have to experiment with
putting it in one or both places in order to get the desired result.
(If none of the possible combinations works, then it is a bug IMO.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-babel-fix-header-arg-duplication.patch --]
[-- Type: text/x-diff, Size: 1950 bytes --]

From d7355798edc643bbbca7ab1ead2a2e11f37aa64c Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
Date: Thu, 29 Oct 2015 13:31:28 +0000
Subject: [PATCH] babel: fix header arg duplication

* lisp/ob-core.el (org-babel-process-params): Make idempotent.
* testing/lisp/test-ob.el (ob/process-params-no-duplicates): New test.
---
 lisp/ob-core.el         |  8 +++++++-
 testing/lisp/test-ob.el | 12 ++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 61753ce..fd6d785 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1597,7 +1597,13 @@ shown below.
       (cons :result-type  (cond ((member "output" result-params) 'output)
 				((member "value" result-params) 'value)
 				(t 'value))))
-     (org-babel-get-header params :var 'other))))
+     (loop for item in params
+	   unless (memq (car item) '(:colname-names
+				     :rowname-names
+				     :result-params
+				     :result-type
+				     :var))
+	   collect item))))
 
 ;; row and column names
 (defun org-babel-del-hlines (table)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 508a3ed..c2feb39 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1477,6 +1477,18 @@ echo \"$data\"
   (should (equal "foo\\\"bar"
 		 (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
 
+(ert-deftest ob/process-params-no-duplicates ()
+    (should (equal (org-babel-process-params '((:colname-names . 1)
+                                               (:rowname-names . 1)
+                                               (:result-params . 1)
+                                               (:result-type . 1)
+                                               (:var . "\"foo\"")))
+                   '((:var)
+		     (:colname-names . 1)
+		     (:rowname-names . 1)
+		     (:result-params . 1)
+		     (:result-type . value)))))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here
-- 
2.6.2


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


-- 
Aaron Ecay

  reply	other threads:[~2015-10-29 13:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28 21:37 problems with export and :cache Andreas Leha
2015-10-28 21:45 ` Andreas Leha
2015-10-29 13:34   ` Aaron Ecay [this message]
2015-10-29 14:22     ` Nicolas Goaziou
2015-10-29 15:14       ` Aaron Ecay
2015-10-29 16:42         ` Nicolas Goaziou
2015-10-29 17:05           ` Aaron Ecay
2015-10-29 17:16             ` Nicolas Goaziou
2015-10-29 19:11         ` Aaron Ecay
2015-10-30 23:40           ` Andreas Leha
2015-11-07 16:37         ` Achim Gratz
2015-11-07 20:33           ` Aaron Ecay
2015-11-07 22:43             ` Achim Gratz
2015-10-29 14:58     ` Andreas Leha
2015-10-29 15:17       ` Aaron Ecay
2015-10-29 16:51       ` Nicolas Goaziou
2015-10-29 19:05         ` Aaron Ecay
2015-10-29 20:32           ` Thomas S. Dye
2015-10-29 23:01             ` Andreas Leha
2015-11-01 22:56           ` Nicolas Goaziou
2015-11-04 12:01             ` Aaron Ecay
2015-11-04 22:41               ` Nicolas Goaziou
2015-11-05 14:51                 ` Aaron Ecay
2015-11-05 14:55                   ` Nicolas Goaziou

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=87vb9pyf0l.fsf@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=andreas.leha@med.uni-goettingen.de \
    --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).