mgを使用したMewの全文検索 [Linux]
実施手順は、以下の通りである。
0. 制限事項
(1) カレントフォルダのみを検索対象とする。
(2) Mew 6.3 以降を対象とする。
下記の環境において、動作確認を行った。
・Mew 6.3 on CentOS 6.x, Mew 6.4 on Debian 7, Mew 6.6 on Debian 8
(補足)
Mew 5.2 では、想定通りの結果とはならなかった。
(3) Perl、nkf がインストールされていること。
1. mg (multi-line grep) のインストール
(1) ダウンロード
下記 URL から mg-2.26 をダウンロードする。
・ftp://ftp.sra.co.jp/pub/lang/perl/scripts/utashiro-scripts/
(2) カスタマイズ
(a) 1 行目を変更する。
(変更前) #!/usr/local/bin/perl (変更後) #!/usr/bin/perl
(b) 354 行目をコメント化する。
コメント化しない場合、下記のワーニングが出力される。 $* is no longer supported at /tmp/mg line 354.
(3) インストール
/usr/local/bin 等に mg というファイル名でインストールする。
また、実行できるようにパーミションを設定する。
2. Base64 エンコードされたメッセージへの対応
テキストメッセージと Base64 メッセージを同時に検索することはできない。
よって、nkf のオプションを変更する関数を作成し、これに対応する。
手順は、下記の通りである。
(1) mew-search-util.el のインストール
mew-search-util.el を load-path に設定されたディレクトリにコピーする。
(mew-search-util.el のソースコードは、備考を参照。)
(2) ~/.mew.el への設定の追加
;;(setq mew-search-mg-locale "ja_JP.UTF-8") ;; ja_JP.UTF-8 の場合に設定 (setq mew-prog-grep "mg") (require 'mew-search-util)
ja_JP.UTF-8 で機能しない場合には、コメント化する(ja_JP.eucJP が使用される)。
3. 使用方法
(1) 検索対象のフォルダに移動する。
(2) 必要に応じて、mg のフィルタコマンド(nkf) のオプションを変更する。
M-x mew-set-mg-opts
または M-? を押下する。
(3) 全文検索を実行する。
・/ または ? を押下する。
・検索条件を入力する。
詳細は、Mew のマニュアルを参照。
4. 備考
(1) mew-search-util.el
;;; -*- tab-width: 4 -*- ;;; mew-search-util.el --- utilities for full-text search ;; This is for Mew-6.3 or later. (require 'mew) (defvar mew-search-mg-locale "ja_JP.eucJP" "The name of locale used in full-text search using mg. Possible values are \"ja_JP.eucJP\" or \"ja_JP.UTF-8\".") ;; set the value of mew-prog-grep-opts (when (equal mew-prog-grep "mg") (let ((mime-opt "")) (cond ((equal mew-search-mg-locale "ja_JP.eucJP") (setq mime-opt "nkf -e")) ((equal mew-search-mg-locale "ja_JP.UTF-8") (setq mime-opt "nkf -w")) (t (setq mew-search-mg-locale "ja_JP.eucJP") (setq mime-opt "nkf -e"))) (setq mew-prog-grep-opts (list "-l" "-e" "-i" "-z" mime-opt "-x" "&mime")))) (defun mew-set-mg-opts () "Set nkf and its options as filter command of mg. If the value of mew-prog-grep is not \"mg\", do nothing. Otherwise, update the value of mew-prog-grep-opts." (interactive) (if (null (equal mew-prog-grep "mg")) (message "mew-prog-grep's value is not \"mg\"") (let ((mime-opt "") current-mB current-mQ case-sensitive current-case (opt-sav mew-prog-grep-opts)) (cond ((equal mew-search-mg-locale "ja_JP.eucJP") (setq mime-opt "nkf -e")) ((equal mew-search-mg-locale "ja_JP.UTF-8") (setq mime-opt "nkf -w")) (t (setq mew-search-mg-locale "ja_JP.eucJP") (setq mime-opt "nkf -e"))) ;; get case sensitive setting (when (member "-i" mew-prog-grep-opts) (setq current-case t)) ;; get filter command (if (member (concat mime-opt " -mB") mew-prog-grep-opts) (setq current-mB t) (when (member (concat mime-opt " -mQ") mew-prog-grep-opts) (setq current-mQ t))) ;; set case sensitive setting (when (y-or-n-p (message "Enable case sensitive (current: %s)? " current-case)) (setq case-sensitive t)) ;; set filter command (if (y-or-n-p (message "Decode MIME base64 stream (current: %s)? " current-mB)) (setq mime-opt (concat mime-opt " -mB")) (when (y-or-n-p (message "Decode MIME quoted stream (current: %s)? " current-mQ)) (setq mime-opt (concat mime-opt " -mQ")))) ;; update mew-prog-grep-opts (if case-sensitive (setq mew-prog-grep-opts (list "-l" "-e" "-i" "-z" mime-opt "-x" "&mime")) (setq mew-prog-grep-opts (list "-l" "-e" "-z" mime-opt "-x" "&mime"))) (if (equal mew-prog-grep-opts opt-sav) (message "same value is selected, so not updated") (message "mew-prog-grep-opts's value has been changed"))))) (define-key mew-summary-mode-map "\e?" 'mew-set-mg-opts) (provide 'mew-search-util) ;;; mew-search-util.el ends here
コメント 0