blog/content/post/2008/08/25/2008-08-25-00001009.md

168 lines
15 KiB
Markdown

---
title: Flymakeが便利
author: kazu634
date: 2008-08-25
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:4233;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- Emacs
---
<div class="section">
<p>
今までの懸念事項だったflymakeを導入してみた。色々な人が色々と書いているので、それを参考にする。
</p>
<h4>
共通の設定
</h4>
<pre class="syntax-highlight">
<span class="synComment">;; ===============================================</span>
<span class="synComment">;; === flymake (Emacs22から標準添付されている) ===</span>
<span class="synComment">;; ===============================================</span>
<span class="synSpecial">(</span><span class="synStatement">require</span> <span class="synSpecial">'</span><span class="synIdentifier">flymake</span><span class="synSpecial">)</span>
<span class="synComment">;; set-perl5lib</span>
<span class="synComment">;; 開いたスクリプトのパスに応じて、@INCにlibを追加してくれる</span>
<span class="synComment">;; 以下からダウンロードする必要あり</span>
<span class="synComment">;; http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el</span>
<span class="synSpecial">(</span><span class="synStatement">require</span> <span class="synSpecial">'</span><span class="synIdentifier">set-perl5lib</span><span class="synSpecial">)</span>
<span class="synComment">;; エラー、ウォーニング時のフェイス</span>
<span class="synSpecial">(</span>set-face-background <span class="synSpecial">'</span><span class="synIdentifier">flymake-errline</span> <span class="synConstant">&#34;red4&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>set-face-foreground <span class="synSpecial">'</span><span class="synIdentifier">flymake-errline</span> <span class="synConstant">&#34;black&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>set-face-background <span class="synSpecial">'</span><span class="synIdentifier">flymake-warnline</span> <span class="synConstant">&#34;yellow&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>set-face-foreground <span class="synSpecial">'</span><span class="synIdentifier">flymake-warnline</span> <span class="synConstant">&#34;black&#34;</span><span class="synSpecial">)</span>
<span class="synComment">;; エラーをミニバッファに表示</span>
<span class="synComment">;; http://d.hatena.ne.jp/xcezx/20080314/1205475020</span>
<span class="synSpecial">(</span><span class="synStatement">defun</span> flymake-display-err-minibuf <span class="synSpecial">()</span>
<span class="synConstant">&#34;Displays the error/warning for the current line in the minibuffer&#34;</span>
<span class="synSpecial">(</span>interactive<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">let*</span> <span class="synSpecial">((</span>line-no <span class="synSpecial">(</span>flymake-current-line-no<span class="synSpecial">))</span>
<span class="synSpecial">(</span>line-err-info-list <span class="synSpecial">(</span><span class="synStatement">nth</span> <span class="synConstant"></span> <span class="synSpecial">(</span>flymake-find-err-info flymake-err-info line-no<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">count</span> <span class="synSpecial">(</span><span class="synStatement">length</span> line-err-info-list<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>while <span class="synSpecial">(</span><span class="synStatement">&#62;</span> <span class="synStatement">count</span> <span class="synConstant"></span><span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">when</span> line-err-info-list
<span class="synSpecial">(</span><span class="synStatement">let*</span> <span class="synSpecial">((</span>file <span class="synSpecial">(</span>flymake-ler-file <span class="synSpecial">(</span><span class="synStatement">nth</span> <span class="synSpecial">(</span><span class="synStatement">1-</span> <span class="synStatement">count</span><span class="synSpecial">)</span> line-err-info-list<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>full-file <span class="synSpecial">(</span>flymake-ler-full-file <span class="synSpecial">(</span><span class="synStatement">nth</span> <span class="synSpecial">(</span><span class="synStatement">1-</span> <span class="synStatement">count</span><span class="synSpecial">)</span> line-err-info-list<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>text <span class="synSpecial">(</span>flymake-ler-text <span class="synSpecial">(</span><span class="synStatement">nth</span> <span class="synSpecial">(</span><span class="synStatement">1-</span> <span class="synStatement">count</span><span class="synSpecial">)</span> line-err-info-list<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>line <span class="synSpecial">(</span>flymake-ler-line <span class="synSpecial">(</span><span class="synStatement">nth</span> <span class="synSpecial">(</span><span class="synStatement">1-</span> <span class="synStatement">count</span><span class="synSpecial">)</span> line-err-info-list<span class="synSpecial">))))</span>
<span class="synSpecial">(</span>message <span class="synConstant">&#34;[%s] %s&#34;</span> line text<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> <span class="synStatement">count</span> <span class="synSpecial">(</span><span class="synStatement">1-</span> <span class="synStatement">count</span><span class="synSpecial">)))))</span>
</pre>
<h4>
C
</h4>
<p>
Cの設定はこんな感じ:
</p>
<pre class="syntax-highlight">
<span class="synComment">;; === Setting some C / C++ defaults ===</span>
<span class="synSpecial">(</span>add-hook <span class="synSpecial">'</span><span class="synIdentifier">c-mode-common-hook</span>
<span class="synSpecial">(</span><span class="synStatement">function</span> <span class="synSpecial">(</span><span class="synStatement">lambda</span> <span class="synSpecial">()</span>
<span class="synComment">;; more stuff here</span>
<span class="synSpecial">(</span>flymake-mode <span class="synStatement">t</span><span class="synSpecial">)</span>
<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>add-hook <span class="synSpecial">'</span><span class="synIdentifier">c-mode-common-hook</span>
<span class="synSpecial">'(</span><span class="synStatement">lambda</span> <span class="synSpecial">()</span>
<span class="synSpecial">(</span>define-key c-mode-map <span class="synConstant">&#34;\C-cd&#34;</span> 'flymake-display-err-menu-for-current-line<span class="synSpecial">)))</span>
</pre>
<p>
Cの場合、Makefileを一緒に書かなければいけない。とりあえずこんな風に書いておけば問題ないようだ。
</p>
<blockquote>
<p>
.PHONY: check-syntax
</p>
<p>
check-syntax:
</p>
<p>
$(CXX) -Wall -Wextra -pedantic -fsyntax-only $(CHK_SOURCES)
</p>
</blockquote>
<h4>
Perl
</h4>
<p>
Perlはこう:
</p>
<pre class="syntax-highlight">
<span class="synComment">;; === Perl用設定 ===</span>
<span class="synComment">;; http://unknownplace.org/memo/2007/12/21#e001</span>
<span class="synSpecial">(</span><span class="synStatement">defvar</span> flymake-perl-err-line-patterns
<span class="synSpecial">'((</span><span class="synConstant">&#34;\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]&#34;</span> 2 3 <span class="synStatement">nil</span> 1<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>defconst flymake-allowed-perl-file-name-masks
<span class="synSpecial">'((</span><span class="synConstant">&#34;\\.pl$&#34;</span> flymake-perl-init<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synConstant">&#34;\\.pm$&#34;</span> flymake-perl-init<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synConstant">&#34;\\.t$&#34;</span> flymake-perl-init<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">defun</span> flymake-perl-init <span class="synSpecial">()</span>
<span class="synSpecial">(</span><span class="synStatement">let*</span> <span class="synSpecial">((</span>temp-file <span class="synSpecial">(</span>flymake-init-create-temp-buffer-copy
<span class="synSpecial">'</span><span class="synIdentifier">flymake-create-temp-inplace</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>local-file <span class="synSpecial">(</span>file-relative-name
temp-file
<span class="synSpecial">(</span>file-name-directory buffer-file-name<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">list</span> <span class="synConstant">&#34;perl&#34;</span> <span class="synSpecial">(</span><span class="synStatement">list</span> <span class="synConstant">&#34;-wc&#34;</span> local-file<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">defun</span> flymake-perl-load <span class="synSpecial">()</span>
<span class="synSpecial">(</span>interactive<span class="synSpecial">)</span>
<span class="synSpecial">(</span>defadvice flymake-post-syntax-check <span class="synSpecial">(</span>before flymake-force-check-was-interrupted<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-check-was-interrupted <span class="synStatement">t</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>ad-activate <span class="synSpecial">'</span><span class="synIdentifier">flymake-post-syntax-check</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-allowed-file-name-masks <span class="synSpecial">(</span><span class="synStatement">append</span> flymake-allowed-file-name-masks flymake-allowed-perl-file-name-masks<span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-err-line-patterns flymake-perl-err-line-patterns<span class="synSpecial">)</span>
<span class="synSpecial">(</span>set-perl5lib<span class="synSpecial">)</span>
<span class="synSpecial">(</span>flymake-mode <span class="synStatement">t</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>add-hook <span class="synSpecial">'</span><span class="synIdentifier">cperl-mode-hook</span> <span class="synSpecial">'</span><span class="synIdentifier">flymake-perl-load</span><span class="synSpecial">)</span>
</pre>
<h4>
Gauche
</h4>
<p>
<a href="http://d.hatena.ne.jp/higepon/20080309/1205043148" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/higepon/20080309/1205043148', '小黒さんのSchemeにおける glint + Emacs + flymake を試してみた &#8211; ひげぽん OSとか作っちゃうかMona-');" target="_blank">小黒さんのSchemeにおける glint + Emacs + flymake を試してみた &#8211; ひげぽん OSとか作っちゃうかMona-</a>」を参考に。
</p>
<pre class="syntax-highlight">
<span class="synComment">;; === Gauche on Flymake ===</span>
<span class="synSpecial">(</span><span class="synStatement">defvar</span> flymake-glint-err-line-patterns <span class="synSpecial">'((</span><span class="synConstant">&#34;^\\(.+\\):\\([0-9]+\\): \\(.+\\)$&#34;</span> 1 2 <span class="synStatement">nil</span> 3<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>defconst flymake-allowed-gauche-file-name-masks <span class="synSpecial">'((</span><span class="synConstant">&#34;\\.scm$&#34;</span> flymake-gauche-init<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">defun</span> flymake-gauche-init <span class="synSpecial">()</span>
<span class="synSpecial">(</span><span class="synStatement">let*</span> <span class="synSpecial">((</span>temp-file <span class="synSpecial">(</span>flymake-init-create-temp-buffer-copy
<span class="synSpecial">'</span><span class="synIdentifier">flymake-create-temp-inplace</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>local-file <span class="synSpecial">(</span>file-relative-name
temp-file
<span class="synSpecial">(</span>file-name-directory buffer-file-name<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">list</span> <span class="synConstant">&#34;glint&#34;</span> <span class="synSpecial">(</span><span class="synStatement">list</span> local-file<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">defun</span> flymake-gauche-load <span class="synSpecial">()</span>
<span class="synSpecial">(</span>interactive<span class="synSpecial">)</span>
<span class="synSpecial">(</span>defadvice flymake-post-syntax-check <span class="synSpecial">(</span>before flymake-force-check-was-interrupted<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-check-was-interrupted <span class="synStatement">t</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>ad-activate <span class="synSpecial">'</span><span class="synIdentifier">flymake-post-syntax-check</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-allowed-file-name-masks <span class="synSpecial">(</span><span class="synStatement">append</span> flymake-allowed-file-name-masks
flymake-allowed-gauche-file-name-masks<span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">setq</span> flymake-err-line-patterns flymake-glint-err-line-patterns<span class="synSpecial">)</span>
<span class="synSpecial">(</span>flymake-mode <span class="synStatement">t</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span>add-hook <span class="synSpecial">'</span><span class="synIdentifier">scheme-mode-hook</span> <span class="synSpecial">'(</span><span class="synStatement">lambda</span> <span class="synSpecial">()</span>
<span class="synSpecial">(</span>flymake-gauche-load<span class="synSpecial">)</span>
<span class="synSpecial">(</span>define-key scheme-mode-map <span class="synConstant">&#34;\C-cd&#34;</span> 'credmp/flymake-display-err-minibuf<span class="synSpecial">)))</span>
</pre>
<h4>
感想
</h4>
<p>
これは果てしなく便利。
</p>
</div>