#plantuml #org uml도 emacs로

1 minute read

nil

plantuml 문법으로 uml을 작성하고 C-c C-c 키를 누르면 짠~

sequence diagram을 그릴 일이 생겼는데, 마우스에 손대기 싫다. 그냥 손으로 그리고 사진으로 찍어서 올릴까? 아님 부기 보드로? 이거 emacs에 있지 않을까? 역시나 있다. 아니 없었으면 놀랐지 싶다.

좀 더 정확히 말하자면 org-bable에서 platuml integration을 지원한다.

;;; image
(setq org-startup-with-inline-images t)

;;; plantuml
(org-babel-do-load-languages
 'org-babel-load-languages
 '((plantuml . t)))
(setq org-confirm-babel-evaluate nil)
(setq org-plantuml-jar-path
      (expand-file-name "~/bin/plantuml.jar"))
(add-hook 'org-babel-after-execute-hook
          (lambda ()
            (when org-inline-image-overlays
              (org-redisplay-inline-images))))
(add-to-list 'org-structure-template-alist
             '("u" "#+BEGIN_SRC plantuml :file ?.png
                    \nskinparam monochrome true
                    \n#+END_SRC"))

org-babel-after-execute-hook

Replace PlantUML source with generated image in org-mode 답변을 보고 org-babel-after-execute-hook 훅에 이미지를 다시 그리는 함수를 추가했다. 변경하고 C-c C-c 키를 누르면 바로 갱신한다.

org-structure-template-alist

<s <TAB> 키를 누르면 SRC 블럭을 만들어 준다. 매번 plantuml :file tryout.png를 추가해야 하는데, 이거 귀찮네. templates에 추가하자. 마침 u 키가 비어있다. 여기에 할당하면 되겠다.

(require 'cl)
(remove-if-not #'(lambda (x) (string= (car x) "s")) org-structure-template-alist)

;;=> (("s" "#+BEGIN_SRC ? #+END_SRC" "<src lang=\"?\"> </src>"))

소스 블럭이랑 비슷하니 참고해서 만들었다. ? 문자는 template을 넣은 후 커서 위치를 가리킨다.

graphviz

sequence diagram은 graphviz가 없어도 잘 나온다. class diagram 같은 걸 그리려면 필요.

windows에서 이미지 지원을 사용하려면?

Update <2018-09-01 Sat> gnu emacs 26 이상이면 따로 설치 안 해도 이미지 지원을 사용할 수 있다.

칫! 뭐든지 windows는 한 방에 안 된다. org-mode에서 이미지가 안 보여 찾아보니 이미지 지원을 받으려면 뭔가 추가해야 한다.

(image-type-available-p 'png)
;;=> nil

이미지 지원이 꺼져있는 거 맞다.

Image support

Emacs has built in support for XBM and PPM/PGM/PBM images, and the libXpm library is bundled, providing XPM support (required for color toolbar icons and splash screen). Source for libXpm should be available from the same place from which you got this binary distribution.

Emacs can also support some other image formats with appropriate libraries. These libraries are all available on the following sites:

1 http://sourceforge.net/projects/ezwinports/files/ – leaner, more up-to-date builds, only for 32-bit Emacs

2 http://www.gtk.org/download/win32.php http://www.gtk.org/download/win64.php – the GTK project site; offers much fatter builds, but includes 64-bit DLLs (from the 2nd URL)

3 GnuWin32 project – very old builds, not recommended

https://ftp.gnu.org/gnu/emacs/windows/README

ezwinports에서 libpng를 다운로드. dll 파일을 emacs 실행 파일이 있는 디렉터리에 복사하면 된다.

(image-type-available-p 'png)
;;=> t

이제 png가 org 버퍼 안에서 잘 보인다.

C-x C-s C-x C-c