all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Filtering files in dired while invoking
@ 2010-08-30 19:26 suvayu ali
  2010-08-30 20:19 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: suvayu ali @ 2010-08-30 19:26 UTC (permalink / raw)
  To: Emacs mailing list

Hi,

I was trying to filter the files listed in a dired buffer. Filtering
with one shell glob works fine, but how do I pass multiple shell globs
to dired?

What I 'm looking for is to list files as they would be listed by,

$ ls -l *.C *.h *.cxx

I couldn't find any reference to this in the info manual. But the
docstring for dired says this,

      (dired DIRNAME &optional SWITCHES)

      .....
      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.
      .....

How can I achieve that? Thanks for any suggestions.

-- 
Suvayu

Open source is the future. It sets us free.



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

* RE: Filtering files in dired while invoking
  2010-08-30 19:26 Filtering files in dired while invoking suvayu ali
@ 2010-08-30 20:19 ` Drew Adams
  2010-08-30 23:40 ` suvayu ali
  2010-08-31 12:17 ` Lei Wang
  2 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2010-08-30 20:19 UTC (permalink / raw)
  To: 'suvayu ali', 'Emacs mailing list'

> I was trying to filter the files listed in a dired buffer. Filtering
> with one shell glob works fine, but how do I pass multiple shell globs
> to dired?
> 
> What I 'm looking for is to list files as they would be listed by,
> 
> $ ls -l *.C *.h *.cxx

`C-x d *.[Chc]*' gets you part-way there.

> I couldn't find any reference to this in the info manual. But the
> docstring for dired says this,
> 
>       (dired DIRNAME &optional SWITCHES)
> 
>       .....
>       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.
>       .....
> 
> 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).

However, you can often do what you want to do using marking or omitting instead.
See `dired-omit-mode' in dired-x.el, for example.  If you use Dired+, then you
can combine marking and omitting - omit all of the marked or unmarked files, for
instance.

Marking files is the single most useful thing you can do in Dired.  You can mark
files that match a regexp (`%m'), and so on.  And you can of course mark some
files matching one pattern and then mark some more by matching another pattern.

With one or more 3rd-party features you can also bookmark or save a Dired
listing persistently, so you don't have to remark files from scratch each time.

These links might help:
http://www.emacswiki.org/emacs/DiredPlus
http://www.emacswiki.org/emacs/BookmarkPlus
http://www.emacswiki.org/emacs/Icicles_-_Dired_Enhancements
http://www.emacswiki.org/emacs/CategoryDirectories




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

* Re: Filtering files in dired while invoking
  2010-08-30 19:26 Filtering files in dired while invoking suvayu ali
  2010-08-30 20:19 ` Drew Adams
@ 2010-08-30 23:40 ` suvayu ali
  2010-08-31  6:10   ` Drew Adams
  2010-08-31 12:17 ` Lei Wang
  2 siblings, 1 reply; 10+ messages in thread
From: suvayu ali @ 2010-08-30 23:40 UTC (permalink / raw)
  To: Emacs mailing list

Hi Drew,

> > I was trying to filter the files listed in a dired
> > buffer. Filtering with one shell glob works fine, but how do I
> > pass multiple shell globs to dired?  What I 'm looking for is to
> > list files as they would be listed by, $ ls -l *.C *.h *.cxx
>
> `C-x d *.[Chc]*' gets you part-way there.

Thank you, don't know why this didn't strike me as a solution. :)

> > I couldn't find any reference to this in the info manual. But the
> > docstring for dired says this,
> >
> >       (dired DIRNAME &optional SWITCHES)
> >
> >       .....
> >       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.
> >       .....
> >
> > 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?

> However, you can often do what you want to do using marking or
> omitting instead.  See `dired-omit-mode' in dired-x.el, for example.
> If you use Dired+, then you can combine marking and omitting - omit
> all of the marked or unmarked files, for instance.
>
> Marking files is the single most useful thing you can do in Dired.
> You can mark files that match a regexp (`%m'), and so on.  And you
> can of course mark some files matching one pattern and then mark
> some more by matching another pattern.
>

I was actually doing something similar for now, I was marking the
files, toggling the marks and then killing the lines with `k'.

> With one or more 3rd-party features you can also bookmark or save a
> Dired listing persistently, so you don't have to remark files from
> scratch each time.
>
> These links might help:
> http://www.emacswiki.org/emacs/DiredPlus
> http://www.emacswiki.org/emacs/BookmarkPlus
> http://www.emacswiki.org/emacs/Icicles_-_Dired_Enhancements
> http://www.emacswiki.org/emacs/CategoryDirectories

These sound very neat. I had actually tried out icicles at some point,
but I was a too much of a beginner back then and was rather
overwhelmed. :-p I will give those another shot.

Thanks for the wonderful suggestions. :)

