ditaa を Emacs から使えるようにしてみた

Jan 24, 2011   #Emacs  :

とりあえずこんな感じで関数を定義してみた。リージョンを選択した状態で使います:

;; /*       _\|/_
;;          (o o)
;;  +----oOO-{_}-OOo--------------+
;;  |Making a diagram, using ditaa|
;;  +----------------------------*/
;; ----------------------------------------------------
;; Process of generating the diagram
;;     +------------------+     +-----------------+
;;     |{io}              |     |{d}              |
;;     |cYEL              |     |cRED             |
;;     |Disgram pattern   |     |Generated Diagram|
;;     |in an Emacs buffer|     +-----------------+
;;     +------------------+           ^
;;              |                     |
;;              |                     |
;;              V                     |
;;     +----------------+       +-------------+
;;     |{s}             |       |             |
;;     |cGRE            |       |cBLU         |
;;     |Diagram pattern |------>|Execute ditaa|
;;     |as a file       |       |             |
;;     +----------------+       +-------------+
;; ----------------------------------------------------
(defun make-diagram (beg end)
(interactive "r")
(let ((temp-file (make-temp-file "diagram"))
(cur-buf (current-buffer))
(temp-diagram-png
(concat
(make-temp-name "/Volumes/MacHDD/kazu634/junk/image/")
".png")))
(copy-region-as-kill beg end)
(get-buffer-create "*diagram*")
(set-buffer "*diagram*")
(yank)
(write-file temp-file)
(set-buffer cur-buf)
(shell-command (format "java -jar /Volumes/MacHDD/kazu634/bin/ditaa0_9.jar -r %s %s" temp-file temp-diagram-png)
nil
nil)
(message "Successfully generate a diagram file.")
(delete-file temp-file)
(insert temp-diagram-png)))

作成されるダイアグラム

これを画像にしてみます:

----------------------------------------------------
Process of generating the diagram
+------------------+     +-----------------+
|{io}cYEL          |     |{d} cRED         |
|Disgram pattern   |     |Generated Diagram|
|in an Emacs buffer|     +-----------------+
+------------------+           ^
|                     |
|                     |
V                     |
+----------------+       +-------------+
|{s}             |       |             |
|Diagram pattern |------>|Execute ditaa|
|as a file       |       |             |
|cGRE            |       |cBLU         |
+----------------+       +-------------+
----------------------------------------------------

生成される画像:

f:id:sirocco634:20110124230203p:image