all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Opening a Dired buffer with an arbitrary list of files.
@ 2006-05-19 14:34 Alder Green
  2006-05-19 15:45 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alder Green @ 2006-05-19 14:34 UTC (permalink / raw)


Hi there

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.

-- 
-Alder

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Opening a Dired buffer with an arbitrary list of files.
  2006-05-19 14:34 Opening a Dired buffer with an arbitrary list of files Alder Green
@ 2006-05-19 15:45 ` Kevin Rodgers
  2006-05-21 12:10 ` Ehud Karni
       [not found] ` <mailman.2068.1148053935.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-05-19 15:45 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Opening a Dired buffer with an arbitrary list of files.
  2006-05-19 14:34 Opening a Dired buffer with an arbitrary list of files Alder Green
  2006-05-19 15:45 ` Kevin Rodgers
@ 2006-05-21 12:10 ` Ehud Karni
       [not found] ` <mailman.2068.1148053935.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Ehud Karni @ 2006-05-21 12:10 UTC (permalink / raw)
  Cc: help-gnu-emacs

On Fri, 19 May 2006 16:34:55 +0200, Alder Green wrote:
>
> Is there a way open a Dired buffer containing an arbitrary list of files?

Look at find-dired.el to see how to do it.

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Opening a Dired buffer with an arbitrary list of files.
       [not found] ` <mailman.2068.1148053935.9609.help-gnu-emacs@gnu.org>
@ 2006-05-22  6:42   ` Mathias Dahl
  2006-05-22 13:48     ` Miles Bader
       [not found]     ` <mailman.2161.1148305715.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-05-22  6:42 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> 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!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Opening a Dired buffer with an arbitrary list of files.
  2006-05-22  6:42   ` Mathias Dahl
@ 2006-05-22 13:48     ` Miles Bader
       [not found]     ` <mailman.2161.1148305715.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Miles Bader @ 2006-05-22 13:48 UTC (permalink / raw)


Mathias Dahl <brakjoller@gmail.com> writes:
> (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)))))

A bit shorter still (and demonstrating the typical use of `interactive'):

(defun gds-dired-3 (dir pattern)
  "Use Google Desktop Search to find files in DIR matching PATTERN
and list them in dired."
  (interactive "DSearch directory: \nsSearch pattern: ")
  (dired (cons dir (gds-get-matching-files pattern gds-dired-number-of-hits))))

-miles
-- 
.Numeric stability is probably not all that important when you're guessing.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Opening a Dired buffer with an arbitrary list of files.
       [not found]     ` <mailman.2161.1148305715.9609.help-gnu-emacs@gnu.org>
@ 2006-05-23 15:01       ` Mathias Dahl
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-05-23 15:01 UTC (permalink / raw)


Miles Bader <miles@gnu.org> writes:


> A bit shorter still (and demonstrating the typical use of `interactive'):
>
> (defun gds-dired-3 (dir pattern)
>   "Use Google Desktop Search to find files in DIR matching PATTERN
> and list them in dired."
>   (interactive "DSearch directory: \nsSearch pattern: ")
>   (dired (cons dir (gds-get-matching-files pattern gds-dired-number-of-hits))))

Super! Although the "Search directory" prompt is misleading. The
directory entered does not control the search in any way, it just sets
the dired buffer's default directory. One should probably hard code it
to "~".

:)

Thanks for the hints!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-23 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-19 14:34 Opening a Dired buffer with an arbitrary list of files Alder Green
2006-05-19 15:45 ` Kevin Rodgers
2006-05-21 12:10 ` Ehud Karni
     [not found] ` <mailman.2068.1148053935.9609.help-gnu-emacs@gnu.org>
2006-05-22  6:42   ` Mathias Dahl
2006-05-22 13:48     ` Miles Bader
     [not found]     ` <mailman.2161.1148305715.9609.help-gnu-emacs@gnu.org>
2006-05-23 15:01       ` Mathias Dahl

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.