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

15 KiB
Raw Blame History

title author date url wordtwit_post_info categories
Flymakeが便利 kazu634 2008-08-25 /2008/08/25/_1085/
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";}}
Emacs

今までの懸念事項だったflymakeを導入してみた。色々な人が色々と書いているので、それを参考にする。

共通の設定

;; ===============================================
;; === flymake (Emacs22から標準添付されている) ===
;; ===============================================
(require 'flymake)
;; set-perl5lib
;; 開いたスクリプトのパスに応じて、@INCにlibを追加してくれる
;; 以下からダウンロードする必要あり
;; http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el
(require 'set-perl5lib)
;; エラー、ウォーニング時のフェイス
(set-face-background 'flymake-errline "red4")
(set-face-foreground 'flymake-errline "black")
(set-face-background 'flymake-warnline "yellow")
(set-face-foreground 'flymake-warnline "black")
;; エラーをミニバッファに表示
;; http://d.hatena.ne.jp/xcezx/20080314/1205475020
(defun flymake-display-err-minibuf ()
"Displays the error/warning for the current line in the minibuffer"
(interactive)
(let* ((line-no             (flymake-current-line-no))
(line-err-info-list  (nth  (flymake-find-err-info flymake-err-info line-no)))
(count               (length line-err-info-list)))
(while (> count )
(when line-err-info-list
(let* ((file       (flymake-ler-file (nth (1- count) line-err-info-list)))
(full-file  (flymake-ler-full-file (nth (1- count) line-err-info-list)))
(text (flymake-ler-text (nth (1- count) line-err-info-list)))
(line       (flymake-ler-line (nth (1- count) line-err-info-list))))
(message "[%s] %s" line text)))
(setq count (1- count)))))

C

Cの設定はこんな感じ:

;; === Setting some C / C++ defaults ===
(add-hook 'c-mode-common-hook
(function (lambda ()
;; more stuff here
(flymake-mode t)
)))
(add-hook 'c-mode-common-hook
'(lambda ()
(define-key c-mode-map "\C-cd" 'flymake-display-err-menu-for-current-line)))

Cの場合、Makefileを一緒に書かなければいけない。とりあえずこんな風に書いておけば問題ないようだ。

.PHONY: check-syntax

check-syntax:

$(CXX) -Wall -Wextra -pedantic -fsyntax-only $(CHK_SOURCES)

Perl

Perlはこう:

;; === Perl用設定 ===
;; http://unknownplace.org/memo/2007/12/21#e001
(defvar flymake-perl-err-line-patterns
'(("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 2 3 nil 1)))
(defconst flymake-allowed-perl-file-name-masks
'(("\\.pl$" flymake-perl-init)
("\\.pm$" flymake-perl-init)
("\\.t$" flymake-perl-init)))
(defun flymake-perl-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "perl" (list "-wc" local-file))))
(defun flymake-perl-load ()
(interactive)
(defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted)
(setq flymake-check-was-interrupted t))
(ad-activate 'flymake-post-syntax-check)
(setq flymake-allowed-file-name-masks (append flymake-allowed-file-name-masks flymake-allowed-perl-file-name-masks))
(setq flymake-err-line-patterns flymake-perl-err-line-patterns)
(set-perl5lib)
(flymake-mode t))
(add-hook 'cperl-mode-hook 'flymake-perl-load)

Gauche

小黒さんのSchemeにおける glint + Emacs + flymake を試してみた ひげぽん OSとか作っちゃうかMona-」を参考に。

;; === Gauche on Flymake ===
(defvar flymake-glint-err-line-patterns '(("^\\(.+\\):\\([0-9]+\\): \\(.+\\)$" 1 2 nil 3)))
(defconst flymake-allowed-gauche-file-name-masks '(("\\.scm$" flymake-gauche-init)))
(defun flymake-gauche-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "glint" (list local-file))))
(defun flymake-gauche-load ()
(interactive)
(defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted)
(setq flymake-check-was-interrupted t))
(ad-activate 'flymake-post-syntax-check)
(setq flymake-allowed-file-name-masks (append flymake-allowed-file-name-masks
flymake-allowed-gauche-file-name-masks))
(setq flymake-err-line-patterns flymake-glint-err-line-patterns)
(flymake-mode t))
(add-hook 'scheme-mode-hook '(lambda ()
(flymake-gauche-load)
(define-key scheme-mode-map "\C-cd" 'credmp/flymake-display-err-minibuf)))

感想

これは果てしなく便利。