[Top][All Lists]

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

RE: Filtering files in dired while invoking

From: Drew Adams
Subject: RE: Filtering files in dired while invoking
Date: Sun, 26 Sep 2010 18:33:15 -0700

Top-posting on purpose - old mail below provides some context.

FYI - I added this feature to Dired+ for interactive use:

Alternative main commands (for `C-x d' and `C-x 4 d') act the same as usual
except when given a non-positive prefix arg.  In that case, you can enter any
number of file or dir names, and a Dired buffer is created for just those files
and dirs.  (A prefix of 0 is both non-positive and non-negative, so it also asks
for switches.)

Also, on MS Windows, you can use wildcards in any of the names.  I submitted a
patch for this feature (or bug fix) for vanilla Emacs, but it still needs a
minor patch for non-Windows (if anyone is interested in contributing that bit).


> From: Drew Adams Sent: Monday, August 30, 2010 11:11 PM
> > > > How can I achieve that? Thanks for any suggestions.
> > >
> > > The command `dired' does not let you do that.  Its 
> > > `interactive' spec just reads a file (directory) name,
> > > possibly with wildcards.
> > >
> > > But function `dired' does let you do that if you call it 
> > > from Lisp - you just need to pass it an explicit list of file
> > > names in place of the directory name.
> > >
> > > So you could write your own command to do what you want.  The
> > > `interactive' spec would, e.g., read file names (possibly with
> > > wildcards) until you enter an empty name ("") - it would 
> > > return a list of the names entered.  The body of the function
> > > would just call `dired', passing the list (with a (pseudo-)
> > > directory name prepended to the file names).
> > 
> > I had a hunch that would be the case. I think I'll try my hand at
> > writing a function like that. Thank you for outlining the basic
> > idea. :) Maybe I can defadvice `dired' to run my function when ever
> > there is a space separated argument, and call regular dired
> > otherwise?
> My recommendation would be to not bother with `defadvice' here and
> just write a new command.  `dired' already does everything you want
> - it is only its `interactive' spec that does not do what you want.
> Just write a new command `foo' whose `interactive' spec calls
> `read-file-name' in a loop until the input is empty, accumulating
> all the file names read in a list. Pass that list of file names to
> `dired' as its (first) arg.  (The list also needs a string at the
> head that names the Dired buffer.)  Something like this:
> (defun foo (files)
>   (interactive
>    (list
>     (let ((insert-default-directory  nil)
>           (files                     ())
>           file)
>       (while (not (string=
>                    ""
>                    (file-name-nondirectory
>                     (setq file  (read-file-name
>                                  "File: " nil nil t)))))
>         (push file files))
>       files)))
>   (dired (cons "A Dir In The Headlights" files)))
> Depending on what you need, you might not want to bind
> `insert-default-directory' to nil.  That prevents the recorded
> file names from explicitly including the default directory.
> If you do bind it to nil, then you don't really need the call to
> `file-name-nondirectory' unless you want to let the user 
> enter absolute as well as relative file names.
> Yes, this kind of Dired buffer can contain a mix of files 
> from different directories.  If a file name is not absolute,
> then the value of `default-directory' for the buffer determines
> its directory.
> Note too that any of the file names read can in fact be 
> directory names.

reply via email to

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