Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

buffer

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])
like image 480
Adobe Avatar asked Jun 07 '12 10:06

Adobe


People also ask

How do you kill a buffer?

C-x k ( kill-buffer ) kills one buffer, whose name you specify in the minibuffer. The default, used if you type just RET in the minibuffer, is to kill the current buffer. If you kill the current buffer, another buffer becomes current: one that was current in the recent past but is not displayed in any window now.

How to close all buffers in Emacs?

For a more manual approach, you can list all buffers with C-x C-b , mark buffers in the list for deletion with d , and then use x to remove them.


2 Answers

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)))
like image 109
phils Avatar answered Sep 20 '22 07:09

phils


For Emacs version >=24, the kmb.el library from ELPA repository does exactly that with the command kmb-kill-matching-buffers-no-ask.

It also provides the command kmb-delete-process-and-kill-buffer-no-ask, which kills the current buffer (without confirmation).

I bind the latter command as follows:

(global-set-key (kbd "H-M-<delete>") 'kmb-delete-process-and-kill-buffer-no-ask)

so that i don't call it accidentaly, just when i need it.

like image 29
Tino Avatar answered Sep 19 '22 07:09

Tino