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

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

Re: Emacs ignores modified state of "untitled" buffer


From: Kevin Rodgers
Subject: Re: Emacs ignores modified state of "untitled" buffer
Date: Fri, 21 May 2010 07:17:25 -0600
User-agent: Thunderbird 2.0.0.24 (Macintosh/20100228)

Stefan Vollmar wrote:
I have now tried:

http://lists.gnu.org/archive/html/gnu-emacs-sources/2008-09/msg00016.html

site-start.el now ends with:

(require 'switch-to-new-buffer)
(switch-to-new-untitled-buffer)
;(org-mode)
(setq initial-buffer-choice 'none)

This works fine - except that when I uncomment the (org-mode) line,
the "Untitled" buffer is set to Org-mode (as intended) but when I
close Emacs it will no longer ask about saving data if the buffer was
marked dirty. If the (org-mode) line is commented out, Emacs does ask
about saving (if it is required). I also tried c-mode instead of
Org-mode, same effect - so the problem is probably not related to
Org-mode.

I was going to suggest:

(let ((default-major-mode 'org-mode))
  (switch-to-new-untitled-buffer))

But when I tested it, I found out it didn't work as intended.  For that,
the following version of switch-to-new-buffer is needed (I will post a
new version of switch-to-new-buffer.el to gnu.emacs.sources and the
EmacsWiki later):

(defun switch-to-new-buffer ()
  "Switch to a new buffer.
The buffer name is the value of `switch-to-new-buffer-name', or \"*scratch*\"
if that is nil.
See `set-buffer-major-mode'."
  (interactive)
  (let ((new-buffer (generate-new-buffer (or switch-to-new-buffer-name
                                             "*scratch*"))))
    (set-buffer-major-mode new-buffer)
    ;; Protect against kill-emacs:
    (setq buffer-offer-save t)
    ;; Protect against kill-buffer:
    (add-hook 'kill-buffer-query-functions
              'switch-to-new-buffer-kill-buffer-query-function
              nil
              t)
    ;; Finally, select:
    (switch-to-buffer new-buffer)))

I guess changing the mode somehow overwrites the kill protections in 
switch-to-new-buffer?

Yes, via kill-all-local-variables.

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

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