From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.help Subject: Re: Opening a Dired buffer with an arbitrary list of files. Date: Mon, 22 May 2006 08:42:40 +0200 Message-ID: References: <68816b4c0605190734r52b29978w7d41ef5393e43246@mail.gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1148283628 25053 80.91.229.2 (22 May 2006 07:40:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 22 May 2006 07:40:28 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 22 09:40:26 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fi51e-0005qF-E6 for geh-help-gnu-emacs@m.gmane.org; Mon, 22 May 2006 09:40:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fi51d-0003pc-O8 for geh-help-gnu-emacs@m.gmane.org; Mon, 22 May 2006 03:40:25 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 107 Original-X-Trace: individual.net yAzfY42de/O9/EMzu0c00AOWggknARHdZc9lU8rAikowWKLNn4 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:q73evbLnfmM2Y7/XehIbwz2+dyg= Original-Xref: shelby.stanford.edu gnu.emacs.help:139570 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35194 Archived-At: Kevin Rodgers writes: > Alder Green wrote: >> Is there a way open a Dired buffer containing an arbitrary list of files? >> I can have those files listed in a plain text file, or maybe >> provided >> as list return value of an elisp function. But I'm wondering how I can >> pass that list to be opened as a Dired buffer, and what format should >> it take. > > Only if all the files are in the same directory: > > ,----[ C-h f dired RET ] > | dired is an interactive compiled Lisp function in `dired.el'. > | It is bound to C-x d, . > | (dired dirname &optional switches) > | > | "Edit" directory dirname--delete, rename, print, etc. some files in it. > | Optional second argument switches specifies the `ls' options used. > | (Interactively, use a prefix argument to be able to specify switches.) > | Dired displays a list of files in dirname (which may also have > | shell wildcards appended to select certain files). If dirname is a cons, > | its first element is taken as the directory name and the rest as an > explicit > | list of files to make directory entries for. > | You can move around in it with the usual commands. > | You can flag files for deletion with d and then > | delete them by typing x. > | Type h after entering Dired for more info. > | > | If dirname is already in a dired buffer, that buffer is used without > refresh. > | > | [back] > `---- > > -- > Kevin Hehe! :) It seems it pays off to read the documentation more clearly. Check out the difference between these two implementations of "gds-dired". The first one done by copy and pasting code from some other place (don't remember, might have been `find-dired'), and the second one using `dired': (defun gds-dired-1 () "Use Google Desktop Search to find files and list them in dired. It generates a result like `find-dired' does, but uses Google Desktop Search to find matching files." (interactive) (let ((dir (read-directory-name "Set current directory: ")) (search (read-string "Search string: ")) (buf (get-buffer-create "*gds-dired*"))) (switch-to-buffer buf) (kill-all-local-variables) (setq buffer-read-only nil) (erase-buffer) (setq default-directory dir) (dired-mode dir) (use-local-map (append (make-sparse-keymap) (current-local-map))) (define-key (current-local-map) "g" 'undefined) ;; Set subdir-alist so that Tree Dired will work: (if (fboundp 'dired-simple-subdir-alist) ;; will work even with nested dired format (dired-nstd.el,v ;; 1.15 and later) (dired-simple-subdir-alist) ;; else we have an ancient tree dired (or classic dired, where ;; this does no harm) (set (make-local-variable 'dired-subdir-alist) (list (cons default-directory (point-min-marker))))) (setq buffer-read-only nil) (insert " " dir ":\n") ;; Make second line a ``dir'' line in analogy to the ``total'' or ;; ``wildcard'' line. (insert " GDS search results for \"" search "\"\n") (let ((buffer-read-only nil) (saved-pos nil)) (goto-char (point-max)) (setq mode-line-process (concat ": GDS search")) (mapc (lambda (x) (when (file-exists-p x) (insert " ") (insert-directory (expand-file-name x) ""))) (gds-get-matching-files search gds-dired-number-of-hits)) (insert " at " (substring (current-time-string) 0 19)) (force-mode-line-update)) (goto-char (point-min)) (forward-line 1) (dired-next-line 1))) Somewhat shorter: (defun gds-dired-2 () "Use Google Desktop Search to find files and list them in dired. It generates a result like `find-dired' does, but uses Google Desktop Search to find matching files." (interactive) (let ((dir (read-directory-name "Set current directory: ")) (search (read-string "Search string: "))) (dired (cons dir (gds-get-matching-files search gds-dired-number-of-hits))))) :) Thanks!