From: Joseph Turner <joseph@breatheoutbreathe.in>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] lisp/ob-plantuml.el: Insert results in buffer
Date: Sun, 31 Jul 2022 15:05:58 -0700 [thread overview]
Message-ID: <875yjdkk25.fsf@breatheoutbreathe.in> (raw)
In-Reply-To: <87a68t9uds.fsf@localhost>
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")))
params))
(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) org-plantuml-executable-path)
(t "java")))
(executable-args (cond ((eq org-plantuml-exec-mode 'plantuml) org-plantuml-executable-args)
((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" org-plantuml-jar-path))
(t (list java
"-jar"
(shell-quote-argument (expand-file-name org-plantuml-jar-path))))))
(full-body (org-babel-plantuml-make-body body params))
(cmd (mapconcat #'identity
(append
(list executable)
executable-args
(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")))
(list
"-p"
cmdline
"<"
(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-plantuml-svg-text-to-path)
(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) (point-max))))))
```
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!
#+end_src
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 :)
Joseph
next prev parent reply other threads:[~2022-07-31 22:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 23:15 [PATCH] lisp/ob-plantuml.el: Insert results in buffer Joseph Turner
2022-07-25 13:15 ` Ihor Radchenko
2022-07-25 19:52 ` Joseph Turner
2022-07-26 5:50 ` Ihor Radchenko
2022-07-27 20:51 ` Joseph Turner
2022-07-28 14:36 ` Ihor Radchenko
2022-07-31 22:05 ` Joseph Turner [this message]
2022-08-02 12:42 ` Ihor Radchenko
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=875yjdkk25.fsf@breatheoutbreathe.in \
--to=joseph@breatheoutbreathe.in \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@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).