Personal tools
You are here: Home ブログ sugawara Stuff SD_Emacs 2009年6月の記事の追補情報
« December 2010 »
Su Mo Tu We Th Fr Sa
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Recent entries
jlineで日本語を使えるようにする。 sugawara 2009-12-10
五反田Emacsの資料 sugawara 2009-10-19
trac-ticket.el sugawara 2007-11-19
Emacs Lisp 勉強会(バッファとウィンドウ編) sugawara 2007-10-22
Categories
Emacs
勉強会
java
 
Document Actions

2009年6月の記事の追補情報

「locateとanythingを組み合わせる」のために必要なもの

まんま前回の記事を写すのはまだまずそうなので、簡単に。
  • find-utils の locate(mlocate ではダメ。updatedb でfindオプションが指定できない)
  • $HOME/locate.db に locate db を作るためのスクリプト
  • home以下、プロジェクト以下の locate db を扱うための elisp

$HOME/locate.db に locate db を作るためのスクリプト

こんな感じで
#!/bin/sh

PRUNES="
-name RCS
-o -name CVS
-o -name .svn
-o -name .hg
-o -name .git
-o -name classes
-o -path $HOME/tmp
"

updatedb.findutils \
    --findoptions="( -type d ( $PRUNES ) -prune ) -o -type f" \
    --localpaths=$HOME --output=$HOME/locate.db

home以下、プロジェクト以下の locate db を扱うための elisp

以下が必要
;; locate db のファイル名
(defvar locate-db-name "locate.db")
;; locate コマンド
(setq locate-command "/usr/bin/locate.findutils")

;; locate コマンドラインを作る為の共通関数
(defun locate-make-command-line (search-string dbpath &rest opts)
  (append
   ;; 大文字小文字を虫するように設定
   (list locate-command "-i")
   (when (and dbpath (file-exists-p dbpath))
     (list "-d" dbpath))
   opts
   (list search-string)))

;; home 以下のファイルを探す為の locate コマンドライン
(defun home-locate-make-command-line (search-string &optional &rest opts)
  (apply 'locate-make-command-line
         search-string
         ;; home 直下の locate.db を使うように指定
         (expand-file-name locate-db-name "~")
         opts))
;; 標準の locate で home 以下を探すように設定する。
(setq locate-make-command-line 'home-locate-make-command-line)

;; 指定したファイルを dir を起点に探す為の関数
(defun find-file-upward (name &optional dir)
  (setq dir (file-name-as-directory (or dir default-directory)))
  (cond
   ((string= dir (directory-file-name dir))
    nil)
   ((file-exists-p name)
    (expand-file-name name dir))
   (t
    (find-file-upward name (expand-file-name ".." dir)))))

;; プロジェクト毎の locate db を使った locate コマンドライン
(defun plocate-make-command-line (search-string &optional &rest opts)
  (apply 'locate-make-command-line
         search-string
         (find-file-upward locate-db-name)
         opts))

;; プロジェクト毎の locate db を使った locate コマンド
(defun plocate (search-string &optional arg)
  (interactive
   (list
    (locate-prompt-for-search-string)
    current-prefix-arg))
  (let ((locate-make-command-line 'plocate-make-command-line))
    (locate search-string nil arg)))

Copyright(C) 2001 - 2006 Ariel Networks, Inc. All rights reserved.