PS: I have noticed this before, for some reason most of your replies
don't arrive in my mailbox and I end up reading them from the archive!
And since the "reply-to" button in the archive is broken, I have to copy paste
your response inside my response. My reply will probably show up in
the wrong place of the thread. Probably some problem at my end, Oh
well :-/

-- 
Suvayu

Open source is the future. It sets us free.



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

* RE: Filtering files in dired while invoking
  2010-08-30 23:40 ` suvayu ali
@ 2010-08-31  6:10   ` Drew Adams
  2010-08-31  6:18     ` OT (was: Filtering files in dired while invoking) Drew Adams
  2010-09-27  1:33     ` Filtering files in dired while invoking Drew Adams
  0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2010-08-31  6:10 UTC (permalink / raw)
  To: 'suvayu ali', 'Emacs mailing list'

> > > 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.

> > However, you can often do what you want to do using marking or
> > omitting instead.  See `dired-omit-mode' in dired-x.el, for example.
> > If you use Dired+, then you can combine marking and omitting - omit
> > all of the marked or unmarked files, for instance.
> >
> > Marking files is the single most useful thing you can do in Dired.
> > You can mark files that match a regexp (`%m'), and so on.  And you
> > can of course mark some files matching one pattern and then mark
> > some more by matching another pattern.
> 
> I was actually doing something similar for now, I was marking the
> files, toggling the marks and then killing the lines with `k'.

Yes, that's good too.  But you usually don't really need to remove any lines,
unless they distract you. Typically you can just act on the marked files,
ignoring the unmarked.  

> PS: I have noticed this before, for some reason most of your replies
> don't arrive in my mailbox and I end up reading them from the archive!

Dunno why, but I got a cannot-deliver return from the mailman for my reply to
you.  For some reason, your mail address did not work - from my end at least.




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

* OT  (was: Filtering files in dired while invoking)
  2010-08-31  6:10   ` Drew Adams
@ 2010-08-31  6:18     ` Drew Adams
  2010-09-27  1:33     ` Filtering files in dired while invoking Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2010-08-31  6:18 UTC (permalink / raw)
  To: 'suvayu ali', 'Emacs mailing list'

> > PS: I have noticed this before, for some reason most of your replies
> > don't arrive in my mailbox and I end up reading them from 
> the archive!
> 
> Dunno why, but I got a cannot-deliver return from the mailman 
> for my reply to you.  For some reason, your mail address did
> not work - from my end at least.

FYI - Here's the mail-problem message I get back.  Dunno if it's a problem from
my mail client or from a mail server.

Diagnostic-Code: SMTP;
 555 5.5.4 XDETAIL parameter unrecognized




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

* Re: Filtering files in dired while invoking
  2010-08-30 19:26 Filtering files in dired while invoking suvayu ali
  2010-08-30 20:19 ` Drew Adams
  2010-08-30 23:40 ` suvayu ali
@ 2010-08-31 12:17 ` Lei Wang
  2010-08-31 17:40   ` suvayu ali
  2 siblings, 1 reply; 10+ messages in thread
From: Lei Wang @ 2010-08-31 12:17 UTC (permalink / raw)
  To: suvayu ali; +Cc: Emacs mailing list

On 8/31/10, suvayu ali <fatkasuvayu+linux@gmail.com> wrote:
> Hi,
>
> I was trying to filter the files listed in a dired buffer. Filtering
> with one shell glob works fine, but how do I pass multiple shell globs
> to dired?
>
> What I 'm looking for is to list files as they would be listed by,
>
> $ ls -l *.C *.h *.cxx
>
> I couldn't find any reference to this in the info manual. But the
> docstring for dired says this,
>
>       (dired DIRNAME &optional SWITCHES)
>
>       .....
>       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.
>       .....
>
> How can I achieve that? Thanks for any suggestions.
>
> --
> Suvayu
>
> Open source is the future. It sets us free.
>
>

