This commit is contained in:
ry
2022-01-11 18:05:13 -08:00
parent 2046befee2
commit 8e7b654716
846 changed files with 71287 additions and 4 deletions

View File

@@ -0,0 +1,63 @@
;;; lang/plantuml/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(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)
;; REVIEW Refactor me
(let* ((body (replace-regexp-in-string
"^[[:blank:]\n]*\\(@start\\)"
"\\\\\\1"
body))
(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)
(if (bound-and-true-p org-export-current-backend)
(user-error "Exporting plantuml diagrams in server mode is not supported (see `plantuml-default-exec-mode')")
(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"
(executable-find plantuml-executable-path)))
(concat (shell-quote-argument (executable-find plantuml-executable-path))
" --headless"))
((not (file-exists-p plantuml-jar-path))
(error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
((concat "java " (cdr (assoc :java params)) " -jar "
(shell-quote-argument
(expand-file-name plantuml-jar-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 "")))
(unless (cdr (assq :file params))
out-file)))

View File

@@ -0,0 +1,29 @@
;;; lang/plantuml/config.el -*- lexical-binding: t; -*-
(use-package! plantuml-mode
:commands plantuml-download-jar
:init
(setq plantuml-jar-path (concat doom-etc-dir "plantuml.jar")
org-plantuml-jar-path plantuml-jar-path)
:config
(set-popup-rule! "^\\*PLANTUML" :size 0.4 :select nil :ttl 0)
(setq plantuml-default-exec-mode
(cond ((file-exists-p plantuml-jar-path) 'jar)
((executable-find "plantuml") 'executable)
(plantuml-default-exec-mode))))
(use-package! flycheck-plantuml
:when (featurep! :checkers syntax)
:after plantuml-mode
:config (flycheck-plantuml-setup))
(after! ob-plantuml
;; HACK Force ob-plantuml to use `plantuml-mode''s building mechanism, which
;; is more sophisticated.
(advice-add #'org-babel-execute:plantuml
:override #'+plantuml-org-babel-execute:plantuml-a)
(add-to-list 'org-babel-default-header-args:plantuml
'(:cmdline . "-charset utf-8")))

View File

@@ -0,0 +1,10 @@
;; -*- lexical-binding: t; no-byte-compile: t; -*-
;;; lang/plantuml/doctor.el
(when (require 'plantuml-mode nil t)
;; java
(unless (executable-find "java")
(warn! "Couldn't find java. PlantUML preview or syntax checking won't work"))
;; plantuml.jar
(unless (file-exists-p plantuml-jar-path)
(warn! "Couldn't find plantuml.jar. Install it with M-x plantuml-download-jar")))

View File

@@ -0,0 +1,8 @@
;; -*- no-byte-compile: t; -*-
;;; lang/plantuml/packages.el
(package! plantuml-mode :pin "ea45a13707abd2a70df183f1aec6447197fc9ccc")
(when (featurep! :checkers syntax)
(package! flycheck-plantuml :pin "183be89e1dbba0b38237dd198dff600e0790309d"))
;; ob-plantuml is provided by org-plus-contrib