Mercurial > emacs
comparison lisp/find-dired.el @ 294:97aa6a6f9aa5
*** empty log message ***
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Thu, 20 Jun 1991 12:32:05 +0000 |
parents | cab78578e745 |
children | c3bbd755b7da |
comparison
equal
deleted
inserted
replaced
293:7e7575d7b6d0 | 294:97aa6a6f9aa5 |
---|---|
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) |
8 ;;; any later version. | 9 ;;; any later version. |
9 ;;; | 10 ;;; |
15 ;;; A copy of the GNU General Public License can be obtained from this | 16 ;;; A copy of the GNU General Public License can be obtained from this |
16 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | 17 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from |
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 |
23 (defvar find-args nil | 35 (defvar find-args nil |
24 "Last arguments given to `find' by \\[find-dired].") | 36 "Last arguments given to `find' by \\[find-dired].") |
30 ;;;###autoload | 42 ;;;###autoload |
31 (defun find-dired (dir args) | 43 (defun find-dired (dir args) |
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. |
33 The command run is \"find . \\( ARGS \\) -ls\" (after changing into DIR)." | 45 The 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. |
39 (setq dir (file-name-as-directory (expand-file-name dir))) | 54 (setq dir (file-name-as-directory (expand-file-name dir))) |
40 ;; Check that it's really a directory. | 55 ;; Check that it's really a directory. |
66 (interactive "DSearch directory: \nsSearch directory %s for: ") | 81 (interactive "DSearch directory: \nsSearch directory %s for: ") |
67 (find-dired dir (concat "-name '" pattern "'"))) | 82 (find-dired dir (concat "-name '" pattern "'"))) |
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. | |
119 Args are NAME BUFFER COMMAND &rest COMMAND-ARGS. | |
120 NAME is name for process. It is modified if necessary to make it unique. | |
121 BUFFER 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 | |
126 Third arg is command name, the name of a shell command. | |
127 Remaining arguments are the arguments for the command. | |
128 Wildcards 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. | |
147 The 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) |