lang/plantuml: force ob-plantuml to build w/ plantuml-mode
It is more sophisticated and robust.
This commit is contained in:
parent
fa9001aacb
commit
0b1f3567a3
2 changed files with 57 additions and 23 deletions
|
@ -1,10 +1,49 @@
|
||||||
;;; lang/plantuml/autoload.el -*- lexical-binding: t; -*-
|
;;; lang/plantuml/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +plantuml/install ()
|
(defun +plantuml-org-babel-execute:plantuml-a (body params)
|
||||||
"Install plantuml.jar."
|
"Execute a block of plantuml code with org-babel.
|
||||||
(interactive)
|
This function is called by `org-babel-execute-src-block'."
|
||||||
(if (file-exists-p plantuml-jar-path)
|
(require 'plantuml-mode)
|
||||||
(user-error "plantuml.jar already installed")
|
(let* ((body (replace-regexp-in-string
|
||||||
(url-copy-file "https://downloads.sourceforge.net/project/plantuml/plantuml.jar"
|
"^[[:blank:]\n]*\\(@start\\)"
|
||||||
plantuml-jar-path)))
|
"\\\\\\1"
|
||||||
|
body))
|
||||||
|
(out-file (or (cdr (assoc :file params))
|
||||||
|
(concat doom-cache-dir
|
||||||
|
"ob-plantuml/"
|
||||||
|
(md5 str nil nil nil t)
|
||||||
|
".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))))
|
||||||
|
(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))
|
||||||
|
" --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")))
|
||||||
|
(message "%s" cmd)
|
||||||
|
(org-babel-eval cmd "")
|
||||||
|
nil)))) ;; signal that output has already been written to file
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
;;; lang/plantuml/config.el -*- lexical-binding: t; -*-
|
;;; lang/plantuml/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(use-package! plantuml-mode
|
(use-package! plantuml-mode
|
||||||
:defer t
|
:commands plantuml-download-jar
|
||||||
:init
|
:init
|
||||||
(setq plantuml-jar-path (concat doom-etc-dir "plantuml.jar")
|
(setq plantuml-jar-path (concat doom-etc-dir "plantuml.jar")
|
||||||
org-plantuml-jar-path plantuml-jar-path)
|
org-plantuml-jar-path plantuml-jar-path)
|
||||||
:config
|
:config
|
||||||
(set-popup-rule! "^\\*PLANTUML" :size 0.4 :select nil :ttl 0))
|
(set-popup-rule! "^\\*PLANTUML" :size 0.4 :select nil :ttl 0)
|
||||||
|
|
||||||
|
(setq plantuml-default-exec-mode
|
||||||
|
(cond ((executable-find "plantuml") 'executable)
|
||||||
|
((file-exists-p plantuml-jar-path) 'jar)
|
||||||
|
(plantuml-default-exec-mode))))
|
||||||
|
|
||||||
|
|
||||||
(use-package! flycheck-plantuml
|
(use-package! flycheck-plantuml
|
||||||
|
@ -16,19 +21,9 @@
|
||||||
|
|
||||||
|
|
||||||
(after! ob-plantuml
|
(after! ob-plantuml
|
||||||
(defadvice! +plantuml--fix-atstart-in-org-src-blocks-a (args)
|
;; HACK We force ob-plantuml to use `plantuml-mode''s building mechanism,
|
||||||
"Fix error when executing plantuml src blocks in org-mode for code that
|
;; which is more sophisticated.
|
||||||
begins with '@'. This character needs to be escaped with a backslash or comma
|
(advice-add #'org-babel-execute:plantuml
|
||||||
for the block to execute correctly, so we do it automatically."
|
:override #'+plantuml-org-babel-execute:plantuml-a)
|
||||||
:filter-args #'org-babel-execute:plantuml
|
|
||||||
(cl-destructuring-bind (body params) args
|
|
||||||
(let* ((origin-body body)
|
|
||||||
(fix-body
|
|
||||||
(replace-regexp-in-string
|
|
||||||
"^[[:blank:]\n]*\\(@start\\)"
|
|
||||||
"\\\\\\1"
|
|
||||||
origin-body)))
|
|
||||||
(list fix-body params))))
|
|
||||||
|
|
||||||
(add-to-list 'org-babel-default-header-args:plantuml
|
(add-to-list 'org-babel-default-header-args:plantuml
|
||||||
'(:cmdline . "-charset utf-8")))
|
'(:cmdline . "-charset utf-8")))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue