emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
@ 2022-08-03 19:02 Joseph Turner
  2022-08-05  5:15 ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Joseph Turner @ 2022-08-03 19:02 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: yantar92, Joseph Turner

When :results header arg is set to a value that doesn't include
"file", insert txt output in buffer below src block.

TINYCHANGE
---
 etc/ORG-NEWS        |  7 +++++++
 lisp/ob-plantuml.el | 13 ++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4cda357f1..b8cd05d4e 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -295,6 +295,13 @@ 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 always exported to a file.  Now, if
+:results is set to a value which does not include "file", no file will be
+exported and 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..85dd34e62 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -109,8 +109,12 @@ 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 (member "file"
+                            (split-string (cdr (assq :results params)))))
+         (out-file (if do-export
+                       (or (cdr (assq :file params))
+                           (error "No :file provided but :results set to file. For plain text output, set :results to verbatim"))
+		     (org-babel-temp-file "plantuml-" ".txt")))
 	 (cmdline (cdr (assq :cmdline params)))
 	 (in-file (org-babel-temp-file "plantuml-"))
 	 (java (or (cdr (assq :java params)) ""))
@@ -155,7 +159,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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-08-03 19:02 [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer Joseph Turner
@ 2022-08-05  5:15 ` Ihor Radchenko
  2022-08-05 20:10   ` Joseph Turner
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-08-05  5:15 UTC (permalink / raw)
  To: Joseph Turner; +Cc: emacs-orgmode

Joseph Turner <joseph@breatheoutbreathe.in> writes:

> When :results header arg is set to a value that doesn't include
> "file", insert txt output in buffer below src block.

This looks reasonable. Thanks!

> -  (let* ((out-file (or (cdr (assq :file params))
> -		       (error "PlantUML requires a \":file\" header argument")))
> +  (let* ((do-export (member "file"
> +                            (split-string (cdr (assq :results params)))))

Let's take this opportunity and fix another omission in ob-plantuml.
:results may generally contain Elisp sexps to be evaluated and the whole
split-string busyness is not accurate. Please use :result-params list
instead of :results.

Also, can you please update the ob-plantuml documentation according to
the changes made. The current version is in
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-plantuml.html

You will need to create a patch against
https://git.sr.ht/~bzg/worg/tree/master/item/org-contrib/babel/languages/ob-doc-plantuml.org
repo.

Best,
Ihor


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-08-05  5:15 ` Ihor Radchenko
@ 2022-08-05 20:10   ` Joseph Turner
  2022-08-06  8:19     ` Ihor Radchenko
  2022-10-30  6:23     ` Ihor Radchenko
  0 siblings, 2 replies; 7+ messages in thread
From: Joseph Turner @ 2022-08-05 20:10 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> Let's take this opportunity and fix another omission in ob-plantuml.
> :results may generally contain Elisp sexps to be evaluated and the whole
> split-string busyness is not accurate. Please use :result-params list
> instead of :results.

Good catch! I will submit a v3 patch. Is this still a TINYCHANGE or
shall I do a copyright assignment?

> Also, can you please update the ob-plantuml documentation according to
> the changes made. The current version is in
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-plantuml.html

Gladly.

Best,

Joseph


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-08-05 20:10   ` Joseph Turner
@ 2022-08-06  8:19     ` Ihor Radchenko
  2022-10-30  6:23     ` Ihor Radchenko
  1 sibling, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2022-08-06  8:19 UTC (permalink / raw)
  To: Joseph Turner; +Cc: emacs-orgmode

Joseph Turner <joseph@breatheoutbreathe.in> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> Let's take this opportunity and fix another omission in ob-plantuml.
>> :results may generally contain Elisp sexps to be evaluated and the whole
>> split-string busyness is not accurate. Please use :result-params list
>> instead of :results.
>
> Good catch! I will submit a v3 patch. Is this still a TINYCHANGE or
> shall I do a copyright assignment?

WORG does not have the copyright requirement.
As long as your contribution to Org core does not exceed 15LOC, you are
good to go with TINYCHANGE. Of course, having copyright assignment will
be good to have if you plan to submit more patches.


-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-08-05 20:10   ` Joseph Turner
  2022-08-06  8:19     ` Ihor Radchenko
@ 2022-10-30  6:23     ` Ihor Radchenko
  2022-10-31  6:02       ` Ihor Radchenko
  1 sibling, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-10-30  6:23 UTC (permalink / raw)
  To: Joseph Turner; +Cc: Ihor Radchenko, emacs-orgmode

Joseph Turner <joseph@breatheoutbreathe.in> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> Let's take this opportunity and fix another omission in ob-plantuml.
>> :results may generally contain Elisp sexps to be evaluated and the whole
>> split-string busyness is not accurate. Please use :result-params list
>> instead of :results.
>
> Good catch! I will submit a v3 patch.

Did you have a chance to work on the patch?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-10-30  6:23     ` Ihor Radchenko
@ 2022-10-31  6:02       ` Ihor Radchenko
  2022-10-31 19:20         ` Joseph Turner
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-10-31  6:02 UTC (permalink / raw)
  To: Joseph Turner; +Cc: Ihor Radchenko, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

>> Good catch! I will submit a v3 patch.
>
> Did you have a chance to work on the patch?

Oops. I missed that you did and I even merged it. :facepalm:
Sorry for the noise.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer
  2022-10-31  6:02       ` Ihor Radchenko
@ 2022-10-31 19:20         ` Joseph Turner
  0 siblings, 0 replies; 7+ messages in thread
From: Joseph Turner @ 2022-10-31 19:20 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Ihor Radchenko, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

No worries!!

Have a good day :)

On October 30, 2022 11:02:18 PM PDT, Ihor Radchenko <yantar92@posteo.net> wrote:
>Ihor Radchenko <yantar92@posteo.net> writes:
>
>>> Good catch! I will submit a v3 patch.
>>
>> Did you have a chance to work on the patch?
>
>Oops. I missed that you did and I even merged it. :facepalm:
>Sorry for the noise.
>
>-- 
>Ihor Radchenko // yantar92,
>Org mode contributor,
>Learn more about Org mode at <https://orgmode.org/>.
>Support Org development at <https://liberapay.com/org-mode>,
>or support my work at <https://liberapay.com/yantar92>

[-- Attachment #2: Type: text/html, Size: 1312 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-31 19:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-03 19:02 [PATCH v2] lisp/ob-plantuml.el: Insert results in buffer Joseph Turner
2022-08-05  5:15 ` Ihor Radchenko
2022-08-05 20:10   ` Joseph Turner
2022-08-06  8:19     ` Ihor Radchenko
2022-10-30  6:23     ` Ihor Radchenko
2022-10-31  6:02       ` Ihor Radchenko
2022-10-31 19:20         ` Joseph Turner

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).