Suggestions on Emacs's Scratch Buffer.

Suggestions on Emacs's Scratch Buffer.

Post by Xah » Mon, 29 Sep 2008 11:32:08


ah Lee wrote:

Suggestions on Emacs's Scratch Buffer.
http://xahlee.org/emacs/modernization_scratch_buffer.html


Chetan wrote:
pasted below my sig

Hi Chetan,

Could you give a summary english what does your changes achieve at the
user level?

or how it differs from the proposal and the code that comes with it?

Thanks for your code. I see even C code... i don't know C.

Xah
http://xahlee.org/



On Sep 27, 5:42 am, Cheta< < XXXX@XXXXX.COM >t> wrote:
Here are my changes.

;;; Buffer created by this function is a temp buffer. It has no auto-
save. It is saved by
;;; save-some-buffers only with prefix argument, will not be saved by
M-x compile etc.
(defun create-new-buffer(name &optional scratch)
"Generate a new buffer with the specified name in default major
mode. There is no auto save for this buffer until a file name is
specified. The optional argument scratch specifies if the buffer is
for scratch purposes and will not be deleted."
(let ((buf (generate-new-buffer name)))
(set-buffer-major-mode buf)
(switch-to-buffer buf)
(setq buffer-offer-save (not scratch))))

;;; save-some-buffers C-x s will not save it
;;; save-buffer C-x C-s will ask for a file name if not specified
;;; no auto save since there is no recovery
(defun new-buffer(&optional name mode)
"Create a new buffer that can be saved later to a file."
(interactive)
(let ((default-major-mode (or mode 'text-mode)))
(create-new-buffer (or (stringp name) "Untitled")))
(add-hook 'kill-buffer-query-functions 'buffer-kill-query nil t))

(defun new-scratch-buffer(&optional arg)
"Create a new temporary buffer."
(interactive)
(create-new-buffer "*scratch*" t))

(defun choice (msg possibilities)
(let ((cursor-in-echo-area t) nmsg answer)
(while (not (memq answer possibilities))
(setq nmsg (format "%s [%s] " msg
(mapconcat (function (lambda(x) (char-to-
string (downcase x)))) possibilities "/")))
(cond (t
(message "%s" (propertize nmsg 'face 'minibuffer-prompt))
(setq answer (capitalize (read-char-exclusive))))
(nil
(setq answer (capitalize (string-to-char (read-from-
minibuffer nmsg)))))))
answer))

(defun buffer-kill-choice (msg)
(let ((possibilities (list ?C ?K ?S)) answer ev)
(setq answer (choice msg possibilities))
(cond ((eq answer ?C) (message "Buffer retained.") nil)
((eq answer ?K) t)
((eq answer ?S) (save-buffer) t))))

(defun buffer-kill-query ()
(cond ((and buffer-offer-save
(buffer-modified-p))
(cond ((and (null buffer-file-name)
>(> (buffer-size) 0))
(buffer-kill-choice (format "Buffer %s has not been
saved to a file. Cancel/Kill/Save?"
(buffer-name))))
(t t)))
(t t)))

(when (featurep 'menu-bar)
(setq menu-bar-buffers-menu-command-entries
(append menu-bar-buffers-menu-command-entries
(list (list 'new-buffer
'menu-item
"Create New Buffer"
'new-buffer
:help "Create a new buffer and select it
in the current window")))))

;;; end

===============
Diff -U3 from 22.3 version of file

--- simple.org.el
+++ simple.el
@@ -90,9 +90,8 @
 
 
 

1. Start emacs with a blank buffer - no *scratch*

2. disabling automatic generation of scratch buffer as current buffer

hi all,

whenever I use Xemacs to open up one or more documents, xemacs launches
a new frame, opens up my specified document(s), then opens up a scratch
buffer and sets that scratch buffer to be the current buffer. I never
saw this behavior up until a few months ago when I upgraded Xemacs. I
now have to go to Buffers and actively kill the scratch buffer every
time I open up a document with Xemacs. Is there any way to prevent
Xemacs automatically opening up a scratch buffer and setting that
scratch buffer as the current buffer whenever I open a document ? If
this is not possible, is there a way to automatically kill the current
buffer if it's the scratch buffer whenever I open up a document ?

3. emacs sql-mode interacting with emacs telnet buffer

4. Carbon emacs (OSX) & /usr/bin/emacs using the same .emacs

5. How to lose the "splash screen" and the note in the scratch buffer ?

6. Q: How to construct buffer zones from scratch?

7. startup with empty scratch buffer

8. How to lose the "splash screen" and the note in the scratch buffer ?

9. How to lose the "splash screen" and the note in the scratch buffer ?

10. Emacspeak, festival and Buffer scratch has no process

11. Q: How to construct buffer zones from scratch?

12. resizing scratch buffer

13. Emacspeak, festival and Buffer scratch has no process

14. Emacs/Vim style buffer/window switching