all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Suggestions on Emacs's Scratch Buffer.
Date: Sat, 27 Sep 2008 19:32:08 -0700 (PDT)	[thread overview]
Message-ID: <7a4cc56b-debe-452e-8078-2634f9997c93@n33g2000pri.googlegroups.com> (raw)

Xah 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, Chetan <Chetan.xs...@xspam.sbcglobal.net> 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 @@
                             buffer visible-ok frame)
       (get-next-valid-buffer (nreverse (buffer-list frame))
                             buffer visible-ok frame)
-      (progn
-       (set-buffer-major-mode (get-buffer-create "*scratch*"))
-       (get-buffer "*scratch*"))))
+      (get-buffer "*scratch*")
+      (current-buffer)))

 (defun next-buffer ()
   "Switch to the next buffer in cyclic order."

===============
File buffer.c function Fother_buffer.

  if (NILP (buf))
    {
#if 0
      buf = Fget_buffer_create (build_string ("*scratch*"));
      Fset_buffer_major_mode (buf);
#else
      buf = buffer;
#endif
    }
  return buf;

}



                 reply	other threads:[~2008-09-28  2:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=7a4cc56b-debe-452e-8078-2634f9997c93@n33g2000pri.googlegroups.com \
    --to=xahlee@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.
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.