[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why not a grep-find-simple?
From: |
Lennart Borgman |
Subject: |
Re: Why not a grep-find-simple? |
Date: |
Fri, 18 Aug 2006 19:05:31 +0200 |
User-agent: |
Thunderbird 1.5.0.5 (Windows/20060719) |
Lennart Borgman wrote:
I think it would be good to have a more easy to use version of
`grep-find' that asks for the most common parameters. I would suggest:
- Directory
- File name pattern
- Grep pattern
No answers yet so I supply a simple version for this:
(defvar grep-find-simple-filepatt-history nil)
(defvar grep-find-simple-grepregexp-history nil)
(defun grep-find-simple(top-dir file-pattern grep-regexp)
"Run grep via find, prompt for commonly used parameters.
This is a simplified interface to `grep-find'. It prompts for
some of the probably most commonly used parameters to that
command:
TOP-DIR is root directory for search.
FILE-PATTERN tells that only file with matching names should be
searched.
GREP-REGEXP is a grep style regular expression that grep should
search for.
FILE-PATTERN and GREP-REGEXP has their own history lists."
(interactive
(list
(read-directory-name "Root directory for search: " nil nil t)
(read-from-minibuffer "File name pattern: "
nil nil nil
'grep-find-simple-filepatt-history)
(read-from-minibuffer "Grep regexp: "
nil nil nil
'grep-find-simple-grepregexp-history)))
(grep-compute-defaults)
(if (not (string-match "-type f " grep-find-command))
(error "Can't find '-type f' in grep-find-command")
(let* ((begin (match-beginning 0))
(end (match-end 0))
(default-directory (file-name-as-directory top-dir))
(grep-find-command
(if (string= "" file-pattern)
(concat grep-find-command grep-regexp)
(concat (substring grep-find-command 0 begin)
"-type f -name '" file-pattern "' "
(substring grep-find-command end)
grep-regexp))))
(if (string= "" grep-regexp)
(message "No grep regexp to search for")
(call-interactively 'grep-find)))))