From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Schierl Newsgroups: gmane.emacs.help Subject: Re: [Q] Several emacs instances / dired and "derived" buffers Date: Fri, 18 Jun 2004 10:32:39 +0200 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <40BD062A.7070205@yahoo.com> Reply-To: schierlm@gmx.de NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: sea.gmane.org 1088536803 21251 80.91.224.253 (29 Jun 2004 19:20:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 29 Jun 2004 19:20:03 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 29 21:19:48 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BfO8x-0005ow-00 for ; Tue, 29 Jun 2004 21:19:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BfOAd-0002jl-Qx for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jun 2004 15:21:31 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-X-Trace: news.uni-berlin.de yrh8rDL4LMaSWpWcMlIBYwEPfVCrq8FQnSwoqQ2Pkq+IMq7Xc= User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (windows-nt) Cancel-Lock: sha1:UAMt2cepc2zfDJrBHSonDbaFHz4= Original-Xref: shelby.stanford.edu gnu.emacs.help:123830 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:19189 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:19189 Kevin Rodgers writes: > Michael Schierl wrote: > > "Ames Andreas (MPA/DF)" writes: > >> if there isn't someone who has already written a command that > >> closes all buffers which are visiting files below a given > >> directory. > > > > Quick&dirty solution: > > > > (defun close-all-buffers-below (dir) > > (interactive "DDirectory: ") > > (mapc '(lambda (buf) (if (and (buffer-file-name buf) > > (string= dir > > (substring (buffer-file-name buf) > > 0 > > (length dir)))) > > (kill-buffer buf))) > > (buffer-list))) After some testing: that solution throws an error if a file name is shorter than the given directory name. e.g. when you close all files below c:/program files/my projects/foo/ and have a file open in c:/autoexec.bat. Seems that Emacs' substring function throws an error if the string is shorter than TO. (I expected it to return the substring from FROM to the end of the string then...) > If dir is "/foo/bar", won't that delete all buffers visiting files under > "/FoO/bAr" (because string= ignores case) If string= ignored case, that would not be any problem, since both me and the OP are using Windows ;-) > and "/foo/bar1" (because you > ignore all characters after "/foo/bar") etc. as well? If you use the autocompletion feature, dir will always end with a slash. Of course you could adjust it to add the slash manually if ther is no one yet. > (mapc (lambda (buf) > (let ((file (buffer-file-name buf))) > (when (and file > (equal (file-name-directory file) dir)) > (kill-buffer buf)))) > (buffer-list)) That one only closes all files *in* a directory and not *below* a directory. If you specify to close all files below "/foo/bar", a file like "/foo/bar/src/package/subpackage/blah/Classname.java" will not be closed as well. Michael