help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: [Q] Several emacs instances / dired and "derived" buffers


From: Michael Schierl
Subject: Re: [Q] Several emacs instances / dired and "derived" buffers
Date: Fri, 18 Jun 2004 10:32:39 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (windows-nt)

Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Michael Schierl wrote:
>  > "Ames Andreas (MPA/DF)" <Andreas.Ames@tenovis.com> 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


reply via email to

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