all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Schierl <schierlm-usenet@gmx.de>
Subject: Re: [Q] Several emacs instances / dired and "derived" buffers
Date: Fri, 18 Jun 2004 10:32:39 +0200	[thread overview]
Message-ID: <wkfz8t9sgo.fsf@smsoft.ixy.de> (raw)
In-Reply-To: 40BD062A.7070205@yahoo.com

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

  parent reply	other threads:[~2004-06-18  8:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7759.1085670886.1061.help-gnu-emacs@gnu.org>
2004-05-27 16:15 ` [Q] Several emacs instances / dired and "derived" buffers Barry Margolin
     [not found] ` <wkaczo1rjv.fsf@smsoft.ixy.de>
     [not found]   ` <40BD062A.7070205@yahoo.com>
2004-06-18  8:32     ` Michael Schierl [this message]
2004-06-21 15:13       ` Kevin Rodgers
2004-05-27 10:22 Ames Andreas (MPA/DF)
2004-05-29 12:11 ` Kai Grossjohann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wkfz8t9sgo.fsf@smsoft.ixy.de \
    --to=schierlm-usenet@gmx.de \
    --cc=schierlm@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.