blog/content/post/2011/01/24/2011-01-24-00001452.md

5.9 KiB

title author date url wordtwit_post_info categories
ditaa を Emacs から使えるようにしてみた kazu634 2011-01-24 /2011/01/24/_1656/
O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5411;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}
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