unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Amy Templeton <amy.g.templeton@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Dumb question #143 -- How do I get the *scratch* window back ??
Date: Wed, 02 May 2007 02:15:41 -0400	[thread overview]
Message-ID: <87lkg7hhte.fsf@gmail.com> (raw)
In-Reply-To: <1178078755.3157.54.camel@CASE> (William Case's message of "Wed\, 02 May 2007 00\:05\:55 -0400")

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

  parent reply	other threads:[~2007-05-02  6:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-02  4:05 Dumb question #143 -- How do I get the *scratch* window back ?? William Case
2007-05-02  4:11 ` Eric Hanchrow
2007-05-02 13:21   ` Stephen Berman
2007-05-02 14:06     ` William Case
2007-05-02  6:15 ` Amy Templeton [this message]
     [not found] <mailman.73.1178079170.32220.help-gnu-emacs@gnu.org>
2007-05-02  7:47 ` Thien-Thi Nguyen
2007-05-02 14:08   ` William Case
     [not found]   ` <mailman.100.1178115299.32220.help-gnu-emacs@gnu.org>
2007-05-02 19:47     ` Thien-Thi Nguyen
2007-05-02 23:14       ` weber
2007-05-03  0:18         ` Mark Elston
2007-05-03 17:55           ` William Case
     [not found]           ` <mailman.184.1178215341.32220.help-gnu-emacs@gnu.org>
2007-05-04  3:31             ` weber
2007-05-04  4:16               ` William Case
     [not found]               ` <mailman.204.1178252610.32220.help-gnu-emacs@gnu.org>
2007-05-04 18:11                 ` Mark Elston
2007-05-03  2:32         ` William Case

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lkg7hhte.fsf@gmail.com \
    --to=amy.g.templeton@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).