Download
(require 'compile)
(defvar mgrep-list
'(
("site" "C:/unix/Meadow2/1.99a6/site-lisp" "*.el" t)
))
(defvar mgrep-word-history nil)
(defvar mgrep-directory-history nil)
(defvar mgrep-find-command nil)
(defvar mgrep-find-grep-command nil)
(defvar mgrep-find-grep-command-last nil)
(defun mgrep-set-find-command ()
(setq grep-find-command
(cond ((eq grep-find-use-xargs 'gnu)
(setq mgrep-find-command
(format "%s . -name "
find-program))
(setq mgrep-find-grep-command
(format " -type f -print0 | xargs -0 -e %s"
grep-command))
(setq mgrep-find-grep-command-last nil)
)
(grep-find-use-xargs
(setq mgrep-find-command
(format "%s . -name "
find-program))
(setq mgrep-find-grep-command
(format " -type f -print | xargs %s"
grep-command))
(setq mgrep-find-grep-command-last nil))
(t
(setq mgrep-find-command
(format "%s . -name "
find-program))
(setq mgrep-find-grep-command
(format " -type f -exec %s"
grep-command null-device))
(setq mgrep-find-grep-command-last
(format " {} %s \\;"
null-device))))))
(defun mgrep (arg)
(interactive "p")
(unless grep-command
(grep-compute-defaults))
(unless grep-find-command
(grep-compute-defaults))
(unless mgrep-find-command
(mgrep-set-find-command))
(let (name regexp dir lst)
(setq name (completing-read
(concat
"mgrep directory "
(when (car mgrep-directory-history)
(format "(default %s)"
(car mgrep-directory-history)))
" : ")
mgrep-list
nil nil nil 'mgrep-directory-history
(if (car mgrep-directory-history)
(car mgrep-directory-history)
nil)
))
(if (assoc name mgrep-list)
()
(setq mgrep-directory-history (cdr mgrep-directory-history))
(error "Input correct name!"))
(setq dir (file-name-as-directory
(eval (nth 1 (assoc name mgrep-list)))))
(if (or (string= 'sub (nth 3 (assoc name mgrep-list)))
(string= 'subfind (nth 3 (assoc name mgrep-list))))
(progn
(setq lst (mapcar '(lambda (file)
(if (and (not (string-match "\\.+$" file))
(file-directory-p file))
(file-name-nondirectory file)))
(directory-files (eval (nth 1 (assoc name mgrep-list))) t)))
(setq lst (delq nil lst))
(setq dir (concat
(file-name-as-directory dir)
(completing-read
"mgrep sub directory : "
(mapcar 'list lst)
nil t)
"/"))
))
(if (or (string= 'dir (nth 3 (assoc name mgrep-list)))
(string= 'dirfind (nth 3 (assoc name mgrep-list))))
(progn
(setq dir (expand-file-name (read-file-name "Directory: ")))
(if (file-directory-p dir)
(setq dir (file-name-as-directory dir))
(setq dir (file-name-directory dir)))))
(setq regexp (read-from-minibuffer "mgrep word : "
nil nil nil
'mgrep-word-history
))
(let ((default-directory dir)
(null-device nil)
com)
(with-temp-buffer
(cond
((or (not (nth 3 (assoc name mgrep-list)))
(string= 'sub (nth 3 (assoc name mgrep-list)))
(string= 'dir (nth 3 (assoc name mgrep-list))))
(setq com (concat grep-command "\"" regexp "\" "
(nth 2 (assoc name mgrep-list))))
(grep com))
(t
(setq com
(concat
mgrep-find-command
(regexp-quote
(nth 2 (assoc name mgrep-list)))
mgrep-find-grep-command
"\"" regexp "\""
mgrep-find-grep-command-last))
(grep-find com)))
))))
(provide 'mgrep)