From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Filtering files in dired while invoking Date: Mon, 30 Aug 2010 23:10:42 -0700 Message-ID: <98DBECF724AA424EA9030AD92CF1F90D@us.oracle.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1283235153 30649 80.91.229.12 (31 Aug 2010 06:12:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 31 Aug 2010 06:12:33 +0000 (UTC) To: "'suvayu ali'" , "'Emacs mailing list'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 31 08:12:32 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OqK57-0001tD-3j for geh-help-gnu-emacs@m.gmane.org; Tue, 31 Aug 2010 08:12:29 +0200 Original-Received: from localhost ([127.0.0.1]:34436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OqK55-0006aP-QI for geh-help-gnu-emacs@m.gmane.org; Tue, 31 Aug 2010 02:12:27 -0400 Original-Received: from [140.186.70.92] (port=39882 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OqK4P-0006aJ-Ky for help-gnu-emacs@gnu.org; Tue, 31 Aug 2010 02:11:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OqK4O-0001dg-JT for help-gnu-emacs@gnu.org; Tue, 31 Aug 2010 02:11:45 -0400 Original-Received: from rcsinet10.oracle.com ([148.87.113.121]:21341) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OqK4O-0001dX-Dm for help-gnu-emacs@gnu.org; Tue, 31 Aug 2010 02:11:44 -0400 Original-Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o7V6Bdl2001246 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 31 Aug 2010 06:11:41 GMT Original-Received: from acsmt354.oracle.com (acsmt354.oracle.com [141.146.40.154]) by rcsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o7TN43td016549 for ; Tue, 31 Aug 2010 06:11:38 GMT Original-Received: from abhmt015.oracle.com by acsmt353.oracle.com with ESMTP id 547221671283235043; Mon, 30 Aug 2010 23:10:43 -0700 Original-Received: from dradamslap1 (/10.159.220.154) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Aug 2010 23:10:42 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: ActInNZwj2YYA0dlTT2flb5Kqud1hgAMAm0g X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:74839 Archived-At: > > > 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.