[Top][All Lists]

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

Re: undo-kill-buffer

From: Stuart D. Herring
Subject: Re: undo-kill-buffer
Date: Wed, 25 Oct 2006 07:37:14 -0700 (PDT)
User-agent: SquirrelMail/1.4.6-7.el3.7lanl

> Yes, i use C-x k .  Mostly it happens when I am doing some development
> that
> happens to involve a large number of files.  Often then I will try to kill
> buffers I'm no longer working with, just to help keep organized or other
> reasons.  Sometimes I'll kill a buffer (file) in this way and a moment
> later
> realize that there is another change I need to make.

I use this when I'm "done with a project":

(defun kill-buffers-by-regexp (REG &optional AUTO)
  "Offer to kill each buffer whose name matches REG.
If AUTO is non-nil, kill all such buffers, prompting only if a buffer needs
  (interactive "MRegexp: \nP")
  (let (to-kill
        (checker (buffer-list)))
    (while checker
      (when (string-match REG (buffer-name (car checker)))
        (if AUTO (kill-buffer (car checker)))
        (push (car checker) to-kill))
      (setq checker (cdr checker)))
    (if to-kill
        (unless AUTO (kill-some-buffers to-kill))
      (error "No matches"))))

It would obviously be trivial to modify it to match on the filename
(including directories, perhaps) rather than the buffer name.

If you really want to be able to see the buffers, another trivial
modification would be to switch to each buffer before killing it (at least
in the AUTO case).  The important thing is to avoid the repetitive C-x k
RET C-x k RET C-x k RET ... that eventually gets you focusing so much on
the keys and so little on the files that you can kill something you'd
rather not.

Otherwise, when I want to be rid of a buffer for now but don't know that I
won't need it again, I use `bury-buffer', which I bind to C-x C-0.  (That
key doesn't exist on terminals, if it matters.)  I find the dabbrev
commands to be particularly useful when I have many relevant files in
buffers, even if I'm not expecting to modify them.

Hope this helps,

This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during

reply via email to

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