]> git.eshelyaron.com Git - emacs.git/commitdiff
New command kill-matching-buffers kills buffers whose name matches a regexp.
authorSam Steingold <sds@gnu.org>
Sun, 3 Jun 2007 18:51:42 +0000 (18:51 +0000)
committerSam Steingold <sds@gnu.org>
Sun, 3 Jun 2007 18:51:42 +0000 (18:51 +0000)
etc/NEWS
lisp/ChangeLog
lisp/files.el

index 50f4daf796cb1f28f5e834f17b0334cbe56048a4..0c2846bf5b91a2381883236c072b14b51bc83bd8 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -28,6 +28,8 @@ with a prefix argument or by typing C-u C-h C-n.
 \f
 * Editing Changes in Emacs 23.1
 
+** New command kill-matching-buffers kills buffers whose name matches a regexp.
+
 \f
 * New Modes and Packages in Emacs 23.1
 
index baf1400232d0443ae5935d65274358eb2a1bee2c..3d3bf598a7813447492f60a897b5deaf1ad0e746 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-03  Sam Steingold  <sds@gnu.org>
+
+       * files.el (kill-buffer-ask): New function.
+       (kill-some-buffers): Use it.
+       (kill-matching-buffers): New user command.
+
 2007-06-01  David Kastrup  <dak@gnu.org>
 
        * dired.el (dired-recursive-deletes, dired-recursive-copies):
index 9ce1f0a04715d4bdece518861aeb3945956e6650..fc8256ba36e9f27fbf21a3c4b2b027e7f1e12ef6 100644 (file)
@@ -4389,6 +4389,14 @@ This command is used in the special Dired buffer created by
            (message "No files can be recovered from this session now")))
       (kill-buffer buffer))))
 
+(defun kill-buffer-ask (buffer)
+  "Kill buffer if confirmed."
+  (when (yes-or-no-p
+         (format "Buffer %s %s.  Kill? " (buffer-name buffer)
+                 (if (buffer-modified-p buffer)
+                     "HAS BEEN EDITED" "is unmodified")))
+    (kill-buffer buffer)))
+
 (defun kill-some-buffers (&optional list)
   "Kill some buffers.  Asks the user whether to kill each one of them.
 Non-interactively, if optional argument LIST is non-nil, it
@@ -4403,13 +4411,20 @@ specifies the list of buffers to kill, asking for approval for each one."
                                        ; if we killed the base buffer.
           (not (string-equal name ""))
           (/= (aref name 0) ?\s)
-          (yes-or-no-p
-           (format "Buffer %s %s.  Kill? "
-                   name
-                   (if (buffer-modified-p buffer)
-                       "HAS BEEN EDITED" "is unmodified")))
-          (kill-buffer buffer)))
+          (kill-buffer-ask buffer)))
     (setq list (cdr list))))
+
+(defun kill-matching-buffers (regexp &optional internal-too)
+  "Kill buffers whose name matches the specified regexp.
+The optional second argument indicates whether to kill internal buffers too."
+  (interactive "sKill buffers matching this regular expression: \nP")
+  (dolist (buffer (buffer-list))
+    (let ((name (buffer-name buffer)))
+      (when (and name (not (string-equal name ""))
+                 (or internal-too (/= (aref name 0) ?\s))
+                 (string-match regexp name))
+        (kill-buffer-ask buffer)))))
+
 \f
 (defun auto-save-mode (arg)
   "Toggle auto-saving of contents of current buffer.