Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Emacs, what's the canonical way to protect vital buffers like *scratch* and *Messages* from ever being killed?

Tags:

emacs

elisp

I was reading this question and the answers are a convoluted mess (timer function REALLY?)

In any case, I don't care about recreating these buffers, as that is trivial. But these buffers contain information which should never be deleted, and because they don't have associated filenames, they are usually killed without confirmation.

I do have a solution in mind, but I want to see if someone has a more "canonical" one.



jtahlborn provided the most canonical solution, except the "keep-buffers" package is showing its age has some issues:

  1. You had to specify whether all protected buffers are to be buried and erased (erased buffers can be recovered with `undo') when killed, or just buried when killed.

  2. member is reimplemented as find-in-list less efficiently.

  3. Helper functions that didn't really help.

I made the the protected-list an alist that associates regexp to erase-action, and deleted the useless (IMO) code. By default, "scratch" is erased when killed, "Messages" is never erased or killed.

See github

like image 458
event_jr Avatar asked Dec 16 '22 09:12

event_jr


1 Answers

You can try adding a function to the kill-buffer-query-functions variable that checks the current buffer, if it is scratch or Messages then return nil. I've never tried this before but it should prevent them from getting killed.

Edit: Here's an example of using kill-buffer-query-functions that allows you to protect specific buffers: http://www.emacswiki.org/emacs/protbuf-by-name.el

like image 156
Jon Lin Avatar answered May 30 '23 07:05

Jon Lin