Mercurial > emacs
annotate lisp/find-dired.el @ 1091:3302f6e93ce5
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 11 Sep 1992 09:04:24 +0000 |
parents | 20674ae6bf52 |
children | 170e5a18c4ba |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;; find-dired.el --- run a `find' command and dired the output |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;;; Copyright (C) 1991 Roland McGrath |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Sebastian Kremer <sk@thp.uni-koeln.de> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 ;; Maintainer: Roland McGrath <roland@gnu.ai.mit.edu> |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
8 ;; Keywords: unix |
294 | 9 |
474 | 10 (defconst find-dired-version (substring "$Revision: 1.9 $" 11 -2) |
11 "$Id: find-dired.el,v 1.9 1991/11/11 13:24:31 sk Exp $") | |
294 | 12 |
292 | 13 ;;; This program is free software; you can redistribute it and/or modify |
14 ;;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
15 ;;; the Free Software Foundation; either version 2, or (at your option) |
292 | 16 ;;; any later version. |
17 ;;; | |
18 ;;; This program is distributed in the hope that it will be useful, | |
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;;; GNU General Public License for more details. | |
22 ;;; | |
23 ;;; A copy of the GNU General Public License can be obtained from this | |
24 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
25 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
26 ;;; 02139, USA. | |
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 |
30 ;; INSTALLATION ====================================================== | |
31 | |
32 ;; To use this file, byte-compile it, install it somewhere in your | |
33 ;; load-path, and put: | |
294 | 34 |
474 | 35 ;; (autoload 'find-dired "find-dired" nil t) |
36 ;; (autoload 'find-name-dired "find-dired" nil t) | |
37 ;; (autoload 'find-grep-dired "find-dired" nil t) | |
38 | |
39 ;; in your ~/.emacs, or site-init.el, etc. | |
40 | |
41 ;; To bind it to a key, put, e.g.: | |
42 ;; | |
43 ;; (global-set-key "\C-cf" 'find-dired) | |
44 ;; (global-set-key "\C-cn" 'find-name-dired) | |
45 ;; (global-set-key "\C-cl" 'find-grep-dired) | |
46 ;; | |
47 ;; in your ~/.emacs. | |
292 | 48 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
49 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
50 |
292 | 51 (require 'dired) |
474 | 52 ;;;###autoload |
53 (defvar find-ls-option (if (eq system-type 'berkeley-unix) "-ls" | |
54 "-exec ls -ldi {} \\;") | |
55 "*Option to `find' to produce an `ls -l'-type listing.") | |
56 | |
57 ;;;###autoload | |
58 (defvar find-grep-options (if (eq system-type 'berkeley-unix) "-s" "-l") | |
59 "*Option to grep to be as silent as possible. | |
60 On Berkeley systems, this is `-s', for others it seems impossible to | |
61 suppress all output, so `-l' is used to print nothing more than the | |
62 file name.") | |
292 | 63 |
64 (defvar find-args nil | |
65 "Last arguments given to `find' by \\[find-dired].") | |
66 | |
67 ;;;###autoload | |
68 (defun find-dired (dir args) | |
69 "Run `find' and go into dired-mode on a buffer of the output. | |
474 | 70 The command run (after changing into DIR) is |
71 | |
72 find . \\( ARGS \\) -ls" | |
292 | 73 (interactive (list (read-file-name "Run find in directory: " nil "" t) |
294 | 74 (if (featurep 'gmhist) |
75 (read-with-history-in 'find-args-history | |
76 "Run find (with args): ") | |
77 (read-string "Run find (with args): " find-args)))) | |
474 | 78 ;; Expand DIR ("" means default-directory), and make sure it has a |
79 ;; trailing slash. | |
292 | 80 (setq dir (file-name-as-directory (expand-file-name dir))) |
81 ;; Check that it's really a directory. | |
82 (or (file-directory-p dir) | |
474 | 83 (error "find-dired needs a directory: %s" dir)) |
292 | 84 (switch-to-buffer (get-buffer-create "*Find*")) |
85 (widen) | |
86 (kill-all-local-variables) | |
87 (setq buffer-read-only nil) | |
88 (erase-buffer) | |
89 (setq default-directory dir | |
90 find-args args | |
91 args (concat "find . " (if (string= args "") "" | |
92 (concat "\\( " args " \\) ")) find-ls-option)) | |
474 | 93 (dired-mode dir "-gils");; find(1)'s -ls corresponds to `ls -gilds' |
94 ;; (but we don't want -d, of course) | |
95 ;; Set subdir-alist so that Tree Dired will work (but STILL NOT with | |
96 ;; dired-nstd.el): | |
97 (set (make-local-variable 'dired-subdir-alist) | |
98 (list (cons default-directory (point-marker)))) ; we are at point-min | |
99 (setq buffer-read-only nil) | |
100 ;; Subdir headlerline must come first because the first marker in | |
101 ;; subdir-alist points there. | |
102 (insert " " dir ":\n") | |
103 ;; Make second line a ``find'' line in analogy to the ``total'' or | |
104 ;; ``wildcard'' line. | |
105 (insert " " args "\n") | |
106 ;; Start the find process | |
292 | 107 (set-process-filter (start-process-shell-command "find" |
108 (current-buffer) args) | |
474 | 109 (function find-dired-filter)) |
292 | 110 (set-process-sentinel (get-buffer-process (current-buffer)) |
474 | 111 (function find-dired-sentinel)) |
292 | 112 (setq mode-line-process '(": %s"))) |
113 | |
114 ;;;###autoload | |
115 (defun find-name-dired (dir pattern) | |
116 "Search DIR recursively for files matching the globbing pattern PATTERN, | |
474 | 117 and run dired on those files. |
118 PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted. | |
119 The command run (after changing into DIR) is | |
120 | |
121 find . -name 'PATTERN' -ls" | |
122 (interactive | |
123 "DFind-name (directory): \nsFind-name (filename wildcard): ") | |
292 | 124 (find-dired dir (concat "-name '" pattern "'"))) |
125 | |
474 | 126 ;; This functionality suggested by |
127 ;; From: oblanc@watcgl.waterloo.edu (Olivier Blanc) | |
128 ;; Subject: find-dired, lookfor-dired | |
129 ;; Date: 10 May 91 17:50:00 GMT | |
130 ;; Organization: University of Waterloo | |
131 | |
132 (fset 'lookfor-dired 'find-grep-dired) | |
133 ;;;###autoload | |
134 (defun find-grep-dired (dir args) | |
135 "Find files in DIR containing a regexp ARG and start Dired on output. | |
136 The command run (after changing into DIR) is | |
137 | |
138 find . -exec grep -s ARG {} \\\; -ls | |
139 | |
140 Thus ARG can also contain additional grep options." | |
141 (interactive "DFind-grep (directory): \nsFind-grep (grep args): ") | |
142 ;; find -exec doesn't allow shell i/o redirections in the command, | |
143 ;; or we could use `grep -l >/dev/null' | |
144 (find-dired dir | |
145 (concat "-exec grep " find-grep-options " " args " {} \\\; "))) | |
146 | |
292 | 147 (defun find-dired-filter (proc string) |
148 ;; Filter for \\[find-dired] processes. | |
474 | 149 (dired-log "``%s''\n" string) |
294 | 150 (let ((buf (process-buffer proc))) |
151 (if (buffer-name buf) ; not killed? | |
152 (save-excursion | |
153 (set-buffer buf) | |
154 (save-restriction | |
155 (widen) | |
156 (save-excursion | |
157 (let ((buffer-read-only nil) | |
158 (end (point-max))) | |
159 (goto-char end) | |
160 (insert string) | |
161 (goto-char end) | |
162 (or (looking-at "^") | |
163 (forward-line 1)) | |
164 (while (looking-at "^") | |
165 (insert " ") | |
474 | 166 (forward-line 1)) |
167 ;; Convert ` ./FILE' to ` FILE' | |
168 ;; This would lose if the current chunk of output | |
169 ;; starts or ends within the ` ./', so backup up a bit: | |
170 (goto-char (- end 3)) ; no error if < 0 | |
171 (while (search-forward " ./" nil t) | |
172 (delete-region (point) (- (point) 2))))))) | |
294 | 173 ;; The buffer has been killed. |
174 (delete-process proc)))) | |
292 | 175 |
176 (defun find-dired-sentinel (proc state) | |
177 ;; Sentinel for \\[find-dired] processes. | |
294 | 178 (let ((buf (process-buffer proc))) |
179 (if (buffer-name buf) | |
180 (save-excursion | |
181 (set-buffer buf) | |
182 (setq mode-line-process nil) | |
183 (message "find-dired %s finished." (current-buffer)))))) | |
184 | |
185 (or (fboundp 'start-process-shell-command) | |
186 ;; From version 19 subr.el. | |
187 (defun start-process-shell-command (name buffer &rest args) | |
188 "Start a program in a subprocess. Return the process object for it. | |
189 Args are NAME BUFFER COMMAND &rest COMMAND-ARGS. | |
190 NAME is name for process. It is modified if necessary to make it unique. | |
191 BUFFER is the buffer or (buffer-name) to associate with the process. | |
192 Process output goes at end of that buffer, unless you specify | |
193 an output stream or filter function to handle the output. | |
194 BUFFER may be also nil, meaning that this process is not associated | |
195 with any buffer | |
196 Third arg is command name, the name of a shell command. | |
197 Remaining arguments are the arguments for the command. | |
198 Wildcards and redirection are handle as usual in the shell." | |
199 (if (eq system-type 'vax-vms) | |
200 (apply 'start-process name buffer args) | |
201 (start-process name buffer shell-file-name "-c" | |
474 | 202 (concat "exec " (mapconcat 'identity args " ")))))) |
294 | 203 |
584 | 204 (provide 'find-dired) |
205 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
206 ;;; find-dired.el ends here |