* [PATCH] Prevent overwriting of output files from babel calls with nil result
@ 2015-10-27 22:55 Éibhear
2015-10-29 13:53 ` Aaron Ecay
0 siblings, 1 reply; 6+ messages in thread
From: Éibhear @ 2015-10-27 22:55 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 725 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Here's a patch to ob-emacs-lisp.el to allow me to start generating
graphs with dot again.
Thanks,
Éibhear
- --
Éibhear Ó hAnluain
Dublin, Ireland.
+-------------------------------+--------------------------------+
| e-mail: eibhear.geo@gmail.com | Web: [http://www.gibiris.org/] |
| Twitter: @eibhear | Google+: +Éibhear Ó hAnluain |
| Mobile: +353 86 856 5666 | VoIP: sip:eibhear@linphone.org |
+-------------------------------+--------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEARECAAYFAlYwAPcACgkQ0ST+nPIXcQb+7QCbB9M8FNYMQM/AO9Sy57vMyjdD
TsMAn0KiaebLDLAxcbQX7OmuQvULwQ42
=wDzV
-----END PGP SIGNATURE-----
[-- Attachment #2: 0001-ob-emacs-lisp.el-Don-t-convert-a-nil-result-to-nil.patch --]
[-- Type: text/x-patch, Size: 1996 bytes --]
From a25cd4da8791ff9bb759ba38c05ff07650555055 Mon Sep 17 00:00:00 2001
From: Eibhear O hAnluain <eibhear.geo@gmail.com>
Date: Tue, 27 Oct 2015 22:43:02 +0000
Subject: [PATCH] ob-emacs-lisp.el: Don't convert a nil result to "nil"
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp): if `result' is nil
after the execution of the emacs-lisp code, then it should be passed
to `ob-babel-result-cond' as nil, and not converted to "nil".
When successful, `org-babel-execute:dot' returns nil, as the output is
written to a file. Commit 041ca4b6f4c7fe1a7e7eb22e2f08ec2e08577bf9
causes the macro `org-babel-result-cond' to overwrite the file and
populate it with the text "nil". This is because the nil `result' from
the call to the emacs-lisp code is converted to "nil" in
`org-babel-execute:emacs-lisp' when calling `org-babel-result-cond'.
This patch preserves `result' as nil.
TINYCHANGE
---
lisp/ob-emacs-lisp.el | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index 796293b..bbd3dc8 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -59,12 +59,14 @@
(org-babel-expand-body:emacs-lisp
body params))))))
(org-babel-result-cond (cdr (assoc :result-params params))
- (let ((print-level nil)
- (print-length nil))
- (if (or (member "scalar" (cdr (assoc :result-params params)))
- (member "verbatim" (cdr (assoc :result-params params))))
- (format "%S" result)
- (format "%s" result)))
+ (if result
+ (let ((print-level nil)
+ (print-length nil))
+ (if (or (member "scalar" (cdr (assoc :result-params params)))
+ (member "verbatim" (cdr (assoc :result-params params))))
+ (format "%S" result)
+ (format "%s" result)))
+ )
(org-babel-reassemble-table
result
(org-babel-pick-name (cdr (assoc :colname-names params))
--
2.1.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Prevent overwriting of output files from babel calls with nil result
2015-10-27 22:55 [PATCH] Prevent overwriting of output files from babel calls with nil result Éibhear
@ 2015-10-29 13:53 ` Aaron Ecay
2015-10-29 17:31 ` "Éibhear"
0 siblings, 1 reply; 6+ messages in thread
From: Aaron Ecay @ 2015-10-29 13:53 UTC (permalink / raw)
To: Éibhear, Org Mode
Hi Éibhear,
I’m afraid I don’t understand the problem the patch is trying to fix.
Can you provide a MWE (minimal working example) that illustrates the bug
you’re observing?
Thanks,
--
Aaron Ecay
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Prevent overwriting of output files from babel calls with nil result
2015-10-29 13:53 ` Aaron Ecay
@ 2015-10-29 17:31 ` "Éibhear"
2015-10-29 19:59 ` Aaron Ecay
0 siblings, 1 reply; 6+ messages in thread
From: "Éibhear" @ 2015-10-29 17:31 UTC (permalink / raw)
To: "Éibhear", Org Mode
> Hi Éibhear,
>
> I'm afraid I don't understand the problem the patch is trying to fix.
> Can you provide a MWE (minimal working example) that illustrates the bug
> you're observing?
>
> Thanks,
>
> --
> Aaron Ecay
>
Hi Aaron,
Thanks for getting back to me.
Prerequisites:
- The dot utility from graphvis is available
- org-babel-load-languages includes '(dot . t)
See below for a sample org file.
For org-mode 8.2.10, invoking C-c C-c on the #+BEGIN_SRC line produces a
file called sample-flow.png, representing a simple flow from a "Start"
node to an "End" node.
In org-mode 8.3.1 and 8.3.2, sample-flow.png contains only the text "nil".
I believe the bug to be in `org-babel-execute:emacs-lisp', when the second
parameter to `org-babel-result-cond' is being evaluated. When `result' is
nil, it is converted to "nil", and this is being written into the
sample-flow.png file, overwriting the contents that the dot utility had
created.
My patch prevents a nil result being converted into a text string when
calling `org-babel-result-cond'. I believe this is an appropriate change.
Éibhear
---------------------->8==========================
* Charts
** Chart from flows
#+name: chart-from-flows
#+HEADER: :var nodes=sample-elements graph=sample-connections
ranks=sample-ranks
#+BEGIN_SRC emacs-lisp :file ./sample-flow.png :colnames yes :exports
results
(org-babel-execute:dot
(concat
"digraph {\n"
"//rankdir=LR;\n" ;; remove comment characters '//' for
horizontal layout; add for vertical layout
(mapconcat
(lambda (x)
(format "%s [label=\"%s\" shape=%s style=\"filled\"
fillcolor=\"%s\"]"
(car x)
(nth 1 x)
(if (string= "" (nth 2 x)) "box" (nth 2 x))
(if (string= "" (nth 3 x)) "none" (nth 3 x))
)) nodes "\n")
"\n"
(mapconcat
(lambda (x)
(format "%s -> %s [taillabel=\"%s\" color=\"%s\" style=\"%s\"]"
(car x)
(nth 1 x)
(nth 2 x)
(if (string= "" (nth 3 x)) "black" (nth 3 x))
(if (string= "" (nth 4 x)) "solid" (nth 4 x))
)) graph "\n")
"\n"
(mapconcat
(lambda (x)
(format "{rank=%s %s}"
(if (or (string= "min" (car x)) (string=
"max" (car x))) (car x) (concat "same; " (car
x))) (nth 1 x))) ranks "\n")
"}\n") params)
#+END_SRC
#+RESULTS: chart-from-flows
[[file:./sample-flow.png]]
** Development process flow
*** Flow elements
#+name: sample-elements
| *node* | *label* | *shape* | *fillcolor* |
|--------+---------+---------+-------------|
| start | Start | ellipse | |
| end | End | ellipse | |
*** Flow connections
#+name: sample-connections
| from | to | label | colour | style |
|-------+-----+-------+--------+-------|
| start | end | | | |
*** Flow ranks
#+name: sample-ranks
| anchor | node |
|--------+-------|
| min | start |
| start | end |
---------------------->8==========================
--
Éibhear Ó hAnluain,
Dublin, Ireland
+-------------------------------+--------------------------------+
| e-mail: eibhear.geo@gmail.com | Web: [http://www.gibiris.org/] |
| Twitter: @eibhear | Google+: +Éibhear Ó hAnluain |
| Mobile: +353 86 856 5666 | VoIP: sip:eibhear@linphone.org |
+-------------------------------+--------------------------------+
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Prevent overwriting of output files from babel calls with nil result
2015-10-29 17:31 ` "Éibhear"
@ 2015-10-29 19:59 ` Aaron Ecay
2015-10-30 23:41 ` Éibhear
0 siblings, 1 reply; 6+ messages in thread
From: Aaron Ecay @ 2015-10-29 19:59 UTC (permalink / raw)
To: Éibhear, Org Mode
Hi Éibhear,
Thanks for sending the example. I think it is not expected to work
going forward because the lisp block relies on being able to pick up the
value of ‘params’, which will not be possible now that org is moving to
lexical binding. In general, org-babel-execute:foo are internal
functions, so trying to trick them int working properly in an elisp code
block is a bad idea.
The emacs-lisp babel backend is special, so I can’t predict what the
result would be of making it return the symbol nil instead of the string
“nil.” (Though for the sake of consistency it ought to allow nil symbol
returns.)
On the balance, I recommend you do something like the following, using
two code blocks (untested):
,----
| #+name: dot-code
| #+begin_src emacs-lisp :results verbatim
| (generate-dot-code)
| #+end_src
|
| #+RESULTS: dot-code
| : "your dot code will appear here"
|
| #+begin_src dot :file foo.png :var code=dot-code()
| $code
| #+end_src
|
| #+RESULTS:
| [[file:foo.png]]
`----
Hope this helps,
--
Aaron Ecay
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Prevent overwriting of output files from babel calls with nil result
2015-10-29 19:59 ` Aaron Ecay
@ 2015-10-30 23:41 ` Éibhear
2015-11-04 10:59 ` Aaron Ecay
0 siblings, 1 reply; 6+ messages in thread
From: Éibhear @ 2015-10-30 23:41 UTC (permalink / raw)
To: aaronecay, Org Mode
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 29/10/15 19:59, Aaron Ecay wrote:
> Hi Éibhear,
>
> Thanks for sending the example. I think it is not expected to
> work going forward because the lisp block relies on being able to
> pick up the value of ‘params’, which will not be possible now that
> org is moving to lexical binding. In general,
> org-babel-execute:foo are internal functions, so trying to trick
> them int working properly in an elisp code block is a bad idea.
>
> The emacs-lisp babel backend is special, so I can’t predict what
> the result would be of making it return the symbol nil instead of
> the string “nil.” (Though for the sake of consistency it ought to
> allow nil symbol returns.)
>
> On the balance, I recommend you do something like the following,
> using two code blocks (untested):
>
> ,---- | #+name: dot-code | #+begin_src emacs-lisp :results
> verbatim | (generate-dot-code) | #+end_src | | #+RESULTS: dot-code
> | : "your dot code will appear here" | | #+begin_src dot :file
> foo.png :var code=dot-code() | $code | #+end_src | | #+RESULTS: |
> [[file:foo.png]] `----
>
> Hope this helps,
>
Thanks Aaron.
The following works (":results raw" being the significant change):
,----
| #+name: dot-code
| #+begin_src emacs-lisp :results raw
| (generate-dot-code)
| #+end_src
|
| #+RESULTS: dot-code
|
| #+begin_src dot :file foo.png :var code=dot-code()
| $code
| #+end_src
|
| #+RESULTS:
| [[file:foo.png]]
`----
Éibhear
- --
Éibhear Ó hAnluain
Dublin, Ireland.
+-------------------------------+--------------------------------+
| e-mail: eibhear.geo@gmail.com | Web: [http://www.gibiris.org/] |
| Twitter: @eibhear | Google+: +Éibhear Ó hAnluain |
| Mobile: +353 86 856 5666 | VoIP: sip:eibhear@linphone.org |
+-------------------------------+--------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlY0ABgACgkQ0ST+nPIXcQZUCgCgpDpWlO2u/D3yT6lMQ7DRO0j4
JV4An2O021+hm6DqwdUXLh8OFKEkUA3v
=+bEL
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Prevent overwriting of output files from babel calls with nil result
2015-10-30 23:41 ` Éibhear
@ 2015-11-04 10:59 ` Aaron Ecay
0 siblings, 0 replies; 6+ messages in thread
From: Aaron Ecay @ 2015-11-04 10:59 UTC (permalink / raw)
To: Éibhear, Org Mode
Hi Éibhear,
2015ko urriak 30an, Éibhear-ek idatzi zuen:
[...]
>
> The following works (":results raw" being the significant change):
I’m glad you figured it out! Thanks for updating us with your solution.
--
Aaron Ecay
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-11-04 10:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-27 22:55 [PATCH] Prevent overwriting of output files from babel calls with nil result Éibhear
2015-10-29 13:53 ` Aaron Ecay
2015-10-29 17:31 ` "Éibhear"
2015-10-29 19:59 ` Aaron Ecay
2015-10-30 23:41 ` Éibhear
2015-11-04 10:59 ` Aaron Ecay
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).