Hello Rudy,

I created 2 new patch files (this time using git diff).

One for the actual patch, the second one for adding an additional test.

Please ignore the previous patch file I sent.

Best
Tim

On 13 Sep 2025, at 18:51, Tim Hansinger wrote:

> Hello Rudy,
>
> thank you very much for verifying the issue.
>
> I am very new to this so I hope this is what you mean.
> I created a patch using the patch command for ob-plantuml.el (attached – I 
> guess I could have done the same directly in emacs as well). Could you have a 
> quick look at it?
>
> I haven't written a test yet in/for Emacs. I will try to learn this next. But 
> for now I don't have a test ready.
>
> Best
> Tim
>
> On 13 Sep 2025, at 16:52, Rudolf Adamkovič wrote:
>
>> "Dr. Arne Babenhauserheide" [email protected] writes:
>>
>>> #+begin_src plantuml :var replace_me="this is variable content" :file 
>>> /tmp/filei.png
>>> @startuml
>>> "replace_me"
>>> @enduml
>>> #+end_src
>>
>> Like the OP, I too am on MacOS (15.5). Further, I am running fresh Org
>> from main' (69b891b59) and fresh Emacs from master' (307405a72c4). I
>> get "replace_me" in the output, instead of "this is variable content".
>> I can also confirm that the suggested code changes fix the problem.
>>
>> Tim, could you perhaps resubmit your code as a Git patch, ideally with
>> at least one test, so that we do not chase our tail next time?
>>
>> Rudy
>>
>> "I do not fear death. I had been dead for billions and billions of years
>> before I was born, and had not suffered the slightest inconvenience from it."
>> --- Mark Twain, paraphrased
>>
>> Rudolf Adamkovič [email protected] [he/him]
>> http://adamkovic.org
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."

Reply via email to