28 votes
Accepted

How to reopen just killed buffer, like C-S-t in Firefox Browser?

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 ...
user avatar
  • 31.1k
17 votes
Accepted

Kill process buffer without confirmation?

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-...
user avatar
  • 3,361
8 votes

Kill process buffer without confirmation?

Or the simpler one would be : (setq kill-buffer-query-functions nil) Inspired from abo-abo config
user avatar
  • 604
8 votes
Accepted

Dired-like browser for buffers?

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 ...
user avatar
  • 1,279
8 votes
Accepted

How can I kill buffers based on mode?

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. ...
user avatar
  • 43.8k
5 votes
Accepted

Detect interactive use of `kill-buffer` in `kill-buffer-hook`

Test the variable this-command to see whether it is kill-buffer
user avatar
  • 43.8k
5 votes
Accepted

Kill-buffer prompt with option to diff the changes

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 ...
user avatar
  • 19.4k
5 votes

Kill-buffer prompt with option to diff the changes

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 ...
user avatar
  • 70.2k
5 votes

How to reopen just killed buffer, like C-S-t in Firefox Browser?

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 ...
user avatar
  • 4,793
5 votes

Kill default buffer (with cursor)

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 ...
user avatar
  • 4,612
5 votes
Accepted

Removing buffers from buffer list

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 ...
user avatar
4 votes

How to reopen just killed buffer, like C-S-t in Firefox Browser?

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 ...
user avatar
  • 24.3k
4 votes
Accepted

server-edit vs kill-buffer to kill an emacsclient buffer

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....
user avatar
  • 196
3 votes
Accepted

How modify this function, that it will detect the visibile buffers in all windows?

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) (...
user avatar
  • 43.8k
3 votes
Accepted

How to override default keybindings?

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,...
user avatar
  • 8,629
3 votes
Accepted

How to kill all duplicates of the current frame

(require 'cl) ;; for `copy-list' (let* ((frame-list (frame-list)) (current-frame (selected-frame)) (result (delq nil (mapcar (lambda (frame) ...
user avatar
  • 17.8k
3 votes

How to reopen just killed buffer, like C-S-t in Firefox Browser?

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 ...
user avatar
  • 8,629
3 votes

How to reopen just killed buffer, like C-S-t in Firefox Browser?

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 ...
user avatar
3 votes

kill-buffer with y-or-n-p instead of yes-or-no-p

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-...
user avatar
  • 2,604
3 votes

kill-buffer with y-or-n-p instead of yes-or-no-p

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-...
user avatar
  • 383
3 votes
Accepted

kill-buffer with y-or-n-p instead of yes-or-no-p

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-...
user avatar
  • 13.7k
3 votes
Accepted

How to kill magit-diff's buffers on quit?

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 ...
user avatar
  • 24.4k
3 votes
Accepted

Delete word backward without coping it to buffer

(defun my-delete-backward-word () (interactive "*") (push-mark) (backward-word) (delete-region (point) (mark)))
user avatar
3 votes

Removing buffers from buffer list

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 ...
user avatar
  • 59
3 votes
Accepted

How to automatically kill a shell buffer when the shell process exits

Use a process sentinel when you want to react to a process exiting. e.g.: Refer to C-hig (elisp)Sentinels In this case shell only calls shell-mode when (and after) starting the inferior process, so ...
user avatar
  • 43.8k
3 votes

Killing current buffer reliably

You can use the function kill-current-buffer from simple.el. The docstring says: kill-current-buffer is an interactive compiled Lisp function in ‘simple.el’. (kill-current-buffer) Kill ...
user avatar
  • 4,612
3 votes

How can I kill buffers based on mode?

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 ...
user avatar
  • 3,494
3 votes

How to automatically open the debugger whenever `kill-buffer` is invoked?

M-x debug-on-entry kill-buffer That opens the standard Emacs debugger whenever kill-buffer is invoked. It doesn't matter that it's a built-in (primitive, not coded in Lisp). See the Elisp manual, ...
user avatar
  • 70.2k
3 votes
Accepted

Kill buffers in *Buffer List* by file path

I join others in recommending Ibuffer, which is similar to the classic buffer list (Buffer Menu mode) but has a lot more features. (That's if you're not using something even fancier like Ido or Helm.) ...
user avatar
2 votes

Rename scratch buffer and ask confirmation to kill non-file buffers created by user

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 ...
user avatar

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