From a3765aca3220cfbb71523f5839612fa8fdc6a181 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 23 Oct 2019 03:24:34 -0400 Subject: [PATCH] lang/plantuml: fix org-babel+plantuml executor --- modules/lang/plantuml/autoload.el | 65 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/modules/lang/plantuml/autoload.el b/modules/lang/plantuml/autoload.el index c42902891..7aaebaca9 100644 --- a/modules/lang/plantuml/autoload.el +++ b/modules/lang/plantuml/autoload.el @@ -5,25 +5,26 @@ "Execute a block of plantuml code with org-babel. This function is called by `org-babel-execute-src-block'." (require 'plantuml-mode) + ;; REVIEW Refactor me (let* ((body (replace-regexp-in-string "^[[:blank:]\n]*\\(@start\\)" "\\\\\\1" body)) - (out-file (or (cdr (assoc :file params)) - (concat doom-cache-dir - "ob-plantuml/" - (md5 str nil nil nil t) - ".png"))) + (fullbody (org-babel-plantuml-make-body body params)) + (out-file (or (cdr (assq :file params)) + (org-babel-temp-file "plantuml-" ".png"))) (in-file (org-babel-temp-file "plantuml-"))) (if (eq plantuml-default-exec-mode 'server) - (let* ((url-request-location )) - (with-current-buffer - (url-retrieve-synchronously (plantuml-server-encode-url body)) - (goto-char (point-min)) - ;; skip the HTTP headers - (while (not (looking-at "\n")) (forward-line)) - (kill-region (point-min) (+ 1 (point))) - (write-file (org-babel-process-file-name out-file)))) + (save-current-buffer + (save-match-data + (with-current-buffer + (url-retrieve-synchronously (plantuml-server-encode-url body) + nil t) + (goto-char (point-min)) + ;; skip the HTTP headers + (while (not (looking-at "\n")) (forward-line)) + (delete-region (point-min) (+ 1 (point))) + (write-file out-file)))) (let* ((cmd (concat (cond ((eq plantuml-default-exec-mode 'executable) (unless (executable-find plantuml-executable-path) (error "Could not find plantuml at %s" @@ -32,18 +33,28 @@ This function is called by `org-babel-execute-src-block'." " --headless ")) ((not (file-exists-p org-plantuml-jar-path)) (error "Could not find plantuml.jar at %s" org-plantuml-jar-path)) - ((concat "java " (or (cdr (assoc :java params)) "") " -jar " - (shell-quote-argument (expand-file-name plantuml-executable-path))))) - (concat (if (string= (file-name-extension out-file) "svg") - " -tsvg" "") - (if (string= (file-name-extension out-file) "eps") - " -teps" "") - " -p " (cdr (assoc :cmdline params)) " < " - (org-babel-process-file-name in-file) - " > " - (org-babel-process-file-name out-file))))) - (with-temp-file in-file - (insert (concat "@startuml\n" body "\n@enduml"))) + ((concat "java " (cdr (assoc :java params)) " -jar " + (shell-quote-argument + (expand-file-name plantuml-executable-path))))) + (pcase (file-name-extension out-file) + ("png" "-tpng") + ("svg" "-tsvg") + ("eps" "-teps") + ("pdf" "-tpdf") + ("tex" "-tlatex") + ("vdx" "-tvdx") + ("xmi" "-txmi") + ("scxml" "-tscxml") + ("html" "-thtml") + ("txt" "-ttxt") + ("utxt" "-utxt")) + " " + " -p " (cdr (assoc :cmdline params)) " < " + (org-babel-process-file-name in-file) + " > " + (org-babel-process-file-name out-file)))) + (with-temp-file in-file (insert fullbody)) (message "%s" cmd) - (org-babel-eval cmd "") - nil)))) ;; signal that output has already been written to file + (org-babel-eval cmd ""))) + (unless (cdr (assq :file params)) + out-file)))