Prev / Next

2005-10-24 / rast-howm-grep

rast.el を書いてみた [2005-10-23-5] ので,ついでに
namazu-howm-grep をもとに rast-howm-grep を書いてみた
(howm の隠し機能で rast を使えるけど,検索だけ出来ればいいので).

rast-search には namazu の "-all" のようにファイル名を返すオプションが
ないので,rast-command は howm の ext/howm-rast-search.rb を使う.


(defun rast-howm-grep (&optional page-num rast-dir key)
  "rast + howm"
  (interactive
   (list
    0
    (if (or (and (not rast-always-query-index-directory) current-prefix-arg)
	    (and rast-always-query-index-directory (not current-prefix-arg)))
	(completing-read "Rast index directory: "
			 rast-dir-alist nil t nil 'rast-index-history)
      nil)
    (read-from-minibuffer
     "Enter Keyword: " nil
     rast-minibuffer-field-map nil 'rast-keyword-history)))
  (let* ((rast-filename-list nil)
	 (dir
	  (progn
	    (or
	     rast-default-dir
	     (setq rast-default-dir (rast-get-default-index-dir)))
	    (expand-file-name rast-default-dir)))
	 (arg-list (list key)))
    (if (and dir (not (string= dir "")) (string-match "[^ \t]" dir))
	(setq arg-list
	      (append
	       (rast-split-dir (rast-expand-dir-alias dir)) arg-list)))
    (message "Rast running ...")
    (let ((default-process-coding-system
	    (cons rast-cs-read rast-cs-write))
	  (process-input-coding-system rast-cs-read)
	  (process-output-coding-system rast-cs-write)
	  (coding-system-for-read rast-cs-read)
	  (coding-system-for-write rast-cs-write)
	  (rast-command "howm-rast-search.rb"))

      (with-temp-buffer
	(apply (function call-process)
	       rast-command nil t nil arg-list)

	(goto-char (point-min))
	(setq rast-filename-list
	      (split-string
	       (buffer-substring-no-properties
		(point-min) (point-max)) "\n"))))

    (message "Rast running ... done!")
    (setq rast-filename-list
	  (mapcar
	   '(lambda (file)
	      (if (string-match "^/\\([a-zA-Z]\\)|/\\(.+\\)$" file)
		  (concat (match-string 1 file)
			  ":/" (match-string 2 file))
		file))
	   rast-filename-list))
    (if (> (length rast-filename-list) rast-search-num)
	(setq rast-filename-list
	      (reverse
	       (nthcdr
		(- (length rast-filename-list) rast-search-num)
		(reverse rast-filename-list)))))

    (let ((moccur-split-word t)
           (regexp key)
           (ti0 (current-time)))
      (while (string-match " " regexp nil)
	(setq regexp (replace-match "\\\\|" nil nil regexp)))
      (let ((howm-view-grep-option "-Hn"))
	(howm-view-search regexp rast-filename-list))
      (howm-list-normalize regexp)
      )))


- namazu-howm-grep
- Rast: 全文検索システム

Referrer (Inside):
[2006-02-05-3] rast-howm-grep
[2005-11-03-3] howm の rast インデックス更新
comments powered by Disqus