昨晚跟群友 SteamedFish 交流 plantuml,发现在 org-mode 里的 src-block 代码块中写 plantuml 代码时,不能写上“@”开头的语句,否则必报错。必须在“@”前面加上“\”或“,”才可以。后来经过多次尝试,发现在开头的@start 前面加上“\”就可以。于是想到写个 defadvice 处理一下。另外把 SteamedFish 兄弟写的自动加上“:cmdline -charset utf-8”的方法也加了进来。另外在我的 doom-emacs 里 exec-mode 只能设置为`executable`,否则 C-c C-c 时报错,不知为啥。(**10 月 26 日更新** doom 修复了此问题,现在不用设置为`executable`也可以了)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| ;; Change plantuml exec mode to `executable', other mode execute error.
(setq plantuml-default-exec-mode 'executable)
;; Add `:cmdline -charset utf-8' to org-src-block:plantuml
;; Fix `@start' prefix execute error
(use-package! ob-plantuml
:when (featurep! :lang plantuml)
:after plantuml-mode
:init
(defadvice! +fixstart--org-babel-plantuml-make-body (args)
:filter-args #'org-babel-execute:plantuml
(cl-destructuring-bind (body params) args
(let* ((origin-body body)
(fix-body
(replace-regexp-in-string
"^\\w*\\(@start\\)"
"\\\\\\1"
origin-body)))
(list fix-body params))))
:config
(add-to-list 'org-babel-default-header-args:plantuml
'(:cmdline . "-charset utf-8")))
|
**9 月 8 日更新** 已把此代码向 doom-emacs 提交 PR 并收录,根据 Henrik 的编码规范建议改为如下形式:
1
2
3
4
5
6
7
8
9
10
11
12
13
| (after! ob-plantuml
(defadvice! +plantuml--fix-atstart-in-org-src-blocks-a (args)
: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
'(:cmdline . "-charset utf-8")))
|