On Tue, Oct 24 2023, Max Nikulin <maniku...@gmail.com> wrote: > On 23/10/2023 18:18, Florin Boariu wrote: >> >>> sh-5.1$ flatpak-spawn --host toolbox run /usr/bin/ditaa >>> /tmp/foo.txt -o /tmp/foo.png > > thanks > >> I really _need_ to generically execute a command. > > I hope, a couple of workarounds are still possible. > > 1. Get java command by adding bash -x (or /usr/bin/bash, or > "/usr/bin/env bash") > > flatpak-spawn --host toolbox run bash -x /usr/bin/ditaa \ > /tmp/foo.txt -o /tmp/foo.png > > - set `org-babel-ditaa-java-cmd' to something like > "flatpak-spawn --host toolbox run /usr/bin/java", > - set `org-ditaa-jar-path' to path to ditaa.jar reported by the > command above, > - add other options to either `org-babel-header-args:ditaa' :java > property or to `org-babel-ditaa-java-cmd' > - perhaps add /usr/bin/env JAVA_HOME=... and other required > environment variables before java binary. > > > 2. > - set `org-babel-ditaa-java-cmd' to > "flatpak-spawn --host toolbox run /usr/bin/ditaa". > - set `org-ditaa-jar-option' to empty string. > - Call of `shell-quote-argument' makes it impossible to set > `org-ditaa-jar-path' to empty string, so set the following variables > to some harmless value, e.g. "-Dfile.encoding=UTF-8" (anything added > through :java babel header argument): > + `org-ditaa-jar-path' > + `org-ditaa-eps-jar-path' > > > I agree that it should be possible to call ditaa executable > directly. Perhaps it is not possible because for a long time ditaa.jar > was a part of Org mode repository (there were a lot of messages > against dropping of jar files from the repository). It seems, nobody > is ready to take responsibility and to become maintainer of > ob-ditaa.el while active users have no ability to install ditaa as a > package, so they anyway have to download .jar from upstream. > > I find it tedious to add "flatpak-spawn ..." to every tool used by > Emacs. Who is the publisher of the flatpak? I would expect a directory > with symlinks named ditaa, java, git, gcc, cpp, etc to a script line > > #!/bin/sh > exec flatpak-spawn --host toolbox run /usr/bin/env "$0" "$@" > > (or "$(basename "$0")") > > mounted to flatpak runtime and added to $PATH. Perhaps another > approach exist and it should be discussed with the packager and Emacs > developers.
Florin, Max is right, there are work-arounds possible, although a bit different from what he suggests. The attached org file shows how to do what you want using the existing ob-ditaa.el code. I have also attached the exported html document with the image created. Tell us if it works for the version of Org that you are using. Leo
#+author: Leo Butler #+title: Executing ditaa from a script * Executing =ditaa= from a script Org assumes that =ditaa= is run as a java jar file. Users may need to use a script to run =ditaa=. This example shows how. First, set ~org-babel-ditaa-java-cmd~ and ~org-ditaa-jar-option~ to empty strings and ~org-ditaa-jar-path~ to the script's path; here, it is =/usr/bin/ditaa=. This example uses ~setq-local~ to change only the values in this buffer. #+name: hello-world-from-script.el.org #+begin_src org :exports code :results replace ,#+name: hello-world-from-script.el ,#+begin_src emacs-lisp :exports none :results none (setq-local org-babel-ditaa-java-cmd "" org-ditaa-jar-option "" org-ditaa-jar-path "/usr/bin/ditaa") ,#+end_src #+end_src #+RESULTS: hello-world-from-script.el.org #+name: hello-world-from-script.el #+begin_src emacs-lisp :exports none :results none (setq-local org-babel-ditaa-java-cmd "" org-ditaa-jar-option "" org-ditaa-jar-path "/usr/bin/ditaa") #+end_src Second, in the =ditaa= code-block, set the header argument =:java= to the empty string =""=. The =:cmdline= header argument can be used to pass command-line options to =ditaa= via the script. #+name: hello-world-from-script.org #+begin_src org :exports code :results replace ,#+name: hello-world-from-script ,#+begin_src ditaa :file images/hello-world-from-script.png :java "" :cmdline -r -e UTF-8 +----------------+ | | | Hello World | | from a script! | | | +----------------+ ,#+end_src #+end_src #+RESULTS: hello-world-from-script.org #+name: hello-world-from-script #+begin_src ditaa :file images/hello-world-from-script.png :java "" :cmdline -r -e UTF-8 +----------------+ | | | Hello World | | from a script! | | | +----------------+ #+end_src #+RESULTS: hello-world-from-script [[file:images/hello-world-from-script.png]]Title: Executing ditaa from a script
Executing ditaa from a script
Table of Contents
1. Executing ditaa
from a script
Org assumes that ditaa
is run as a java jar file. Users may need to
use a script to run ditaa
. This example shows how.
First, set org-babel-ditaa-java-cmd
and org-ditaa-jar-option
to
empty strings and org-ditaa-jar-path
to the script's path; here, it
is /usr/bin/ditaa
. This example uses setq-local
to change only
the values in this buffer.
#+name: hello-world-from-script.el #+begin_src emacs-lisp :exports none :results none (setq-local org-babel-ditaa-java-cmd "" org-ditaa-jar-option "" org-ditaa-jar-path "/usr/bin/ditaa") #+end_src
Second, in the ditaa
code-block, set the header argument :java
to
the empty string ""
. The :cmdline
header argument can be used to
pass command-line options to ditaa
via the script.
#+name: hello-world-from-script #+begin_src ditaa :file images/hello-world-from-script.png :java "" :cmdline -r -e UTF-8 +----------------+ | | | Hello World | | from a script! | | | +----------------+ #+end_src
Created: 2023-10-26 Thu 10:23