[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: |
Mon, 30 Aug 2010 23:10:42 -0700 |
> > > 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.