;; we just created it.
(with-current-buffer scratch
(when initial-scratch-message
- ;; We used to run this through substitute-command-keys,
- ;; but that might be unsafe in some rare cases, and this
- ;; function must never fail and signal an error, because
- ;; it is called from other_buffer_safely, which must
- ;; always produce a valid buffer.
- (insert initial-scratch-message)
+ (insert (substitute-command-keys initial-scratch-message))
(set-buffer-modified-p nil))
(funcall initial-major-mode))
scratch)))
(defcustom initial-scratch-message (purecopy "\
;; This buffer is for text that is not saved, and for Lisp evaluation.
-;; To create a file, visit it with \"C-x C-f\" and enter text in its buffer.
+;; To create a file, visit it with \\[find-file] and enter text in its buffer.
")
"Initial documentation displayed in *scratch* buffer at startup.
if (candidate_buffer (buf, buffer))
return buf;
- return safe_call (1, Qget_scratch_buffer_create);
+ /* This function must return a valid buffer, since it is frequently
+ our last line of defense in the face of the expected buffers
+ becoming dead under our feet. safe_call below could return nil
+ if recreating *scratch* in Lisp, which does some fancy stuff,
+ signals an error in some weird use case. */
+ buf = safe_call (1, Qget_scratch_buffer_create);
+ if (NILP (buf))
+ {
+ AUTO_STRING (scratch, "*scratch*");
+ buf = Fget_buffer_create (scratch, Qnil);
+ }
+ return buf;
}
\f
DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
Lisp_Object arglist = Qnil;
/* We are visiting windows in canonical order, and add
- new windows at the front of args[1], which means we
+ new windows at the front of arglist, which means we
have to reverse this list at the end. */
foreach_window (XFRAME (frame), add_window_to_list, &arglist);
arglist = Fnreverse (arglist);
last_selected_window)
= selected_window;
+ /* We may have deleted windows above. Then again, maybe we
+ haven't: the functions we call to maybe delete windows can
+ decide a window cannot be deleted. Force recalculation of
+ Vwindow_list next time it is needed, to make sure stale
+ windows with no buffers don't escape into the wild, which
+ will cause crashes elsewhere. */
+ Vwindow_list = Qnil;
+
if (NILP (data->focus_frame)
|| (FRAMEP (data->focus_frame)
&& FRAME_LIVE_P (XFRAME (data->focus_frame))))