Mercurial > emacs
annotate lisp/find-dired.el @ 10946:aa943e2ea495
(read_input_waiting): Fix Lisp_Object vs. int problem.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 08 Mar 1995 22:49:11 +0000 |
parents | 8102a6447ea0 |
children | 97da4cb32d03 |
rev | line source |
---|---|
2230
6314334d7c2b
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1225
diff
changeset
|
1 ;;; find-dired.el --- run a `find' command and dired the output |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
3 ;;; Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>, |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
6 ;; Sebastian Kremer <sk@thp.uni-koeln.de> |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: unix |
294 | 8 |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
9 (defconst find-dired-version (substring "$Revision: 1.18 $" 11 -2) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
10 "$Id: find-dired.el,v 1.18 1994/12/15 12:16:29 rms Exp roland $") |
294 | 11 |
292 | 12 ;;; This program is free software; you can redistribute it and/or modify |
13 ;;; it under the terms of the GNU General Public License as published by | |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
14 ;;; the Free Software Foundation; either version 2, or (at your option) |
292 | 15 ;;; any later version. |
16 ;;; | |
17 ;;; This program is distributed in the hope that it will be useful, | |
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;;; GNU General Public License for more details. | |
21 ;;; | |
22 ;;; A copy of the GNU General Public License can be obtained from this | |
23 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
24 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
25 ;;; 02139, USA. | |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
26 ;;; |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
27 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
28 ;;; Commentary: |
474 | 29 |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
30 ;; LISPDIR ENTRY for the Elisp Archive =============================== |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
31 ;; LCD Archive Entry: |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
32 ;; find-dired|Roland McGrath, Sebastian Kremer |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
33 ;; |roland@gnu.ai.mit.edu, sk@thp.uni-koeln.de |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
34 ;; |Run a `find' command and dired the output |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
35 ;; |$Date: 1994/12/15 12:16:29 $|$Revision: 1.18 $| |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
36 |
474 | 37 ;; INSTALLATION ====================================================== |
38 | |
39 ;; To use this file, byte-compile it, install it somewhere in your | |
40 ;; load-path, and put: | |
294 | 41 |
474 | 42 ;; (autoload 'find-dired "find-dired" nil t) |
43 ;; (autoload 'find-name-dired "find-dired" nil t) | |
44 ;; (autoload 'find-grep-dired "find-dired" nil t) | |
45 | |
46 ;; in your ~/.emacs, or site-init.el, etc. | |
47 | |
48 ;; To bind it to a key, put, e.g.: | |
49 ;; | |
50 ;; (global-set-key "\C-cf" 'find-dired) | |
51 ;; (global-set-key "\C-cn" 'find-name-dired) | |
52 ;; (global-set-key "\C-cl" 'find-grep-dired) | |
53 ;; | |
54 ;; in your ~/.emacs. | |
292 | 55 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
56 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
57 |
292 | 58 (require 'dired) |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
59 |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
60 ;; find(1)'s -ls corresponds to these switches. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
61 ;; Note -b, at least GNU find quotes spaces etc. in filenames |
474 | 62 ;;;###autoload |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
63 (defvar find-ls-option (if (eq system-type 'berkeley-unix) '("-ls" . "-gilsb") |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
64 '("-exec ls -ld {} \\;" . "-ld")) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
65 "*Description of the option to `find' to produce an `ls -l'-type listing. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
66 This is a cons of two strings (FIND-OPTION . LS-SWITCHES). FIND-OPTION |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
67 gives the option (or options) to `find' that produce the desired output. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
68 LS-SWITCHES is a list of `ls' switches to tell dired how to parse the output.") |
474 | 69 |
70 ;;;###autoload | |
10168
64163654c255
(find-grep-options): Use -q on non-BSD systems.
Richard M. Stallman <rms@gnu.org>
parents:
10024
diff
changeset
|
71 (defvar find-grep-options (if (eq system-type 'berkeley-unix) "-s" "-q") |
474 | 72 "*Option to grep to be as silent as possible. |
10168
64163654c255
(find-grep-options): Use -q on non-BSD systems.
Richard M. Stallman <rms@gnu.org>
parents:
10024
diff
changeset
|
73 On Berkeley systems, this is `-s'; on Posix, and with GNU grep, `-q' does it. |
64163654c255
(find-grep-options): Use -q on non-BSD systems.
Richard M. Stallman <rms@gnu.org>
parents:
10024
diff
changeset
|
74 On other systems, the closest you can come is to use `-l'.") |
292 | 75 |
76 (defvar find-args nil | |
77 "Last arguments given to `find' by \\[find-dired].") | |
78 | |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
79 ;; History of find-args values entered in the minibuffer. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
80 (defvar find-args-history nil) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
81 |
292 | 82 ;;;###autoload |
83 (defun find-dired (dir args) | |
84 "Run `find' and go into dired-mode on a buffer of the output. | |
474 | 85 The command run (after changing into DIR) is |
86 | |
87 find . \\( ARGS \\) -ls" | |
292 | 88 (interactive (list (read-file-name "Run find in directory: " nil "" t) |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
89 (read-string "Run find (with args): " find-args |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
90 '(find-args-history . 1)))) |
474 | 91 ;; Expand DIR ("" means default-directory), and make sure it has a |
92 ;; trailing slash. | |
292 | 93 (setq dir (file-name-as-directory (expand-file-name dir))) |
94 ;; Check that it's really a directory. | |
95 (or (file-directory-p dir) | |
474 | 96 (error "find-dired needs a directory: %s" dir)) |
292 | 97 (switch-to-buffer (get-buffer-create "*Find*")) |
98 (widen) | |
99 (kill-all-local-variables) | |
100 (setq buffer-read-only nil) | |
101 (erase-buffer) | |
102 (setq default-directory dir | |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
103 find-args args ; save for next interactive call |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
104 args (concat "find . " |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
105 (if (string= args "") |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
106 "" |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
107 (concat "\\( " args " \\) ")) |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
108 (car find-ls-option))) |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
109 ;; The next statement will bomb in classic dired (no optional arg allowed) |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
110 (dired-mode dir (cdr find-ls-option)) |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
111 ;; Set subdir-alist so that Tree Dired will work: |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
112 (dired-simple-subdir-alist) |
474 | 113 (setq buffer-read-only nil) |
114 ;; Subdir headlerline must come first because the first marker in | |
115 ;; subdir-alist points there. | |
116 (insert " " dir ":\n") | |
117 ;; Make second line a ``find'' line in analogy to the ``total'' or | |
118 ;; ``wildcard'' line. | |
119 (insert " " args "\n") | |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
120 ;; Start the find process. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
121 (let ((proc (start-process-shell-command "find" (current-buffer) args))) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
122 (set-process-filter proc (function find-dired-filter)) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
123 (set-process-sentinel proc (function find-dired-sentinel)) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
124 ;; Initialize the process marker; it is used by the filter. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
125 (move-marker (process-mark proc) 1 (current-buffer))) |
7073
c662b47cda3f
(find-dired, find-dired-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
5460
diff
changeset
|
126 (setq mode-line-process '(":%s"))) |
292 | 127 |
128 ;;;###autoload | |
129 (defun find-name-dired (dir pattern) | |
130 "Search DIR recursively for files matching the globbing pattern PATTERN, | |
474 | 131 and run dired on those files. |
132 PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted. | |
133 The command run (after changing into DIR) is | |
134 | |
135 find . -name 'PATTERN' -ls" | |
136 (interactive | |
137 "DFind-name (directory): \nsFind-name (filename wildcard): ") | |
292 | 138 (find-dired dir (concat "-name '" pattern "'"))) |
139 | |
474 | 140 ;; This functionality suggested by |
141 ;; From: oblanc@watcgl.waterloo.edu (Olivier Blanc) | |
142 ;; Subject: find-dired, lookfor-dired | |
143 ;; Date: 10 May 91 17:50:00 GMT | |
144 ;; Organization: University of Waterloo | |
145 | |
2571
b65cf676a09b
All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2230
diff
changeset
|
146 (defalias 'lookfor-dired 'find-grep-dired) |
474 | 147 ;;;###autoload |
148 (defun find-grep-dired (dir args) | |
149 "Find files in DIR containing a regexp ARG and start Dired on output. | |
150 The command run (after changing into DIR) is | |
151 | |
152 find . -exec grep -s ARG {} \\\; -ls | |
153 | |
154 Thus ARG can also contain additional grep options." | |
10168
64163654c255
(find-grep-options): Use -q on non-BSD systems.
Richard M. Stallman <rms@gnu.org>
parents:
10024
diff
changeset
|
155 (interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ") |
474 | 156 ;; find -exec doesn't allow shell i/o redirections in the command, |
157 ;; or we could use `grep -l >/dev/null' | |
158 (find-dired dir | |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
159 (concat "! -type d -exec grep " find-grep-options " " |
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
160 args " {} \\\; "))) |
474 | 161 |
292 | 162 (defun find-dired-filter (proc string) |
163 ;; Filter for \\[find-dired] processes. | |
294 | 164 (let ((buf (process-buffer proc))) |
165 (if (buffer-name buf) ; not killed? | |
166 (save-excursion | |
167 (set-buffer buf) | |
168 (save-restriction | |
169 (widen) | |
170 (save-excursion | |
171 (let ((buffer-read-only nil) | |
172 (end (point-max))) | |
173 (goto-char end) | |
174 (insert string) | |
175 (goto-char end) | |
176 (or (looking-at "^") | |
177 (forward-line 1)) | |
178 (while (looking-at "^") | |
179 (insert " ") | |
474 | 180 (forward-line 1)) |
181 ;; Convert ` ./FILE' to ` FILE' | |
182 ;; This would lose if the current chunk of output | |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
183 ;; starts or ends within the ` ./', so back up a bit: |
474 | 184 (goto-char (- end 3)) ; no error if < 0 |
185 (while (search-forward " ./" nil t) | |
10929
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
186 (delete-region (point) (- (point) 2))) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
187 ;; Find all the complete lines in the unprocessed |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
188 ;; output and process it to add text properties. |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
189 (goto-char end) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
190 (if (search-backward "\n" (process-mark proc) t) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
191 (progn |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
192 (dired-insert-set-properties (process-mark proc) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
193 (1+ (point))) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
194 (move-marker (process-mark proc) (1+ (point))))) |
8102a6447ea0
(find-ls-option): Doc fix: now a cons.
Roland McGrath <roland@gnu.org>
parents:
10168
diff
changeset
|
195 )))) |
294 | 196 ;; The buffer has been killed. |
197 (delete-process proc)))) | |
292 | 198 |
199 (defun find-dired-sentinel (proc state) | |
200 ;; Sentinel for \\[find-dired] processes. | |
294 | 201 (let ((buf (process-buffer proc))) |
202 (if (buffer-name buf) | |
203 (save-excursion | |
204 (set-buffer buf) | |
3189
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
205 (let ((buffer-read-only nil)) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
206 (save-excursion |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
207 (goto-char (point-max)) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
208 (insert "\nfind " state) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
209 (forward-char -1) ;Back up before \n at end of STATE. |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
210 (insert " at " (substring (current-time-string) 0 19)) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
211 (forward-char 1) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
212 (setq mode-line-process |
7073
c662b47cda3f
(find-dired, find-dired-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
5460
diff
changeset
|
213 (concat ":" |
3189
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
214 (symbol-name (process-status proc)))) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
215 ;; Since the buffer and mode line will show that the |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
216 ;; process is dead, we can delete it now. Otherwise it |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
217 ;; will stay around until M-x list-processes. |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
218 (delete-process proc) |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
219 ;; Force mode line redisplay soon. |
77efda0d2b31
(find-dired-sentinel): Write a line describing death.
Roland McGrath <roland@gnu.org>
parents:
2571
diff
changeset
|
220 (set-buffer-modified-p (buffer-modified-p)))) |
294 | 221 (message "find-dired %s finished." (current-buffer)))))) |
1225
e16f52a7c9f9
New version from sk. Further hacked:
Roland McGrath <roland@gnu.org>
parents:
1183
diff
changeset
|
222 |
584 | 223 (provide 'find-dired) |
224 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
225 ;;; find-dired.el ends here |