[Top][All Lists]

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

Re: [PATCH] lisp/ob-plantuml.el: Insert results in buffer

From: Joseph Turner
Subject: Re: [PATCH] lisp/ob-plantuml.el: Insert results in buffer
Date: Sun, 31 Jul 2022 15:05:58 -0700

Ihor Radchenko <yantar92@gmail.com> writes:
> You also need to change :result-params and :result-type.
> See `org-babel-execute-src-block'.

Here's what I've got so far:

(defvar org-babel-default-header-args:plantuml
  '((:exports . "results"))
  "Default arguments for evaluating a plantuml source block.")

(defun org-babel-execute:plantuml (body params)
  "Execute a block of plantuml code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((do-export (cdr (assq :file params)))
         (params (if do-export
                     (map-merge 'list params '((:results . "file") 
(:result-params "replace" "file")))
         (out-file (or do-export
                       (org-babel-temp-file "plantuml-" ".txt"))) ; if ":file" 
is not provided, don't export, just print ASCII results
         (cmdline (cdr (assq :cmdline params)))
         (in-file (org-babel-temp-file "plantuml-"))
         (java (or (cdr (assq :java params)) ""))
         (executable (cond ((eq org-plantuml-exec-mode 'plantuml) 
                           (t "java")))
         (executable-args (cond ((eq org-plantuml-exec-mode 'plantuml) 
                                ((string= "" org-plantuml-jar-path)
                                 (error "`org-plantuml-jar-path' is not set"))
                                ((not (file-exists-p org-plantuml-jar-path))
                                 (error "Could not find plantuml.jar at %s" 
                                (t (list java
(expand-file-name org-plantuml-jar-path))))))
         (full-body (org-babel-plantuml-make-body body params))
         (cmd (mapconcat #'identity
                          (list executable)
                          (pcase (file-name-extension out-file)
                            ("png" '("-tpng"))
                            ("svg" '("-tsvg"))
                            ("eps" '("-teps"))
                            ("pdf" '("-tpdf"))
                            ("tex" '("-tlatex"))
                            ("vdx" '("-tvdx"))
                            ("xmi" '("-txmi"))
                            ("scxml" '("-tscxml"))
                            ("html" '("-thtml"))
                            ("txt" '("-ttxt"))
                            ("utxt" '("-utxt")))
                           (org-babel-process-file-name in-file)
                           (org-babel-process-file-name out-file)))
                         " ")))
    (with-temp-file in-file (insert full-body))
    (message "\n%s\n" do-export)
    (message "\n%s\n" params)
    (message "%s" cmd) (org-babel-eval cmd "")
    (if (and (string= (file-name-extension out-file) "svg")
        (org-babel-eval (format "inkscape %s -T -l %s" out-file out-file) ""))
    (unless do-export (with-temp-buffer
                        (insert-file-contents out-file)
                        (buffer-substring-no-properties (point-min) 

I've added a couple of (message ...) blocks to log the value of
do-export and params. It appears that this combination is producing a
params value which is equivalent to the value of params produced by the
current org-babel-execute:plantuml function. However, when the above
function is executed on a block like:

#+begin_src plantuml :file "this.png"
  Bob->Alice : Hello1!

I get "Code block produced no output."

I suspect that setting the scoped params variable has no effect on the
execution of the function, since I can set params to '((:results .
"none")), and I'll still get a printed result if
org-babel-default-header-args:plantuml is set to the above value.

Is it safe to modify the value of org-babel-default-header-args:plantuml
from within the function? Would that even work?

Thank you for your patience in figuring this out with me :)


reply via email to

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