28

Here's another, simple alternative that doesn't require recentf. Hooking the first function into kill-buffer-hook will push the filename associated with the buffer onto a list. (Note that, if you kill a buffer that's not visiting a file, it's gone for good.) The latter function pops that file off of the list and visits it: (defvar killed-file-list nil "...


17

Remove the corresponding function from the relevant variable : (setq kill-buffer-query-functions (delq 'process-kill-buffer-query-function kill-buffer-query-functions)) How did I find this ? kill-this-buffer uses kill-buffer internally, which references the variable kill-buffer-query-functions.


8

Or the simpler one would be : (setq kill-buffer-query-functions nil) Inspired from abo-abo config


8

What you want is built-in to emacs. Put (require 'ibuffer) in your config file, then bind a key to 'ibuffer: (global-set-key "\C-x\C-b" 'ibuffer) Be sure to check out its help documentation. It has a lot of features.


8

You can use M-x ibuffer which I recommend binding to C-xC-b to replace the default (or whatever binding you prefer). Use %m to mark buffers by matching a regexp against the displayed mode-name (e.g. Emacs-Lisp). Then use D to kill the marked buffers. "notmuch-" or "[Notmuch]" Note that, as we're dealing with regexps, you would need to ...


5

Test the variable this-command to see whether it is kill-buffer


5

I would like to ask you: “Do you really want to kill it?”. Indeed, killing a buffer is such a common thing in Emacs world, but once killed, buffer is gone, and as your question demonstrates, it's not always desirable. However we can choose another way, so that you never need to restore killed buffer — just prefer burying to killing. Take a look at Kill or ...


5

Based on the other answers and comments, here's a custom kill command that provides the option to diff a modified buffer with the file it is visiting. I've mapped this to C-x C-k but could also remap kill-buffer as suggested in @Drew's answer. (defun my/kill-this-buffer () (interactive) (catch 'quit (save-window-excursion (let (done) (...


5

The big question is whether you want this behavior for kill-buffer itself, which means not only when you call it interactively but for every use of it in existing Lisp code, or whether you want it only for interactive use. I'll assume the latter. In that case, leave kill-buffer alone, define your own command that does what you want, and remap the keys that ...


5

Use the function kill-this-buffer. I basically never want to kill buffers that are not the current buffer, so I rebind C-x k to that function: (global-set-key (kbd "C-x k") #'kill-this-buffer) (Of course, if you ever do wanted to be prompted for a buffer to kill, you can just run M-x kill-buffer, or since you use Helm, kill it from the buffer switcher.)


4

I use this solution from this SO post and it works fine. The solution is elegant but not perfect; it stores a list of active buffers and returns the first file from the the recentf-list that doesn't belong to the list of active buffers. ;; Reopen the last killed buffer ;; Source: https://stackoverflow.com/questions/10394213/emacs-reopen-previous-killed-...


4

For me, using emacsclient with the '-n' switch prevents me from getting the "no client connection" warning. Invoking emacsclient file from the command line will open file in the current Emacs session. The command line from which you ran emacsclient will be waiting for the file to be closed by the server, and then terminate. You won't be able to execute ...


4

Given you have multiple buffers open, use C-x C-b to open the buffer list. You will be given a nice list of all the buffers currently in memory. Make sure you have the current window that displays the buffer list open. Use C-x o to navigate to the aforementioned window. Now you have several options here. First you can mark the specific buffers you want ...


3

(require 'cl) ;; for `copy-list' (let* ((frame-list (frame-list)) (current-frame (selected-frame)) (result (delq nil (mapcar (lambda (frame) (with-selected-frame frame (when (one-window-p) (with-current-buffer (car (buffer-list frame)) (if (...


3

You can iterate over the window-list of each frame in frame-list. Rather than: (delete (current-buffer) (seq-filter #'buffer-file-name (buffer-list))) You could use: (let (buflist) (dolist (frame (frame-list)) (dolist (window (window-list frame t)) (push (window-buffer window) buflist))) (seq-filter (lambda (buf) (...


3

There are multiple ways to specify the key you want to bind. [C-u] doesn't work; if you're supplying a vector, you have to use it a little differently. From that link: In the vector representation, each element of the vector represents an input event, in its Lisp form. See Input Events. For example, the vector [?\C-x ?l] represents the key sequence C-...


3

I think the best way to handle this is to use cl-letf, like so: (require 'cl-lib) (cl-letf (((symbol-function 'yes-or-no-p) #'y-or-n-p)) (let* ((filename "~/private/tmp/foofile") (buf (get-buffer-create "*foo*"))) (with-current-buffer buf (write-file filename) (insert "Every good boy deserves fudge.")) (kill-buffer buf) (...


3

just in case I decide to exit out of the function with a 'quit signal such as C-g, in which case the effect would become long-lasting rather than merely temporary. This can be solved with unwind-protect. The following function always restores yes-or-no-p's definition at the end even if you quit in the middle of it: (defun my/kill-buffer () (interactive) ...


3

Advice kill-buffer: (defun yes-or-no-p->-y-or-n-p (orig-fun &rest r) (cl-letf (((symbol-function 'yes-or-no-p) #'y-or-n-p)) (apply orig-fun r))) (advice-add 'kill-buffer :around #'yes-or-no-p->-y-or-n-p) or advice yes-or-no-p (defun yes-or-no-p@maybe-just-y-or-n-p (orig-fun prompt) (funcall (if (eq this-command 'kill-buffer) #'...


3

You need to turn on recentf-mode. To do that, run M-x recentf-mode. Then, the function might not work until you open or kill some new buffers; I don't think you'll have recentf-list filled out. If you want this to be enabled when Emacs starts up, put this in your init file: (recentf-mode) You can then put the defun you found in there, and bind it to a key,...


3

This answer takes the other answers and the comments into account, offering better ways of doing the same things. Your original question was about deleting the diff buffer after committing, though the other answers concentrated on doing something when quitting the status buffer. So I will do that first too, but later also tell you how to do something when ...


3

(defun my-delete-backward-word () (interactive "*") (push-mark) (backward-word) (delete-region (point) (mark)))


3

When you have moved to the buffer-list (made it active), press g. This will update this buffer and the buffers that have already been deleted will disappear from the list, just the list does not automatically update when you call it, but it shows it is already open


3

You can do this with Helm by entering a partial major-mode name prefixed with *. For example: *lisp, *sh etc. You can also use negation, e.g. !*org to narrow down all non-Org mode buffers, or specify multiple major modes, e.g. *!lisp,!sh,!fun etc. Then press M-a to mark those buffers and M-D to kill them. For example, to kill all dired buffers: M-x helm-...


2

I made it slightly different (but the previous answers helped me a lot, thanks guys), to avoid string matching. I modified the "new-empty-buffer" function suggested by Xah Lee from ErgoEmacs, making it set a local-variable 'custom-scratch-buffer when the buffer is created. Therefore, we know when the buffer is a scratch buffer created by this function and ...


2

I guess much of this is a matter of taste and usage patterns. I tend to use something inbetween your solution and @Drew's usage (according to the comments). Here is the gist of it: I want "throwaway" buffers to be quickly available, without having to think ahead of time where to save them; I want them to be file buffers in order for Emacs to warn me if I ...


2

EDIT: I didn't pay attention when answering, and answered something else the OP didn't ask. Once again, I'm sorry. Thank you for your words, @CodyChan. Well, I'm no Emacs veteran, and maybe this possibly has became available just on recent versions. I know I'm coming some years later, but maybe it can be helpful for others, since my search got me here. I'...


2

After googling around and tweaking the code snippets from the internet, I got this solution and it works as expected: (defvar all-gud-modes '(gud-mode comint-mode gdb-locals-mode gdb-frames-mode gdb-breakpoints-mode) "A list of modes when using gdb") (defun kill-all-gud-buffers () "Kill all gud buffers including Debugger, Locals, Frames, Breakpoints. ...


2

Another attempt at explaining the situation: (let ((buf "*Async Shell Command*")) (async-shell-command "cat") (while (let ((bp (get-buffer-process buf))) (message "status: %s" (process-status bp)) bp) (message "still has proc") (kill-process (get-buffer-process buf)) (accept-process-output) (message "Letting emacs ...


2

As mentioned, Ibuffer (ibuffer) and Buffer Menu (buffer-menu) are the closest to a Dired-like interface. But you can also list and act on multiple buffers using just completion. With Icicles, commands that show you buffer names for completion let you use S-<delete> on any number of them to kill those buffer. Similarly, C-x k (icicle-kill-buffer, in ...


Only top voted, non community-wiki answers of a minimum length are eligible