How do I answer y automatically (kill-matching-buffers asks if I should kill a modified buffer)?

buffer, emacs

Solution

How do I answer y automatically (kill-matching-buffers asks if I should kill a modified buffer)?

`kill-matching-buffers` calls `kill-buffer-ask` which calls `yes-or-no-p`. You could temporarily redefine the latter, but for safety reasons I am inclined not to do that -- killing a given buffer could trigger other functionality which needs to ask a yes-or-no question.

Redefining `kill-buffer-ask` seems a safer bet (or simply copying and modifying the `kill-matching-buffers` function itself).

(require 'cl)
(defun bk-kill-buffers (regexp)
  "Kill buffers matching REGEXP without asking for confirmation."
  (interactive "sKill buffers matching this regular expression: ")
  (flet ((kill-buffer-ask (buffer) (kill-buffer buffer)))
    (kill-matching-buffers regexp)))

Problem

In Emacs - how do I kill buffers matching regexp? Edit: How do I answer `y` automatically (`kill-matching-buffers` asks if I should kill a modified buffer)? Something like this? ``` (defun bk-kill-buffers (bfrRgxp) (interactive) (kill-matching-buffers bfrRgxp) [return]) ```

Original source