From: "Rancier, Jeffrey" <Jeffrey.Rancier@xerox.com>
To: "B. T. Raven" <nihil@nihilo.net>, <help-gnu-emacs@gnu.org>
Subject: RE: *scratch* lost
Date: Wed, 17 Jun 2009 10:12:53 -0400 [thread overview]
Message-ID: <367290EA0A6BA54DAA91825A93DF8AD20D3A7736@USA0300MS01.na.xerox.net> (raw)
In-Reply-To: <obednUzbxaM2faXXnZ2dnUVZ_oudnZ2d@sysmatrix.net>
[-- Attachment #1: Type: text/plain, Size: 2380 bytes --]
Would the following help?
(require 'protbuf)
(protect-buffer-from-kill-mode nil (get-buffer "*scratch*"))
|-----Original Message-----
|From: help-gnu-emacs-bounces+jeffrey.rancier=xerox.com@gnu.org
|[mailto:help-gnu-emacs-bounces+jeffrey.rancier=xerox.com@gnu.or
|g] On Behalf Of B. T. Raven
|Sent: Wednesday, June 17, 2009 8:25 AM
|To: help-gnu-emacs@gnu.org
|Subject: Re: *scratch* lost
|
|Stefan Kamphausen wrote:
|> Hi Pascal,
|>
|> pjb@informatimago.com (Pascal J. Bourguignon) writes:
|>
|>>> Hm, I don't seem to need that. I can always M-x switch-to-buffer
|>>> *scratch* RET (having to type "*scratch*" without completion since
|>>> it may have been killed) and end up in a perfect
|stracth-buffer with
|>>> lisp-interaction-mode. It even works with iswitchb-buffer which
|>>> asks before creating the new buffer.
|>> Of course, but if you want to insert the initial-scratch-message...
|>
|> OK, I loose that. I understand that it is meant for
|newcomers anyway.
|>
|>> And switch-to-buffer creates a buffer in default-major-mode, not
|>> emacs-lisp-mode.
|>
|> My default-major-mode is fundamental-mode and my scratch buffer is
|> always in lisp-interaction-mode. I tried to find out where
|that comes
|> from but without success. Nothing in auto-mode-alist,
|> magic-mode-alist, interpreter-mode-alist. No configuration
|found with
|> grep -ir lisp-interaction-mode ~/.emacs.d/. Nothing found using
|> apropos-value lisp-interaction-mode. Funny that it, but very handy
|> ;-)
|>
|>
|> Best,
|> Stefan
|
|Thanks for insight, Stefan. My problem was that I had a
|*scratch* buffer sans message, in Fundamental mode immediately
|after restarting Emacs.
|Impossible, no? But it was caused by some anomaly in specifing (via
|custom) 'org-agenda-files and in some way that debug-init
|didn't catch.
|After fixing that, the normal *scratch* was generated spontaneously.
|Also I learned that most of .emacs's (not all) can be gotten
|by evaluating .emacs piecewise after running emac -Q. When I
|was thinking elisp had gone crazy I discovered that I had
|invoked another keyboard (Italian instead of U.S Dvorak) that
|I had neglected to unload after testing something. The whole
|experience was so bizarre that I don't even want to understand
|what happened.
|
|
|Ed
|
[-- Attachment #2: protbuf.el --]
[-- Type: application/octet-stream, Size: 7097 bytes --]
;;; protbuf.el --- protect buffers from accidental killing
;; Copyright (C) 1994, 1999 Noah S. Friedman
;; Author: Noah Friedman <friedman@splode.com>
;; Maintainer: friedman@splode.com
;; Keywords: extensions
;; Status: Works with emacs 19.23 or later.
;; Created: 1994-06-21
;; $Id: protbuf.el,v 1.7 2000/08/21 10:45:38 friedman Exp $
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This package allows you to make it harder to kill buffers accidentally,
;; e.g. by being too trigger happy selecting items in the buffer menu.
;; protect-process-buffer-from-kill-mode is perhaps the more useful of the
;; two, making it harder to accidentally kill shell buffers without
;; terminating the process in them first.
;;; Code:
(defvar protect-buffer-verbose t
"*If non-nil, print a message when attempting to kill a protected buffer.")
(defvar protect-buffer-bury-p t
"*If non-nil, bury buffer when attempting to kill it.
This only has an effect if the buffer to be killed is the one
visible in the selected window.")
\f
;;;###autoload
(defvar protect-buffer-from-kill-mode nil
"*If non-`nil', then prevent buffer from being accidentally killed.
This variable is local to all buffers.")
(progn
(make-variable-buffer-local 'protect-buffer-from-kill-mode)
(put 'protect-buffer-from-kill-mode 'permanent-local t)
(or (assq 'protect-buffer-from-kill-mode minor-mode-alist)
(setq minor-mode-alist (cons '(protect-buffer-from-kill-mode " ProtBuf")
minor-mode-alist))))
;;;###autoload
(defvar protect-process-buffer-from-kill-mode nil
"*If non-`nil', then protect buffer with live process from being killed.
This variable is local to all buffers.")
(progn
(make-variable-buffer-local 'protect-process-buffer-from-kill-mode)
(put 'protect-process-buffer-from-kill-mode 'permanent-local t)
(or (assq 'protect-process-buffer-from-kill-mode minor-mode-alist)
(setq minor-mode-alist
(cons '(protect-process-buffer-from-kill-mode " ProtProcBuf")
minor-mode-alist))))
;;;###autoload
(defvar protect-process-buffer-from-kill-preserve-function nil
"*Function to run to determine whether to kill a process buffer.
If function returns non-nil, buffer is preserved. Otherwise, the buffer
may be killed.
If this variable is undefined, default action is to test whether a process
object is using this buffer as a process buffer.
This variable is buffer-local when set.")
(make-variable-buffer-local 'protect-process-buffer-from-kill-preserve-function)
(put 'protect-process-buffer-from-kill-preserve-function 'permanent-local t)
\f
;;;###autoload
(defun protect-buffer-from-kill-mode (&optional prefix buffer)
"Protect buffer from being killed.
To remove this protection, call this command with a negative prefix argument."
(interactive "P")
(or buffer (setq buffer (current-buffer)))
(save-excursion
;; Each cond does its own set-buffer *after* comparing prefix just in
;; case there's a buffer-local variable `prefix' to screw up the works.
(cond
((null prefix)
(set-buffer buffer)
(setq protect-buffer-from-kill-mode
(not protect-buffer-from-kill-mode)))
((>= prefix 0)
(set-buffer buffer)
(setq protect-buffer-from-kill-mode t))
(t
(set-buffer buffer)
(setq protect-buffer-from-kill-mode nil)))
;; This is always done because kill-buffer-query-functions might have
;; been buffer-local when this package was initially loaded, leaving
;; the global value unchanged.
(add-hook 'kill-buffer-query-functions 'protect-buffer-from-kill)))
;; This function is listed in kill-buffer-query-functions; it should return
;; nil if the buffer should not be killed, t otherwise.
(defun protect-buffer-from-kill ()
(cond
(protect-buffer-from-kill-mode
(and protect-buffer-verbose
(message "Buffer \"%s\" is protected from being killed."
(buffer-name)))
(and protect-buffer-bury-p
(eq (current-buffer)
(window-buffer (selected-window)))
(bury-buffer))
nil)
(t)))
\f
;;;###autoload
(defun protect-process-buffer-from-kill-mode (&optional prefix buffer)
"Protect buffer from being killed as long as it has an active process.
To remove this protection, call this command with a negative prefix argument."
(interactive "P")
(or buffer (setq buffer (current-buffer)))
(save-excursion
;; Each cond does its own set-buffer *after* comparing prefix just in
;; case there's a buffer-local variable `prefix' to screw up the works.
(cond
((null prefix)
(set-buffer buffer)
(setq protect-process-buffer-from-kill-mode
(not protect-process-buffer-from-kill-mode)))
((>= prefix 0)
(set-buffer buffer)
(setq protect-process-buffer-from-kill-mode t))
(t
(set-buffer buffer)
(setq protect-process-buffer-from-kill-mode nil)))
;; This is always done because kill-buffer-query-functions might have
;; been buffer-local when this package was initially loaded, leaving
;; the global value unchanged.
(add-hook 'kill-buffer-query-functions 'protect-process-buffer-from-kill)))
;; This function is listed in kill-buffer-query-functions; it should return
;; nil if the buffer should be protected, t if buffer should be killed.
(defun protect-process-buffer-from-kill ()
(cond
((not protect-process-buffer-from-kill-mode) t)
((or (and (boundp 'protect-process-buffer-from-kill-preserve-function)
protect-process-buffer-from-kill-preserve-function
(funcall protect-process-buffer-from-kill-preserve-function))
(get-buffer-process (current-buffer)))
(and protect-buffer-verbose
(message "Buffer \"%s\" has live process; not killing."
(buffer-name)))
(and protect-buffer-bury-p
(eq (current-buffer)
(window-buffer (selected-window)))
(bury-buffer))
nil)
(t t)))
(add-hook 'kill-buffer-query-functions 'protect-buffer-from-kill)
(add-hook 'kill-buffer-query-functions 'protect-process-buffer-from-kill)
(provide 'protbuf)
;;; protbuf.el ends here
next prev parent reply other threads:[~2009-06-17 14:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-13 16:20 *scratch* lost B. T. Raven
2009-06-13 16:40 ` B. T. Raven
2009-06-15 10:24 ` Pascal J. Bourguignon
2009-06-15 15:31 ` B. T. Raven
2009-06-17 11:03 ` Stefan Kamphausen
2009-06-17 11:36 ` Pascal J. Bourguignon
2009-06-17 11:49 ` Stefan Kamphausen
2009-06-17 12:25 ` B. T. Raven
2009-06-17 14:12 ` Rancier, Jeffrey [this message]
2009-06-17 18:14 ` Johan Bockgård
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=367290EA0A6BA54DAA91825A93DF8AD20D3A7736@USA0300MS01.na.xerox.net \
--to=jeffrey.rancier@xerox.com \
--cc=help-gnu-emacs@gnu.org \
--cc=nihil@nihilo.net \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.