perlbrew.elとProject::Libsを使ったflymakeの設定 - delirious thoughts
の通りに flymakeを設定したんですが、トップディレクトリが
@INCにないので 'use t::Util;'みたいなのを書くとエラーとして
指摘されていました。Project::Libsに pull requestを送ると
いうことも考えたんですが、t::Utilが一般的かどうかがわからない
ので、自分で '-I'オプションを追加することで対応しました。
コード
個人的には Perlプロジェクト = git管理下なので、git管理下であれば
トップディレクトリを追加という形にしています。Makefile.PLか Build.PLが
あればトップディレクトリという方が正確かもしれないですが。
追記 flymakeが機能しない問題があったので修正
(defun flymake-perl-add-topdir-option ()
(let ((curdir (directory-file-name (file-name-directory (buffer-file-name)))))
(with-temp-buffer
(let ((ret (call-process-shell-command "git rev-parse --show-toplevel" nil t)))
(cond ((zerop ret)
(goto-char (point-min))
(let ((topdir (buffer-substring-no-properties (point) (line-end-position))))
(unless (string= topdir curdir)
(format "-I%s" topdir))))
(t nil))))))
(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)))
(topdir (flymake-perl-add-topdir-option)))
(if topdir
`("perl" ,(list "-MProject::Libs" topdir "-wc" local-file))
`("perl" ,(list "-MProject::Libs" "-wc" local-file)))))
これでとりあえず問題は回避できました。