emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Price <moptop99@gmail.com>
To: Nick Dokos <ndokos@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: org-babel-execute:dot -- why doesn't this work?
Date: Thu, 24 Sep 2015 07:10:26 -0400	[thread overview]
Message-ID: <CAN_Dec8Q0VJbO3xr1ZHmfqDGA4+VkOK4U6d2RNthWtmJEGppzg@mail.gmail.com> (raw)
In-Reply-To: <87mvwc1n62.fsf@pierrot.dokosmarshall.org>

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

On Thu, Sep 24, 2015 at 12:00 AM, Nick Dokos <ndokos@gmail.com> wrote:

> Matt Price <moptop99@gmail.com> writes:
>
> > I would, however, like to avoid the clumsy intermediate step and use
> something like this instead:
> > #+name: graph-from-tables
> > #+HEADER: :var nodes=students-table graph=students-graph horiz='t
> > #+BEGIN_SRC emacs-lisp :file ~/example-diagram.png :colnames yes
> :exports results
> >   (org-babel-execute:dot
> >    (concat
> >     "graph {\n"
> >     (when horiz "rankdir=LR;\n")       ;up-down or left-right
> >     (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;"
> >               (car x) (nth 1 x) )) graph "\n")
> >     "}\n") params)
> > #+END_SRC
> >
>
> There are a couple of problems, one minor (the :colnames yes part
> truncates the graph so you have only two edges), and one major: the
> "params" argument is not defined.
>
> When a dot source block is passed to org-babel-execute:dot, the params
> argument I get [fn:1] is:
>
> ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline . #1#)
>  (:noweb . "no") (:tangle . "no") (:exports . "results")
>  (:results . "file replace") (:session . "none") (:hlines . "no")
>  (:file . "Images/foobar.png") (:result-type . value)
>  (:result-params "file" "replace") (:rowname-names) (:colname-names))
>
> So I tried passing it to org-babel-execute:dot and somewhat
> to my surprise it worked [fn:2] - try evaluating the following in your
> *scratch* buffer (make sure there is an Images subdir under the
> current directory of that buffer):
>
> --8<---------------cut here---------------start------------->8---
>
> (org-babel-execute:dot
>  "graph {
> rankdir=LR;
> a [label=\"Omar\" shape=ellipse style=\"filled\" fillcolor=\"green\"]
> b [label=\"Hindia\" shape=ellipse style=\"filled\" fillcolor=\"orange\"]
> c [label=\"Yuvrai\" shape=ellipse style=\"filled\" fillcolor=\"purple\"]
> a -- b;
> a -- c;
> b -- c;
> }
> "
>  '((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline . #1#)
>  (:noweb . "no") (:tangle . "no") (:exports . "results")
>  (:results . "file replace") (:session . "none") (:hlines . "no")
>  (:file . "Images/foobar.png") (:result-type . value)
>  (:result-params "file" "replace") (:rowname-names) (:colname-names)))
> --8<---------------cut here---------------end--------------->8---
>
> But I would hardly call this method less clumsy than your earlier
> attempt.
>
> Footnotes:
>
> [fn:1]  I made a simple dot source block with your graph
>
> #+BEGIN_SRC dot :file Images/foobar.png
> graph {
> rankdir=LR;
> a [label="Omar" shape=ellipse style="filled" fillcolor="green"]
> b [label="Hindia" shape=ellipse style="filled" fillcolor="orange"]
> c [label="Yuvrai" shape=ellipse style="filled" fillcolor="purple"]
> a -- b;
> a -- c;
> b -- c;
> }
> #+END_SRC
>
> and instrumented org-babel-execute:dot under edebug - when I executed the
> code
> block, the debugger kicked in when the function got called and I could
> get the "params" argument.
>
> [fn:2] I thought the #1 and #1# constructs (which I don't understand at
>        all) would make it blow up.
>
> --
> Nick
>
> Many thanks, Nick, and especially to the pointer to edebug (so obvious
once you say it!).  With my original code, I stepped through the whole
function and I can't quite understand why it's not working. The code block
text is generated as expected, but somehow it's not getting written, or
perhaps not executed by dot, as hoped.  Here is the debugging output:

(nodes (quote (("a" "Omar" "ellipse" "green") ("b" "Hindia" "ellipse"
"orange") ("c" "Yuvrai" "ellipse" "purple"))))

(graph (quote (("a" "b") ("a" "c"))))

(horiz (quote t))

funcall-interactively: Buffer is read-only: #<buffer ob-dot.el> [4 times]

Result: ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline .
#1#) (:noweb . "no") (:tangle . "no") (:exports . "results") (:results .
"file replace") (:var nodes ("a" "Omar" "ellipse" "green") ("b" "Hindia"
"ellipse" "orange") ("c" "Yuvrai" "ellipse" "purple")) (:var graph ("a"
"b") ("a" "c")) (:var horiz . t) (:colnames . "yes") (:file .
"~/example-diagram.png") (:hlines . "no") (:session . "none") (:result-type
. value) (:result-params "file" "replace") (:rowname-names) (:colname-names
(nodes "*node*" "*label*" "*shape*" "*fillcolor*") (graph "From" "To")))

Result: (:result-params "file" "replace")

Result: ("file" "replace")

Stop

