From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: org-babel-execute:dot -- why doesn't this work? Date: Thu, 24 Sep 2015 00:00:53 -0400 Message-ID: <87mvwc1n62.fsf@pierrot.dokosmarshall.org> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZexiV-0005vh-A5 for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 00:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZexiR-0006Ay-6p for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 00:01:07 -0400 Received: from plane.gmane.org ([80.91.229.3]:46408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZexiR-00069e-1N for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 00:01:03 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZexiO-0006Sm-5U for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 06:01:00 +0200 Received: from pool-108-20-41-232.bstnma.fios.verizon.net ([108.20.41.232]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Sep 2015 06:01:00 +0200 Received: from ndokos by pool-108-20-41-232.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Sep 2015 06:01:00 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Matt Price 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