help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dumb question #143 -- How do I get the *scratch* window back ??


From: Amy Templeton
Subject: Re: Dumb question #143 -- How do I get the *scratch* window back ??
Date: Wed, 02 May 2007 02:15:41 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

William Case wrote:
> I have been inadvertently deleting my "scratch* window.
> How do I get it back?

You can add the following code to your .emacs file (taken
from either the emacs wiki or from some useful person's
website...apologies to whomever is going uncredited here).
The effect of this is to grant you an immortal scratch
buffer. Once killed, it rise from the ashes, albeit empty.
Enjoy!

Code:
_________________________________________________________________

;;; Immortal scratch buffer
(save-excursion
  (set-buffer (get-buffer-create "*scratch*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))

(defun kill-scratch-buffer ()
  ;; Kill the current (*scratch*) buffer
  (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
  (kill-buffer (current-buffer))
  ;; Make a brand new *scratch* buffer
  (set-buffer (get-buffer-create "*scratch*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
  ;; Since we killed it, don't let caller do that.
  nil)
_________________________________________________________________

Amy

P.S.:  You do need to include both the defun and the first
       stanza; the part before the defun adds a hook to your
       current scratch buffer's kill-buffer-query-functions
       which will call the program defined in the defun if
       the buffer is killed, which creates a new scratch
       buffer and adds a hook to your new scratch buffer's
       kill-buffer-query-functions which will call the
       program defined in the defun, which...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]