From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.devel Subject: Re: master f2d2fe6fc8: server-execute: Initialize the *scratch* buffer Date: Thu, 05 May 2022 15:07:41 -0700 Message-ID: <871qx74or6.fsf@melete.silentflame.com> References: <165162665935.26821.8964921720746152690@vcs2.savannah.gnu.org> <20220504011059.9F667C009A8@vcs2.savannah.gnu.org> <87levhdfeh.fsf@athena.silentflame.com> <87y1zhe5qz.fsf@athena.silentflame.com> <87levhe24h.fsf@athena.silentflame.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15524"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Notmuch/0.36 Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Robert Pluim , emacs-devel@gnu.org, 55257-submitter@debbugs.gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 06 00:08:51 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nmjeT-0003mW-8e for ged-emacs-devel@m.gmane-mx.org; Fri, 06 May 2022 00:08:50 +0200 Original-Received: from localhost ([::1]:47132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmjeR-0006ba-Oo for ged-emacs-devel@m.gmane-mx.org; Thu, 05 May 2022 18:08:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmjdU-0005i3-79 for emacs-devel@gnu.org; Thu, 05 May 2022 18:07:48 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:59841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmjdR-0001Xy-VN for emacs-devel@gnu.org; Thu, 05 May 2022 18:07:47 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 24C8C5C00EB; Thu, 5 May 2022 18:07:44 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 05 May 2022 18:07:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1651788464; x=1651874864; bh=nO 3YJF+ssfkfdb+kqBIu+8Ciz8qcPyqaZswMgM3HAlg=; b=PspMmdy+DFg+CRM5GG P1ddHGyGmkGmlOaan8lIjKysEIzlGrEjRnuoqW4lSribY+oAQyf89Nsr3uAlID+A fM56kCa1oA3RK+8IME7bLy3C4y8+5dDaEyoMUoi+pzsHtA/NkB7qy0P/fl7WL2ji iNoBIf9dSCHjxZl+Hox6YxKYWPEK66KI+tU5m8MSEsl8MoE/nQ8XAh2lMOd4yVhA 74f5DmGwrroRvEWhuPhPWsE5B0YNsTPRzsoVqkSPm0cW3Xe82XUl9pjZZroJJAHe zGRjyYVcY5ADt5aA8jtgr/dt/BCBtJEzA8RnVhRp+Y2LpAUCzQVBdMrPLhUXo5up I+Dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1651788464; x= 1651874864; bh=nO3YJF+ssfkfdb+kqBIu+8Ciz8qcPyqaZswMgM3HAlg=; b=d UeTlOXNAyJEOEn1ut4jD0pctiCscxBcYnI1tGgZo+wAnxW/gYlPV9bkzoobzmytr p50gRJLRyXSvNGRcnvjTjnkzOOgMtE/Hi+oG8l1w82mub0vmNYUMphMX6+2b4Rp+ rYmB0aieW+gUa29tEYLSzguZlRbZNYEaamljGKpLEr52kUXA0JDrUQaGmiDeAzjy 7T5csmjfHlSUEMUIcWX4keh9vdb2HAr7v9OlIzHJ5bPU1LkVZKJxCmWy67xeaJgJ hvEiQKID+B1NsXL3/1AZ1CinS0ufjI58uzddzEw4N+9GA/plXcGp58PkbywRgc9Y xkneh1OXWqFZWyyNf2N5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfedvgddthecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufgjfhgffffkgggtsehmtddtredtredtnecuhfhrohhmpefuvggrnhcu hghhihhtthhonhcuoehsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvgeqne cuggftrfgrthhtvghrnhepfeffhfegudeuueehkeejjefhgeelffdvveefheekvedukeeu keeuhedvueejvdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepshhpfihhihhtthhonhesshhpfihhihhtthhonhdrnhgrmhgv X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 May 2022 18:07:43 -0400 (EDT) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id 06CDC7E5A84; Thu, 5 May 2022 15:07:42 -0700 (MST) In-Reply-To: Received-SPF: pass client-ip=66.111.4.29; envelope-from=spwhitton@spwhitton.name; helo=out5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:289285 Archived-At: --=-=-= Content-Type: text/plain Hello, On Wed 04 May 2022 at 12:26PM -04, Stefan Monnier wrote: >> It looks like Fother_window is called only from Fcall_interactively and >> Fkill_buffer, so there probably isn't a bootstrapping issue if I make >> those Ffuncall my new `get-initial-buffer-create'. It looks like >> bootstrapping C code just makes an empty *scratch* and leaves it to >> startup.el to initialise it. > > Even better, Here's my fix. Haven't quite finished testing each and every call site but seemed worth posting it for comments. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Factor-out-scratch-initialization.patch >From ac1c813ccd4cc266dd722704a36a9d178dab1e4c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 5 May 2022 13:03:06 -0700 Subject: [PATCH] Factor out *scratch* initialization * lisp/simple.el: Require subr-x when compiling. (get-initial-buffer-create): New function, factored out of scratch-buffer, and additionally clearing the modification flag and calling substitute-command-keys (bug#55257). (scratch-buffer): lisp/server.el (server-execute): lisp/startup.el (normal-no-mouse-startup-screen): (command-line-1): lisp/window.el (last-buffer): src/buffer.c (Fother_buffer, other_buffer_safely): Use it. lisp/startup.el (startup--get-buffer-create-scratch): Delete now-unused function. --- lisp/server.el | 2 +- lisp/simple.el | 22 +++++++++++++++------- lisp/startup.el | 12 +++--------- lisp/window.el | 5 +---- src/buffer.c | 21 ++------------------- 5 files changed, 22 insertions(+), 40 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index 763cf27f7a..042962b8e9 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1367,7 +1367,7 @@ server-execute ((functionp initial-buffer-choice) (funcall initial-buffer-choice))))) (switch-to-buffer - (if (buffer-live-p buf) buf (get-buffer-create "*scratch*")) + (if (buffer-live-p buf) buf (get-initial-buffer-create)) 'norecord))) ;; Delete the client if necessary. diff --git a/lisp/simple.el b/lisp/simple.el index 861d9eefde..5a37e246f7 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -28,7 +28,9 @@ ;;; Code: -(eval-when-compile (require 'cl-lib)) +(eval-when-compile + (require 'cl-lib) + (require 'subr-x)) (declare-function widget-convert "wid-edit" (type &rest args)) (declare-function shell-mode "shell" ()) @@ -10213,16 +10215,22 @@ capitalize-dwim the number of seconds east of Greenwich.") ) +(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))))) + (defun scratch-buffer () "Switch to the \*scratch\* buffer. If the buffer doesn't exist, create it first." (interactive) - (if (get-buffer "*scratch*") - (pop-to-buffer-same-window "*scratch*") - (pop-to-buffer-same-window (get-buffer-create "*scratch*")) - (when initial-scratch-message - (insert initial-scratch-message)) - (funcall initial-major-mode))) + (pop-to-buffer-same-window (get-initial-buffer-create))) diff --git a/lisp/startup.el b/lisp/startup.el index c7cf86a01e..3fa25ddee9 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -2355,7 +2355,7 @@ normal-no-mouse-startup-screen (insert "\t\t") (insert-button "Open *scratch* buffer" 'action (lambda (_button) (switch-to-buffer - (startup--get-buffer-create-scratch))) + (get-initial-buffer-create))) 'follow-link t) (insert "\n") (save-restriction @@ -2487,12 +2487,6 @@ display-about-screen (defalias 'about-emacs 'display-about-screen) (defalias 'display-splash-screen 'display-startup-screen) -(defun startup--get-buffer-create-scratch () - (or (get-buffer "*scratch*") - (with-current-buffer (get-buffer-create "*scratch*") - (set-buffer-major-mode (current-buffer)) - (current-buffer)))) - ;; This avoids byte-compiler warning in the unexec build. (declare-function pdumper-stats "pdumper.c" ()) @@ -2784,7 +2778,7 @@ command-line-1 (when (eq initial-buffer-choice t) ;; When `initial-buffer-choice' equals t make sure that *scratch* ;; exists. - (startup--get-buffer-create-scratch)) + (get-initial-buffer-create)) ;; If *scratch* exists and is empty, insert initial-scratch-message. ;; Do this before switching to *scratch* below to handle bug#9605. @@ -2808,7 +2802,7 @@ command-line-1 ((functionp initial-buffer-choice) (funcall initial-buffer-choice)) ((eq initial-buffer-choice t) - (startup--get-buffer-create-scratch)) + (get-initial-buffer-create)) (t (error "`initial-buffer-choice' must be a string, a function, or t"))))) (unless (buffer-live-p buf) diff --git a/lisp/window.el b/lisp/window.el index 9f78784612..4ec329e0cf 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4886,10 +4886,7 @@ last-buffer (setq frame (or frame (selected-frame))) (or (get-next-valid-buffer (nreverse (buffer-list frame)) buffer visible-ok frame) - (get-buffer "*scratch*") - (let ((scratch (get-buffer-create "*scratch*"))) - (set-buffer-major-mode scratch) - scratch))) + (get-initial-buffer-create))) (defcustom frame-auto-hide-function #'iconify-frame "Function called to automatically hide frames. diff --git a/src/buffer.c b/src/buffer.c index f8a7a4f510..702b21f9fc 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1634,16 +1634,7 @@ DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, if (!NILP (notsogood)) return notsogood; else - { - 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")); } /* 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")); } DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo, -- 2.30.2 --=-=-=--