98 lines
5.9 KiB
Markdown
98 lines
5.9 KiB
Markdown
---
|
|
title: ditaa を Emacs から使えるようにしてみた
|
|
author: kazu634
|
|
date: 2011-01-24
|
|
url: /2011/01/24/_1656/
|
|
wordtwit_post_info:
|
|
- '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";}}'
|
|
categories:
|
|
- Emacs
|
|
|
|
---
|
|
<div class="section">
|
|
<p>
|
|
とりあえずこんな感じで関数を定義してみた。リージョンを選択した状態で使います:
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">;; /* _\|/_</span>
|
|
<span class="synComment">;; (o o)</span>
|
|
<span class="synComment">;; +----oOO-{_}-OOo--------------+</span>
|
|
<span class="synComment">;; |Making a diagram, using ditaa|</span>
|
|
<span class="synComment">;; +----------------------------*/</span>
|
|
<span class="synComment">;; ----------------------------------------------------</span>
|
|
<span class="synComment">;; Process of generating the diagram</span>
|
|
<span class="synComment">;; +------------------+ +-----------------+</span>
|
|
<span class="synComment">;; |{io} | |{d} |</span>
|
|
<span class="synComment">;; |cYEL | |cRED |</span>
|
|
<span class="synComment">;; |Disgram pattern | |Generated Diagram|</span>
|
|
<span class="synComment">;; |in an Emacs buffer| +-----------------+</span>
|
|
<span class="synComment">;; +------------------+ ^</span>
|
|
<span class="synComment">;; | |</span>
|
|
<span class="synComment">;; | |</span>
|
|
<span class="synComment">;; V |</span>
|
|
<span class="synComment">;; +----------------+ +-------------+</span>
|
|
<span class="synComment">;; |{s} | | |</span>
|
|
<span class="synComment">;; |cGRE | |cBLU |</span>
|
|
<span class="synComment">;; |Diagram pattern |------>|Execute ditaa|</span>
|
|
<span class="synComment">;; |as a file | | |</span>
|
|
<span class="synComment">;; +----------------+ +-------------+</span>
|
|
<span class="synComment">;; ----------------------------------------------------</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">defun</span> make-diagram <span class="synSpecial">(</span>beg end<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>interactive <span class="synConstant">"r"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">let</span> <span class="synSpecial">((</span>temp-file <span class="synSpecial">(</span>make-temp-file <span class="synConstant">"diagram"</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>cur-buf <span class="synSpecial">(</span>current-buffer<span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>temp-diagram-png
|
|
<span class="synSpecial">(</span>concat
|
|
<span class="synSpecial">(</span>make-temp-name <span class="synConstant">"/Volumes/MacHDD/kazu634/junk/image/"</span><span class="synSpecial">)</span>
|
|
<span class="synConstant">".png"</span><span class="synSpecial">)))</span>
|
|
<span class="synSpecial">(</span>copy-region-as-kill beg end<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>get-buffer-create <span class="synConstant">"*diagram*"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>set-buffer <span class="synConstant">"*diagram*"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>yank<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>write-file temp-file<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>set-buffer cur-buf<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>shell-command <span class="synSpecial">(</span><span class="synStatement">format</span> <span class="synConstant">"java -jar /Volumes/MacHDD/kazu634/bin/ditaa0_9.jar -r %s %s"</span> temp-file temp-diagram-png<span class="synSpecial">)</span>
|
|
<span class="synStatement">nil</span>
|
|
<span class="synStatement">nil</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>message <span class="synConstant">"Successfully generate a diagram file."</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">delete-file</span> temp-file<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>insert temp-diagram-png<span class="synSpecial">)))</span>
|
|
</pre>
|
|
|
|
<h4>
|
|
作成されるダイアグラム
|
|
</h4>
|
|
|
|
<p>
|
|
これを画像にしてみます:
|
|
</p>
|
|
|
|
<pre>
|
|
----------------------------------------------------
|
|
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 |
|
|
+----------------+ +-------------+
|
|
----------------------------------------------------
|
|
</pre>
|
|
|
|
<p>
|
|
生成される画像:
|
|
</p>
|
|
|
|
<p>
|
|
<a href="http://f.hatena.ne.jp/sirocco634/20110124230203" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://f.hatena.ne.jp/sirocco634/20110124230203', '');" class="hatena-fotolife" target="_blank"><img src="http://cdn-ak.f.st-hatena.com/images/fotolife/s/sirocco634/20110124/20110124230203.png" alt="f:id:sirocco634:20110124230203p:image" title="f:id:sirocco634:20110124230203p:image" class="hatena-fotolife" /></a>
|
|
</p>
|
|
</div> |