GNU bug report logs -
#55257
29.0.50; New command `scratch-buffer' inconsistent with startup
Previous Next
Reported by: David Ponce <da_vid <at> orange.fr>
Date: Wed, 4 May 2022 08:33:02 UTC
Severity: normal
Found in version 29.0.50
Done: Sean Whitton <spwhitton <at> spwhitton.name>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 55257-submitter <at> debbugs.gnu.org (full text, mbox):
> From: Sean Whitton <spwhitton <at> spwhitton.name>
> Cc: Robert Pluim <rpluim <at> gmail.com>, emacs-devel <at> gnu.org,
> 55257-submitter <at> debbugs.gnu.org
> Date: Thu, 05 May 2022 15:07:41 -0700
>
> -(eval-when-compile (require 'cl-lib))
> +(eval-when-compile
> + (require 'cl-lib)
> + (require 'subr-x))
Why did you need subr-x here? AFAIR, doing this breaks bootstrap,
which is why if-let is now in subr.el.
> +(defun get-initial-buffer-create ()
> + "Return the \*scratch\* buffer, creating a new one if needed."
> + (if-let ((scratch (get-buffer "*scratch*")))
> + scratch
> + (prog1 (setq scratch (get-buffer-create "*scratch*"))
> + (with-current-buffer scratch
> + (when initial-scratch-message
> + (insert (substitute-command-keys initial-scratch-message))
> + (set-buffer-modified-p nil))
> + (funcall initial-major-mode)))))
It's somewhat inelegant to explicitly test for the buffer's existence
before you call get-buffer-create. Is that only to avoid changing its
contents? If so, can't you test for that in some other way?
> + return call0 (intern ("get-initial-buffer-create"));
Instead of calling intern each time this function is called from C, it
is better to define a symbol for it, usually named
Qget_initial_buffer_create, and then call0 it directly.
> /* The following function is a safe variant of Fother_buffer: It doesn't
> @@ -1659,15 +1650,7 @@ other_buffer_safely (Lisp_Object buffer)
> if (candidate_buffer (buf, buffer))
> return buf;
>
> - AUTO_STRING (scratch, "*scratch*");
> - buf = Fget_buffer (scratch);
> - if (NILP (buf))
> - {
> - buf = Fget_buffer_create (scratch, Qnil);
> - Fset_buffer_major_mode (buf);
> - }
> -
> - return buf;
> + return call0 (intern ("get-initial-buffer-create"));
get-initial-buffer-create shows the initial-scratch-message, something
the C code you are replacing didn't do. This is a change in behavior
that should at least be documented, if not fixed.
I also wonder whether we should use safe_call in these places.
Thanks.
This bug report was last modified 3 years and 105 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.