Tim Hansinger <[email protected]> writes:
> Hello Rudy,
Tim, hi!
> please find here the latest patch.
>
> I tried to implement the changes request. This one is now simplified.
The new patch is *much* simplified, to the point even I can read it. :)
Better and better!
> I think this is very clean. If you have anything to change please
> provide me with complete alternative code. I hope however this one
> works for you.
It works but is still tiny bit too complex. :)
Below, I include "complete alternative code" you asked for.
- It matches the regular language of the input body *exactly once*.
- It contains *exactly one* invocation of `org-babel-expand-body:...'.
- It contains *exactly one* invocation of `org-babel-variable-assignments:...'.
- It uses `rx' for readability, as I am trying to learn it. :)
Please test it thoroughly; I just tried it once. *ducks*
P.S. We could also extract a `defcustom' for those default "@startuml"
and "@enduml", e.g. `org-babel-plantuml-default-diagram-type' containing
the string "uml".
P.P.S. Great work, Tim!
(defun org-babel-plantuml-make-body (body params)
"..."
(let ((match (string-match
(rx (zero-or-more (or whitespace control))
(group (minimal-match (zero-or-more anything)))
line-start
(zero-or-more blank)
(group "@start" (group (one-or-more (any "a-zA-Z"))))
(zero-or-more blank)
line-end
(group (zero-or-more anything))
line-start
(zero-or-more blank)
(group "@end" (group (one-or-more (any "a-zA-Z"))))
(zero-or-more blank)
line-end
(group (minimal-match (zero-or-more anything)))
(zero-or-more (or whitespace control)))
body)))
(pcase-let ((`(,pre-body
,start-keyword
,start-keyword-type
,inner-body
,end-keyword
,end-keyword-type
,post-body)
(mapcar (lambda (group)
(if match (match-string group body)))
(number-sequence 1 7))))
(unless (string= start-keyword-type end-keyword-type)
(user-error "Incompatible PlantUML start/end keywords: %s, %s"
start-keyword end-keyword))
(string-join
(remove "" (list (or pre-body "")
(or start-keyword "@startuml")
(org-babel-expand-body:generic
(or inner-body body)
params
(org-babel-variable-assignments:plantuml params))
(or end-keyword "@enduml")
(or post-body "")))
"\n"))))
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č <[email protected]> [he/him]
http://adamkovic.org