Mercurial > emacs
comparison lisp/find-dired.el @ 22630:e4a895537576
(find-dired): Bind dired-buffers so it can't change. Use abbreviate-file-name.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 27 Jun 1998 21:59:11 +0000 |
parents | 9b9c929675eb |
children | cbe304a26771 |
comparison
equal
deleted
inserted
replaced
22629:5d51b13e0d1f | 22630:e4a895537576 |
---|---|
65 ;; History of find-args values entered in the minibuffer. | 65 ;; History of find-args values entered in the minibuffer. |
66 (defvar find-args-history nil) | 66 (defvar find-args-history nil) |
67 | 67 |
68 ;;;###autoload | 68 ;;;###autoload |
69 (defun find-dired (dir args) | 69 (defun find-dired (dir args) |
70 "Run `find' and go into dired-mode on a buffer of the output. | 70 "Run `find' and go into Dired mode on a buffer of the output. |
71 The command run (after changing into DIR) is | 71 The command run (after changing into DIR) is |
72 | 72 |
73 find . \\( ARGS \\) -ls | 73 find . \\( ARGS \\) -ls |
74 | 74 |
75 except that the variable `find-ls-option' specifies what to use | 75 except that the variable `find-ls-option' specifies what to use |
76 as the final argument." | 76 as the final argument." |
77 (interactive (list (read-file-name "Run find in directory: " nil "" t) | 77 (interactive (list (read-file-name "Run find in directory: " nil "" t) |
78 (read-string "Run find (with args): " find-args | 78 (read-string "Run find (with args): " find-args |
79 '(find-args-history . 1)))) | 79 '(find-args-history . 1)))) |
80 ;; Expand DIR ("" means default-directory), and make sure it has a | 80 (let ((dired-buffers dired-buffers)) |
81 ;; trailing slash. | 81 ;; Expand DIR ("" means default-directory), and make sure it has a |
82 (setq dir (file-name-as-directory (expand-file-name dir))) | 82 ;; trailing slash. |
83 ;; Check that it's really a directory. | 83 (setq dir (abbreviate-file-name |
84 (or (file-directory-p dir) | 84 (file-name-as-directory (expand-file-name dir)))) |
85 (error "find-dired needs a directory: %s" dir)) | 85 ;; Check that it's really a directory. |
86 (switch-to-buffer (get-buffer-create "*Find*")) | 86 (or (file-directory-p dir) |
87 (widen) | 87 (error "find-dired needs a directory: %s" dir)) |
88 (kill-all-local-variables) | 88 (switch-to-buffer (get-buffer-create "*Find*")) |
89 (setq buffer-read-only nil) | 89 (widen) |
90 (erase-buffer) | 90 (kill-all-local-variables) |
91 (setq default-directory dir | 91 (setq buffer-read-only nil) |
92 find-args args ; save for next interactive call | 92 (erase-buffer) |
93 args (concat "find . " | 93 (setq default-directory dir |
94 (if (string= args "") | 94 find-args args ; save for next interactive call |
95 "" | 95 args (concat "find . " |
96 (concat "\\( " args " \\) ")) | 96 (if (string= args "") |
97 (car find-ls-option))) | 97 "" |
98 ;; The next statement will bomb in classic dired (no optional arg allowed) | 98 (concat "\\( " args " \\) ")) |
99 (dired-mode dir (cdr find-ls-option)) | 99 (car find-ls-option))) |
100 ;; This really should rerun the find command, but I don't | 100 ;; The next statement will bomb in classic dired (no optional arg allowed) |
101 ;; have time for that. | 101 (dired-mode dir (cdr find-ls-option)) |
102 (use-local-map (append (make-sparse-keymap) (current-local-map))) | 102 ;; This really should rerun the find command, but I don't |
103 (define-key (current-local-map) "g" 'undefined) | 103 ;; have time for that. |
104 ;; Set subdir-alist so that Tree Dired will work: | 104 (use-local-map (append (make-sparse-keymap) (current-local-map))) |
105 (if (fboundp 'dired-simple-subdir-alist) | 105 (define-key (current-local-map) "g" 'undefined) |
106 ;; will work even with nested dired format (dired-nstd.el,v 1.15 | 106 ;; Set subdir-alist so that Tree Dired will work: |
107 ;; and later) | 107 (if (fboundp 'dired-simple-subdir-alist) |
108 (dired-simple-subdir-alist) | 108 ;; will work even with nested dired format (dired-nstd.el,v 1.15 |
109 ;; else we have an ancient tree dired (or classic dired, where | 109 ;; and later) |
110 ;; this does no harm) | 110 (dired-simple-subdir-alist) |
111 (set (make-local-variable 'dired-subdir-alist) | 111 ;; else we have an ancient tree dired (or classic dired, where |
112 (list (cons default-directory (point-min-marker))))) | 112 ;; this does no harm) |
113 (setq buffer-read-only nil) | 113 (set (make-local-variable 'dired-subdir-alist) |
114 ;; Subdir headlerline must come first because the first marker in | 114 (list (cons default-directory (point-min-marker))))) |
115 ;; subdir-alist points there. | 115 (setq buffer-read-only nil) |
116 (insert " " dir ":\n") | 116 ;; Subdir headlerline must come first because the first marker in |
117 ;; Make second line a ``find'' line in analogy to the ``total'' or | 117 ;; subdir-alist points there. |
118 ;; ``wildcard'' line. | 118 (insert " " dir ":\n") |
119 (insert " " args "\n") | 119 ;; Make second line a ``find'' line in analogy to the ``total'' or |
120 ;; Start the find process. | 120 ;; ``wildcard'' line. |
121 (let ((proc (start-process-shell-command "find" (current-buffer) args))) | 121 (insert " " args "\n") |
122 (set-process-filter proc (function find-dired-filter)) | 122 ;; Start the find process. |
123 (set-process-sentinel proc (function find-dired-sentinel)) | 123 (let ((proc (start-process-shell-command "find" (current-buffer) args))) |
124 ;; Initialize the process marker; it is used by the filter. | 124 (set-process-filter proc (function find-dired-filter)) |
125 (move-marker (process-mark proc) 1 (current-buffer))) | 125 (set-process-sentinel proc (function find-dired-sentinel)) |
126 (setq mode-line-process '(":%s"))) | 126 ;; Initialize the process marker; it is used by the filter. |
127 (move-marker (process-mark proc) 1 (current-buffer))) | |
128 (setq mode-line-process '(":%s")))) | |
127 | 129 |
128 ;;;###autoload | 130 ;;;###autoload |
129 (defun find-name-dired (dir pattern) | 131 (defun find-name-dired (dir pattern) |
130 "Search DIR recursively for files matching the globbing pattern PATTERN, | 132 "Search DIR recursively for files matching the globbing pattern PATTERN, |
131 and run dired on those files. | 133 and run dired on those files. |