Result: ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline .
#1#) (:noweb . "no") (:tangle . "no") (:exports . "results") (:results .
"file replace") (:var nodes ("a" "Omar" "ellipse" "green") ("b" "Hindia"
"ellipse" "orange") ("c" "Yuvrai" "ellipse" "purple")) (:var graph ("a"
"b") ("a" "c")) (:var horiz . t) (:colnames . "yes") (:file .
"~/example-diagram.png") (:hlines . "no") (:session . "none") (:result-type
. value) (:result-params "file" "replace") (:rowname-names) (:colname-names
(nodes "*node*" "*label*" "*shape*" "*fillcolor*") (graph "From" "To")))
Stop

Result: (:file . "~/example-diagram.png")
Stop

Result: (:file . "~/example-diagram.png")
Stop

Result: "~/example-diagram.png"

Result: ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline .
#1#) (:noweb . "no") (:tangle . "no") (:exports . "results") (:results .
"file replace") (:var nodes ("a" "Omar" "ellipse" "green") ("b" "Hindia"
"ellipse" "orange") ("c" "Yuvrai" "ellipse" "purple")) (:var graph ("a"
"b") ("a" "c")) (:var horiz . t) (:colnames . "yes") (:file .
"~/example-diagram.png") (:hlines . "no") (:session . "none") (:result-type
. value) (:result-params "file" "replace") (:rowname-names) (:colname-names
(nodes "*node*" "*label*" "*shape*" "*fillcolor*") (graph "From" "To")))
Stop

Result: nil
Stop

Result: nil
Stop

Stop

Result: "~/example-diagram.png"

Result: "png"

Result: "-Tpng"

Result: "-Tpng"

Result: ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline .
#1#) (:noweb . "no") (:tangle . "no") (:exports . "results") (:results .
"file replace") (:var nodes ("a" "Omar" "ellipse" "green") ("b" "Hindia"
"ellipse" "orange") ("c" "Yuvrai" "ellipse" "purple")) (:var graph ("a"
"b") ("a" "c")) (:var horiz . t) (:colnames . "yes") (:file .
"~/example-diagram.png") (:hlines . "no") (:session . "none") (:result-type
. value) (:result-params "file" "replace") (:rowname-names) (:colname-names
(nodes "*node*" "*label*" "*shape*" "*fillcolor*") (graph "From" "To")))
Stop

Result: nil
Stop

Result: nil
Stop

Result: "dot"

Result: "/tmp/babel-2749DTL/dot-2749Nkt"

Result: "/tmp/babel-2749DTL/dot-2749Nkt"

Result: "graph {\nrankdir=LR;\na [label=\"Omar\" shape=ellipse
style=\"filled\" fillcolor=\"green\"]\nb [label=\"Hindia\" shape=ellipse
style=\"filled\" fillcolor=\"orange\"]\nc [label=\"Yuvrai\" shape=ellipse
style=\"filled\" fillcolor=\"purple\"]\na -- b;\na -- c;}\n"
Stop

Result: ((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline .
#1#) (:noweb . "no") (:tangle . "no") (:exports . "results") (:results .
"file replace") (:var nodes ("a" "Omar" "ellipse" "green") ("b" "Hindia"
"ellipse" "orange") ("c" "Yuvrai" "ellipse" "purple")) (:var graph ("a"
"b") ("a" "c")) (:var horiz . t) (:colnames . "yes") (:file .
"~/example-diagram.png") (:hlines . "no") (:session . "none") (:result-type
. value) (:result-params "file" "replace") (:rowname-names) (:colname-names
(nodes "*node*" "*label*" "*shape*" "*fillcolor*") (graph "From" "To")))
Stop

Result: "graph {\nrankdir=LR;\na [label=\"Omar\" shape=ellipse
style=\"filled\" fillcolor=\"green\"]\nb [label=\"Hindia\" shape=ellipse
style=\"filled\" fillcolor=\"orange\"]\nc [label=\"Yuvrai\" shape=ellipse
style=\"filled\" fillcolor=\"purple\"]\na -- b;\na -- c;}\n"
Stop

Result: nil
Stop

Result: nil
Stop

Stop

Stop

Result: "dot"

Result: "/tmp/babel-2749DTL/dot-2749Nkt"

Result: "/tmp/babel-2749DTL/dot-2749Nkt"

Result: "-Tpng"

Stop

Result: "~/example-diagram.png"

Result: "/home/matt/example-diagram.png"
Stop

Result: "dot /tmp/babel-2749DTL/dot-2749Nkt -Tpng -o
/home/matt/example-diagram.png"
Stop

Wrote /tmp/babel-2749DTL/ob-input-2749auz
Result: ""

Result: nil

Code block evaluation complete.
Mark set

-----
it looks about right until the very end; Manually running "dot
/tmp/babel-2749DTL/dot-2749Nkt -Tpng -o /home/matt/example-diagram.png"
from a shell works fine. However, the result of:

(org-babel-eval
     (concat cmd
         " " (org-babel-process-file-name in-file)
         " " cmdline
         " -o " (org-babel-process-file-name out-file)) "")

is "nil".  Any idea why that might be?

Again, many thanks,
Matt

[-- Attachment #2: Type: text/html, Size: 13283 bytes --]

  reply	other threads:[~2015-09-24 11:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24  1:29 org-babel-execute:dot -- why doesn't this work? Matt Price
2015-09-24  4:00 ` Nick Dokos
2015-09-24 11:10   ` Matt Price [this message]
2015-09-24 12:46     ` Matt Price
2015-10-23 12:27       ` Éibhear
2015-10-23 17:43         ` Matt Price
2015-10-23 20:48           ` Éibhear

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=CAN_Dec8Q0VJbO3xr1ZHmfqDGA4+VkOK4U6d2RNthWtmJEGppzg@mail.gmail.com \
    --to=moptop99@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=ndokos@gmail.com \
    /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).