2017-07-08 23:05:23 +02:00
|
|
|
;;; lang/plantuml/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-10-22 18:50:33 -04:00
|
|
|
(defun +plantuml-org-babel-execute:plantuml-a (body params)
|
|
|
|
"Execute a block of plantuml code with org-babel.
|
|
|
|
This function is called by `org-babel-execute-src-block'."
|
|
|
|
(require 'plantuml-mode)
|
2019-10-23 03:24:34 -04:00
|
|
|
;; REVIEW Refactor me
|
2019-10-22 18:50:33 -04:00
|
|
|
(let* ((body (replace-regexp-in-string
|
|
|
|
"^[[:blank:]\n]*\\(@start\\)"
|
|
|
|
"\\\\\\1"
|
|
|
|
body))
|
2019-10-23 03:24:34 -04:00
|
|
|
(fullbody (org-babel-plantuml-make-body body params))
|
|
|
|
(out-file (or (cdr (assq :file params))
|
|
|
|
(org-babel-temp-file "plantuml-" ".png")))
|
2019-10-22 18:50:33 -04:00
|
|
|
(in-file (org-babel-temp-file "plantuml-")))
|
|
|
|
(if (eq plantuml-default-exec-mode 'server)
|
2019-10-23 03:24:34 -04:00
|
|
|
(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))))
|
2019-10-22 18:50:33 -04:00
|
|
|
(let* ((cmd (concat (cond ((eq plantuml-default-exec-mode 'executable)
|
|
|
|
(unless (executable-find plantuml-executable-path)
|
|
|
|
(error "Could not find plantuml at %s"
|
|
|
|
(executable-find plantuml-executable-path)))
|
|
|
|
(concat (shell-quote-argument (executable-find plantuml-executable-path))
|
2019-10-23 13:04:25 -04:00
|
|
|
" --headless"))
|
|
|
|
((not (file-exists-p plantuml-jar-path))
|
2019-10-22 18:50:33 -04:00
|
|
|
(error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
|
2019-10-23 03:24:34 -04:00
|
|
|
((concat "java " (cdr (assoc :java params)) " -jar "
|
|
|
|
(shell-quote-argument
|
2019-10-23 13:04:25 -04:00
|
|
|
(expand-file-name plantuml-jar-path)))))
|
|
|
|
" "
|
2019-10-23 03:24:34 -04:00
|
|
|
(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))
|
2019-10-22 18:50:33 -04:00
|
|
|
(message "%s" cmd)
|
2019-10-23 03:24:34 -04:00
|
|
|
(org-babel-eval cmd "")))
|
|
|
|
(unless (cdr (assq :file params))
|
|
|
|
out-file)))
|