emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] bug#26467: 25.2; [Org mode] Call dot babel from elisp generate inval


From: Nicolas Goaziou
Subject: [O] bug#26467: 25.2; [Org mode] Call dot babel from elisp generate invalid image
Date: Sun, 15 Apr 2018 09:59:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Hello,

wang jinjian <address@hidden> writes:

> Use case is call dot babel from elisp code block. refer to
> http://orgmode.org/worg/org-tutorials/org-dot-diagrams.html
>
> Below is a more minimal example:
>
> #+NAME: nodes
> | From | To | Weight |
>
> |------+----+--------|
> | A    | B  |      3 |
> | A    | C  |      2 |
> | B    | D  |      4 |
> | B    | E  |      5 |
> | C    | F  |     10 |
>
> #+BEGIN_SRC elisp :file a.png :var nodes=nodes
>     (defun rowfun(x)
>         (format "%s -> %s [label=%s];" (nth 0 x) (nth 1 x) (nth 2 x))
>         )
>       (defun dotgen(nodes)
>         (let ((dotbegin "digraph {\nnode [shape=circle]\n")
>               (dotend "\n}"))
>           (concat dotbegin
>                   (mapconcat #'rowfun nodes "\n")
>                   dotend)))
> (setq params (nth 2 (org-babel-get-src-block-info)))
>   (org-babel-execute:dot (dotgen nodes) params)
> #+END_SRC
>
> If run this block with C-c C-c, it will generate a image a.png with
> "nil" string in it. so it's a invalid image file.

I can achieve the desired effect with:

    #+name: nodes
    | From | To | Weight |
    |------+----+--------|
    | A    | B  |      3 |
    | A    | C  |      2 |
    | B    | D  |      4 |
    | B    | E  |      5 |
    | C    | F  |     10 |

    #+begin_src elisp :file /tmp/a.png :var nodes=nodes :results file
    (defun rowfun (x)
      (format "%s -> %s [label=%s];" (nth 0 x) (nth 1 x) (nth 2 x)))
    (defun dotgen (nodes)
      (format "digraph {\nnode [shape=circle]\n%s\n}"
              (mapconcat #'rowfun nodes "\n")))
    (dotgen nodes)
    #+end_src

I don't see why you would need to call `org-babel-execute:dot'.

Does it fix your issue?

Regards,

-- 
Nicolas Goaziou                                                0x80A93738





reply via email to

[Prev in Thread] Current Thread [Next in Thread]