Hello Rudy,

thanks again for the explanation.

I mainly worked on my own till now (when it comes to coding). Just recently I 
started to work with github/commits/PRs.

It is always good to learn something new. Please have a look at the attached 
patch. I created it according to your info using Magit.

This time this single patch contains both changes (the one to ob-plantuml.el 
and the one to the test-ob-plantuml.el).

I hope the syntax inside and my description is ok.

Best
Tim

On 15 Sep 2025, at 9:43, Rudolf Adamkovič wrote:

> Tim Hansinger t...@timhansinger.com writes:
>
>> thank you very much for verifying the issue.
>
> Tim, thank you for investigating and fixing the problem!
>
>> I am very new to this so I hope this is what you mean.
>
>> I created a patch using the patch command [...]
>
> Almost there!
>
> A Git patch is like the standard Unix patch (which you created), but it
> includes more information, such as the author, date, and commit message.
>
> As to how you do it, you have a couple of options.
>
> The original way is to use `git send-mail', where Git creates and sends
> your patch over e-mail. This is how Linus Torvalds, the author of Git,
> envisioned Git to be used.
>
> A more interactive way is to use Emacs and Magit. First, you pull the
> Git repo and work on your commit [*]. Then, when you are happy with
> your commit, you type `W c c' in Magit to create a Git patch file.
>
> [*] When crafting your commit, pay attention to the commit message:
> https://orgmode.org/worg/org-contribute.html#commit-messages
>
> P.S. As for testing, I typically do the following:
>
> - Open testing/org-test.el' and M-x eval-buffer RET'.
> - Add some test(s) to `testing/lisp/...'.
> - Evaluate newly added test(s) interactively, using `C-c C-e'.
> - Run all tests with `make test' in the terminal.
>
> Rudy
>
> "All of humanity's problems stem from man's inability to sit quietly in
> a room alone." --- Blaise Pascal, Pensées, 1670
>
> Rudolf Adamkovič rud...@adamkovic.org [he/him]
> http://adamkovic.org
From 7b727afbb9fe118909752c62608e0f9d247c7bad Mon Sep 17 00:00:00 2001
From: Tim Hansinger <t...@timhansinger.com>
Date: Mon, 15 Sep 2025 17:52:15 +0200
Subject: [PATCH] ob-plantuml.el: Fix for var definition

* lisp/ob-plantuml.el (org-babel-plantuml-make-body): On (some) macOS systems
the var definition was not written inside pre-existing @startxxx ... @endxxx
clauses.

* testing/lisp/test-ob-plantuml.el
(test-ob-plantuml/single-var-on-body-with-start-end-clauses):
Added an additional test for aboves use case (var definition on a BODY
with pre-existing @startxxx ... @endxxx clauses).

Reported-by: "Tim Hansinger" <t...@timhansinger.com>
Link: 
https://list.orgmode.org/3291b2dc-ddbe-4b54-84b9-bb2c08c38...@timhansinger.com/
---
 lisp/ob-plantuml.el              | 22 +++++++++++++++++-----
 testing/lisp/test-ob-plantuml.el | 25 +++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index 05a4f7263..fc5b0e1f1 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -104,11 +104,23 @@ function to convert variables to PlantUML assignments.
 
 If BODY does not contain @startXXX ... @endXXX clauses, @startuml
 ... @enduml will be added."
-  (let ((full-body
-        (org-babel-expand-body:generic
-         body params (org-babel-variable-assignments:plantuml params))))
-    (if (string-prefix-p "@start" body t) full-body
-      (format "@startuml\n%s\n@enduml" full-body))))
+  (let ((assignments (org-babel-variable-assignments:plantuml params)))
+    (if
+        (or (string-prefix-p "@start" body t)
+            (string-prefix-p "\\@start" body t))
+        (if assignments
+            (let*
+                ((lines (split-string body "\n")) (first-line (car lines))
+                 (rest-lines (cdr lines))
+                 (assignment-lines (mapconcat 'identity assignments "\n"))
+                 (clean-first-line
+                  (replace-regexp-in-string "\\\\@" "@" first-line)))
+              (concat clean-first-line "\n" assignment-lines
+                      (when rest-lines
+                        (concat "\n" (mapconcat 'identity rest-lines "\n")))))
+          body)
+      (let ((full-body (org-babel-expand-body:generic body params 
assignments)))
+        (format "@startuml\n%s\n@enduml" full-body)))))
 
 (defun org-babel-execute:plantuml (body params)
   "Execute a block of plantuml code with org-babel.
diff --git a/testing/lisp/test-ob-plantuml.el b/testing/lisp/test-ob-plantuml.el
index b45d38be6..6feee9cf9 100644
--- a/testing/lisp/test-ob-plantuml.el
+++ b/testing/lisp/test-ob-plantuml.el
@@ -45,6 +45,31 @@ class CLASSNAME
           (car src-block-info)
           (car (cdr src-block-info)))))))))
 
+(ert-deftest test-ob-plantuml/single-var-on-body-with-start-end-clauses ()
+  "Test file output with input variable on BODY with @startxxx ... @endxxx 
clauses."
+  (should
+   (string=
+    "@startuml
+!define CLASSNAME test_class
+class CLASSNAME
+@enduml"
+    (let ((org-plantuml-jar-path nil))
+      (org-test-with-temp-text
+         "#+name: variable_value
+: test_class
+
+#+header: :file tmp.puml
+#+header: :var CLASSNAME=variable_value
+#+begin_src plantuml
+@startuml
+class CLASSNAME
+@enduml
+#+end_src"
+        (org-babel-next-src-block)
+       (let ((src-block-info (cdr (org-babel-get-src-block-info))))
+         (org-babel-plantuml-make-body
+          (car src-block-info)
+          (car (cdr src-block-info)))))))))
 
 (ert-deftest test-ob-plantuml/prologue ()
   "Test file output with prologue."
-- 
2.51.0

Reply via email to