help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening a Dired buffer with an arbitrary list of files.


From: Mathias Dahl
Subject: Re: Opening a Dired buffer with an arbitrary list of files.
Date: Mon, 22 May 2006 08:42:40 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

Kevin Rodgers <address@hidden> 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, <menu-bar> <file> <dired>.
> | (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!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]