Why not use `find-name-dired' or write your function on basis of it?
--
Regards,
Lei



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

* Re: Filtering files in dired while invoking
       [not found] <AANLkTi=3DFkTuuj8U358Sr6_tHUsEK+6yCPoHB32nL6bK_@mail.gmail.com>
@ 2010-08-31 15:28 ` Ehud Karni
  2010-08-31 17:33   ` suvayu ali
  0 siblings, 1 reply; 10+ messages in thread
From: Ehud Karni @ 2010-08-31 15:28 UTC (permalink / raw)
  To: fatkasuvayu+linux; +Cc: help-gnu-emacs

On Mon, 30 Aug 2010 12:26:58 suvayu ali wrote:
>
> What I 'm looking for is to list files as they would be listed by,
>
> $ ls -l *.C *.h *.cxx

The way to it in Emacs is to use {}.
In your case it will be {*.C,*.h,*.cxx} or *.{C,h,cxx}.

BTW. It is not an Emacs thing, but a shell one,
     i.e. you can write ls -al *.{jpg,gif,pcx}
     See the Bash man page under "Brace Expansion".

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7976-561  \ /  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] 10+ messages in thread

* Re: Filtering files in dired while invoking
  2010-08-31 15:28 ` Ehud Karni
@ 2010-08-31 17:33   ` suvayu ali
  0 siblings, 0 replies; 10+ messages in thread
From: suvayu ali @ 2010-08-31 17:33 UTC (permalink / raw)
  To: ehud; +Cc: help-gnu-emacs

On 31 August 2010 08:28, Ehud Karni <ehud@unix.mvs.co.il> wrote:
> On Mon, 30 Aug 2010 12:26:58 suvayu ali wrote:
>>
>> What I 'm looking for is to list files as they would be listed by,
>>
>> $ ls -l *.C *.h *.cxx
>
> The way to it in Emacs is to use {}.
> In your case it will be {*.C,*.h,*.cxx} or *.{C,h,cxx}.
>
> BTW. It is not an Emacs thing, but a shell one,
>     i.e. you can write ls -al *.{jpg,gif,pcx}
>     See the Bash man page under "Brace Expansion".
>

Thank you! I wasn't aware of this bash feature. :-p To get similar
behaviour I have extended globing turned on, but that doesn't won't
work with dired.

> Ehud.
>

-- 
Suvayu

Open source is the future. It sets us free.



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

* Re: Filtering files in dired while invoking
  2010-08-31 12:17 ` Lei Wang
@ 2010-08-31 17:40   ` suvayu ali
  0 siblings, 0 replies; 10+ messages in thread
From: suvayu ali @ 2010-08-31 17:40 UTC (permalink / raw)
  To: Lei Wang; +Cc: Emacs mailing list

On 31 August 2010 05:17, Lei Wang <f3d27b@gmail.com> wrote:
>
> Why not use `find-name-dired' or write your function on basis of it?

I don't think that will work either. My problem was I wanted to give
multiple globs. As far as I know the -name flag for find, doesn't
accept more than one glob.

However Ehud's solution works fine. :) I might still try out Drew's
suggestions just for fun though.

> --
> Regards,
> Lei
>

-- 
Suvayu

Open source is the future. It sets us free.



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

* RE: Filtering files in dired while invoking
  2010-08-31  6:10   ` Drew Adams
  2010-08-31  6:18     ` OT (was: Filtering files in dired while invoking) Drew Adams
@ 2010-09-27  1:33     ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2010-09-27  1:33 UTC (permalink / raw)
  To: 'suvayu ali', 'Emacs mailing list'

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).

HTH.

> 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.




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

end of thread, other threads:[~2010-09-27  1:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-30 19:26 Filtering files in dired while invoking suvayu ali
2010-08-30 20:19 ` Drew Adams
2010-08-30 23:40 ` suvayu ali
2010-08-31  6:10   ` Drew Adams
2010-08-31  6:18     ` OT (was: Filtering files in dired while invoking) Drew Adams
2010-09-27  1:33     ` Filtering files in dired while invoking Drew Adams
2010-08-31 12:17 ` Lei Wang
2010-08-31 17:40   ` suvayu ali
     [not found] <AANLkTi=3DFkTuuj8U358Sr6_tHUsEK+6yCPoHB32nL6bK_@mail.gmail.com>
2010-08-31 15:28 ` Ehud Karni
2010-08-31 17:33   ` suvayu ali

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.