aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath1991-06-20 12:32:05 +0000
committerRoland McGrath1991-06-20 12:32:05 +0000
commitc23ae0440bc2ad23237142545edfb741dba4dc2f (patch)
treee511ca6f6b8806ed59c7b066d90e02d9c6ef5740
parentdbc3787ccdd8a97ca86453523e4a5cf27776ec68 (diff)
downloademacs-c23ae0440bc2ad23237142545edfb741dba4dc2f.tar.gz
emacs-c23ae0440bc2ad23237142545edfb741dba4dc2f.zip
*** empty log message ***
-rw-r--r--lisp/find-dired.el135
1 files changed, 108 insertions, 27 deletions
diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index 3f24dc83058..630953121a2 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -1,7 +1,8 @@
1;;; find-dired.el -- Run a `find' command and dired the result. 1;;; find-dired.el -- Run a `find' command and dired the result.
2;;; Copyright (C) 1991 Free Software Foundation, Inc. 2;;; Copyright (C) 1991 Roland McGrath
3;;; Written by Roland McGrath 3
4;;; 4(defconst find-dired-version "$Id: find-dired.el,v 1.7 1991/06/20 08:50:20 sk RelBeta $")
5
5;;; This program is free software; you can redistribute it and/or modify 6;;; This program is free software; you can redistribute it and/or modify
6;;; it under the terms of the GNU General Public License as published by 7;;; it under the terms of the GNU General Public License as published by
7;;; the Free Software Foundation; either version 1, or (at your option) 8;;; the Free Software Foundation; either version 1, or (at your option)
@@ -17,6 +18,17 @@
17;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 18;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
18;;; 02139, USA. 19;;; 02139, USA.
19;;; 20;;;
21;;; Send bug reports to roland@gnu.ai.mit.edu.
22
23;;; To use this file, byte-compile it, install it somewhere
24;;; in your load-path, and put:
25;;; (autoload 'find-dired "find-dired" nil t)
26;;; (autoload 'lookfor-dired "find-dired" nil t)
27;;; in your .emacs, or site-init.el, etc.
28;;; To bind it to a key, put, e.g.:
29;;; (global-set-key "\C-cf" 'find-dired)
30;;; (global-set-key "\C-cl" 'lookfor-dired)
31;;; in your .emacs.
20 32
21(require 'dired) 33(require 'dired)
22 34
@@ -32,7 +44,10 @@
32 "Run `find' and go into dired-mode on a buffer of the output. 44 "Run `find' and go into dired-mode on a buffer of the output.
33The command run is \"find . \\( ARGS \\) -ls\" (after changing into DIR)." 45The command run is \"find . \\( ARGS \\) -ls\" (after changing into DIR)."
34 (interactive (list (read-file-name "Run find in directory: " nil "" t) 46 (interactive (list (read-file-name "Run find in directory: " nil "" t)
35 (read-string "Run find (with args): " find-args))) 47 (if (featurep 'gmhist)
48 (read-with-history-in 'find-args-history
49 "Run find (with args): ")
50 (read-string "Run find (with args): " find-args))))
36 (if (equal dir "") 51 (if (equal dir "")
37 (setq dir default-directory)) 52 (setq dir default-directory))
38 ;; Expand DIR, and make sure it has a trailing slash. 53 ;; Expand DIR, and make sure it has a trailing slash.
@@ -68,31 +83,97 @@ and run dired on those files."
68 83
69(defun find-dired-filter (proc string) 84(defun find-dired-filter (proc string)
70 ;; Filter for \\[find-dired] processes. 85 ;; Filter for \\[find-dired] processes.
71 (let ((buf (process-buffer proc))) 86 (let ((buf (process-buffer proc)))
72 (if (buffer-name buf) 87 (if (buffer-name buf) ; not killed?
73 (save-excursion 88 (save-excursion
74 (set-buffer buf) 89 (set-buffer buf)
75 (save-restriction 90 (save-restriction
76 (widen) 91 (widen)
77 (save-excursion 92 (save-excursion
78 (let ((buffer-read-only nil) 93 (let ((buffer-read-only nil)
79 (end (point-max))) 94 (end (point-max)))
80 (goto-char end) 95 (goto-char end)
81 (insert string) 96 (insert string)
82 (goto-char end) 97 (goto-char end)
83 (or (looking-at "^") 98 (or (looking-at "^")
84 (forward-line 1)) 99 (forward-line 1))
85 (while (looking-at "^") 100 (while (looking-at "^")
86 (insert " ") 101 (insert " ")
87 (forward-line 1)))))) 102 (forward-line 1))))))
88 ;; The buffer has been killed. 103 ;; The buffer has been killed.
89 (delete-process proc)))) 104 (delete-process proc))))
90 105
91(defun find-dired-sentinel (proc state) 106(defun find-dired-sentinel (proc state)
92 ;; Sentinel for \\[find-dired] processes. 107 ;; Sentinel for \\[find-dired] processes.
93 (save-excursion 108 (let ((buf (process-buffer proc)))
94 (set-buffer (process-buffer proc)) 109 (if (buffer-name buf)
95 (setq mode-line-process nil) 110 (save-excursion
96 (message "find-dired %s finished." (current-buffer)))) 111 (set-buffer buf)
112 (setq mode-line-process nil)
113 (message "find-dired %s finished." (current-buffer))))))
114
115(or (fboundp 'start-process-shell-command)
116 ;; From version 19 subr.el.
117 (defun start-process-shell-command (name buffer &rest args)
118 "Start a program in a subprocess. Return the process object for it.
119Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
120NAME is name for process. It is modified if necessary to make it unique.
121BUFFER is the buffer or (buffer-name) to associate with the process.
122 Process output goes at end of that buffer, unless you specify
123 an output stream or filter function to handle the output.
124 BUFFER may be also nil, meaning that this process is not associated
125 with any buffer
126Third arg is command name, the name of a shell command.
127Remaining arguments are the arguments for the command.
128Wildcards and redirection are handle as usual in the shell."
129 (if (eq system-type 'vax-vms)
130 (apply 'start-process name buffer args)
131 (start-process name buffer shell-file-name "-c"
132 (concat "exec " (mapconcat 'identity args " ")))))
133 )
134
135;; From: oblanc@watcgl.waterloo.edu (Olivier Blanc)
136;; Subject: find-dired, lookfor-dired
137;; Date: 10 May 91 17:50:00 GMT
138;; Organization: University of Waterloo
139
140;; I added a functiopn to the find-dired.el file:
141;; The function is a lookfor-dired and is used to search a string
142;; a subtree:
143
144;;;###autoload
145(defun lookfor-dired (dir args)
146 "Find files in DIR containing a regexp ARG and go into dired-mode on the output.
147The command run is
148
149 \"find . -exec grep -l ARG {} \\\; -ls\"
150
151\(after changing into DIR)."
152 (interactive (list (read-file-name "Run find in directory: " nil "" t)
153 (read-string "Run find (with args): " find-args)))
154 (if (equal dir "")
155 (setq dir default-directory))
156 ;; Expand DIR, and make sure it has a trailing slash.
157 (setq dir (file-name-as-directory (expand-file-name dir)))
158 ;; Check that it's really a directory.
159 (or (file-directory-p dir)
160 (error "%s is not a directory!" dir))
161 (switch-to-buffer (get-buffer-create "*Find*"))
162 (widen)
163 (kill-all-local-variables)
164 (setq buffer-read-only nil)
165 (erase-buffer)
166 (setq default-directory dir
167 find-args args
168 args (concat "find . -exec grep -l " args " {} \\\; -ls"))
169 (insert " " args "\n"
170 " " dir ":\n")
171 (set-process-filter (start-process-shell-command "find"
172 (current-buffer) args)
173 'find-dired-filter)
174 (set-process-sentinel (get-buffer-process (current-buffer))
175 'find-dired-sentinel)
176 (dired-mode)
177 (setq mode-line-process '(": %s")))
97 178
98(provide 'find-dired) 179(provide 'find-dired)