annotate lisp/dired/find-dired.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 ;;; find-dired.el --- run a `find' command and dired the output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 ;; Keywords: unix
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 ;; any later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 ;; General Public License for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.30.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28 ;;; Commentary:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 ;; To bind the following functionality to a key, put, e.g.:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 ;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32 ;; (global-set-key "\C-cf" 'find-dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 ;; (global-set-key "\C-cn" 'find-name-dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 ;; (global-set-key "\C-cl" 'find-grep-dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35 ;;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 ;; in your ~/.emacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 ;;; Code:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 (require 'dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 ;; find's -ls corresponds to these switches.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 ;; Note -b, at least GNU find quotes spaces etc. in filenames
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 (defvar find-ls-option (purecopy
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46 ;; XEmacs: add purecopy
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 (if (eq system-type 'berkeley-unix) '("-ls" . "-gilsb")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 '("-exec ls -ld {} \\;" . "-ld")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 "*Description of the option to `find' to produce an `ls -l'-type listing.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 This is a cons of two strings (FIND-OPTION . LS-SWITCHES). FIND-OPTION
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 gives the option (or options) to `find' that produce the desired output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 LS-SWITCHES is a list of `ls' switches to tell dired how to parse the output.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 (defvar find-grep-options (purecopy
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 ;; XEmacs: add purecopy
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 (if (eq system-type 'berkeley-unix) "-s" "-q"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58 "*Option to grep to be as silent as possible.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 On Berkeley systems, this is `-s'; on Posix, and with GNU grep, `-q' does it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 On other systems, the closest you can come is to use `-l'.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 ;; XEmacs additions: next two variables.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 (defvar find-dired-multiple-buffers nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 "*If non-nil, generates a new buffer for each find")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 (defvar find-dired-dir-history nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 "History of directories used by find-dired")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 (defvar find-args nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 "Last arguments given to `find' by \\[find-dired].")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74 (defvar find-args-history nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 "Last arguments given to `find' by \\[find-dired].")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 ;; XEmacs: various changes in next function.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 (defun find-dired (dir args)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 "Run `find' and go into dired-mode on a buffer of the output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 The command run (after changing into DIR) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 find . \\( ARGS \\) -ls"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 (interactive (list (read-file-name "Run find in directory: "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 nil "" t nil 'find-dired-dir-history)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87 (if (featurep 'gmhist)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 (read-with-history-in 'find-args-history
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 "Run find (with args): ")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 (read-string "Run find (with args): "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91 (or (and (fboundp 'symbol-near-point)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 (symbol-near-point))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 (car find-args-history))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 'find-args-history))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 ;; Expand DIR ("" means default-directory), and make sure it has a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 ;; trailing slash.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 (setq dir (file-name-as-directory (expand-file-name dir)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 ;; Check that it's really a directory.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 (or (file-directory-p dir)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 (error "find-dired needs a directory: %s" dir))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 (switch-to-buffer-other-window (if find-dired-multiple-buffers
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102 (generate-new-buffer (concat "*Find-in-"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 (file-name-nondirectory (directory-file-name dir))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 "/..*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 (get-buffer-create "*Find*")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 (widen)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 (kill-all-local-variables)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 (setq buffer-read-only nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 (setq default-directory dir
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 find-args args ; save for next interactive call
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 args (concat "find . "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 (if (string= args "")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 ""
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 (concat "\\( " args " \\) "))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 (car find-ls-option)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 ;; The next statement will bomb in classic dired (no optional arg allowed)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 (dired-mode dir (cdr find-ls-option))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 ;; This really should rerun the find command, but I don't
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120 ;; have time for that.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121 (let ((keymap (make-sparse-keymap)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 (set-keymap-parents keymap (list (current-local-map)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 (define-key keymap "g" 'undefined)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124 (use-local-map keymap))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 ;; Set subdir-alist so that Tree Dired will work:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 (if (fboundp 'dired-simple-subdir-alist)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 ;; will work even with nested dired format (dired-nstd.el,v 1.15
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 ;; and later)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 (dired-simple-subdir-alist)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 ;; else we have an ancient tree dired (or classic dired, where
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131 ;; this does no harm)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 (set (make-local-variable 'dired-subdir-alist)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 (list (cons default-directory (point-min-marker)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 (setq buffer-read-only nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135 ;; Subdir headlerline must come first because the first marker in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 ;; subdir-alist points there.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 (insert " " dir ":\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 ;; Make second line a ``find'' line in analogy to the ``total'' or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139 ;; ``wildcard'' line.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
140 (insert " " args "\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 ;; Start the find process
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 (message "Searching .... (but you can continue other work)")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 (sit-for 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 (let ((proc (start-process-shell-command "find" (current-buffer) args)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 (set-process-filter proc (function find-dired-filter))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146 (set-process-sentinel proc (function find-dired-sentinel))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147 ;; Initialize the process marker; it is used by the filter.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 (move-marker (process-mark proc) 1 (current-buffer)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149 (setq modeline-process '(": %s")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152 (defun find-name-dired (dir pattern)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 "Search DIR recursively for files matching the globbing pattern PATTERN,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 and run dired on those files.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155 PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156 The command run (after changing into DIR) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158 find . -name 'PATTERN' -ls"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 (interactive
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 "DFind-name (directory): \nsFind-name (filename wildcard): ")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 (find-dired dir (concat "-name '" pattern "'")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 ;; This functionality suggested by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 ;; From: oblanc@watcgl.waterloo.edu (Olivier Blanc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 ;; Subject: find-dired, lookfor-dired
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 ;; Date: 10 May 91 17:50:00 GMT
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 ;; Organization: University of Waterloo
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 (defalias 'lookfor-dired 'find-grep-dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 ;; XEmacs addition
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 (defvar find-grep-dired-history nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 "history for find-grep-dired input")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 (defun find-grep-dired (dir args)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 "Find files in DIR containing a regexp ARG and start Dired on output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 The command run (after changing into DIR) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 find . -type f -exec test -r {} \\\; -exec egrep -s ARG {} \\\; -ls
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 Thus ARG can also contain additional grep options."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 (interactive
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 ;; XEmacs improvements here.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 (list (read-string "Find-grep (directory): "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 default-directory 'find-dired-dir-history)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 (read-string "Find-grep (grep args): " (and (fboundp 'symbol-near-point)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 (symbol-near-point))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 'find-grep-dired-history)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 ;; find -exec doesn't allow shell i/o redirections in the command,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 ;; or we could use `grep -l >/dev/null'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 (find-dired dir
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 ;; XEmacs improvements here.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 (concat "-type f -exec test -r {} \\\; -exec egrep "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 find-grep-options " " args " {} \\\; ")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 (defun find-dired-filter (proc string)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 ;; Filter for \\[find-dired] processes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 (let ((buf (process-buffer proc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200 (if (buffer-name buf) ; not killed?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 (set-buffer buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 (save-restriction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 (widen)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 (let ((buffer-read-only nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 (end (point-max)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 (goto-char end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 (insert string)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 (goto-char end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 (or (looking-at "^")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 (forward-line 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 (while (looking-at "^")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 (insert " ")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 (forward-line 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 ;; Convert ` ./FILE' to ` FILE'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 ;; This would lose if the current chunk of output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 ;; starts or ends within the ` ./', so back up a bit:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 (goto-char (- end 3)) ; no error if < 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 (while (search-forward " ./" nil t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 (delete-region (point) (- (point) 2)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 ;; Find all the complete lines in the unprocessed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 ;; output and process it to add text properties.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 (goto-char end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 (if (search-backward "\n" (process-mark proc) t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 (dired-insert-set-properties (process-mark proc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 (1+ (point)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 (move-marker (process-mark proc) (1+ (point)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230 ))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 ;; The buffer has been killed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 (delete-process proc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 (defun find-dired-sentinel (proc state)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 ;; Sentinel for \\[find-dired] processes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 (let ((buf (process-buffer proc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 (if (buffer-name buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 (set-buffer buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 (let ((buffer-read-only nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 (goto-char (point-max))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 (insert "\nfind " state)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 (forward-char -1) ;Back up before \n at end of STATE.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 (insert " at " (substring (current-time-string) 0 19))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 (forward-char 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 (setq modeline-process ;; XEmacs: newer spelling
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 (concat ":"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 (symbol-name (process-status proc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 ;; Since the buffer and mode line will show that the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 ;; process is dead, we can delete it now. Otherwise it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 ;; will stay around until M-x list-processes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 (delete-process proc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 (redraw-modeline))) ;; XEmacs function
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 (message "find-dired %s finished." (current-buffer))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 (provide 'find-dired)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 ;;; find-dired.el ends here