emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Joseph Turner <joseph@breatheoutbreathe.in>
To: emacs-orgmode@gnu.org
Cc: Joseph Turner <joseph@breatheoutbreathe.in>
Subject: [PATCH] lisp/ob-plantuml.el: Insert results in buffer
Date: Tue, 19 Jul 2022 16:15:21 -0700	[thread overview]
Message-ID: <20220719231520.100206-1-joseph@breatheoutbreathe.in> (raw)

Allow src block execution without ":file" header arg. When ":file" is
omitted, insert txt output in buffer below src block.

TINYCHANGE
---
 etc/ORG-NEWS        |  5 +++++
 lisp/ob-plantuml.el | 10 +++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4cda357f1..1613fdab5 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -295,6 +295,11 @@ files that are exported to Texinfo.
 
 =org-at-heading-p= now returns t by default on headings inside folds.
 Passing optional argument will produce the old behaviour.
+
+*** =org-babel-execute:plantuml= can output ASCII graphs in the buffer
+
+Previously, executing PlantUML src blocks required a ":file" header argument. Now, if that header argument is omitted, an ASCII graph will be inserted below the src block.
+
 ** Removed or renamed functions and variables
 *** =org-plantump-executable-args= is renamed and applies to jar as well
 
diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index ebbcdf166..f9b41c140 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -109,8 +109,9 @@ If BODY does not contain @startXXX ... @endXXX clauses, @startuml
 (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* ((out-file (or (cdr (assq :file params))
-		       (error "PlantUML requires a \":file\" header argument")))
+  (let* ((do-export (cdr (assq :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)) ""))
@@ -155,7 +156,10 @@ This function is called by `org-babel-execute-src-block'."
     (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) ""))
-    nil)) ;; signal that output has already been written to file
+    (unless do-export (with-temp-buffer
+                        (insert-file-contents out-file)
+                        (buffer-substring-no-properties (point-min) (point-max))
+                        ))))
 
 (defun org-babel-prep-session:plantuml (_session _params)
   "Return an error because plantuml does not support sessions."
-- 
2.37.0



             reply	other threads:[~2022-07-21 15:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 23:15 Joseph Turner [this message]
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
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=20220719231520.100206-1-joseph@breatheoutbreathe.in \
    --to=joseph@breatheoutbreathe.in \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] lisp/ob-plantuml.el: Insert results in buffer' \
    /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

Code repositories for project(s) associated with this 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).