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:13:24 -0700 Message-ID: <87y1zf39x7.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> <871qx74or6.fsf@melete.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="5473"; 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:15:23 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 1nmjkn-0001Cg-VC for ged-emacs-devel@m.gmane-mx.org; Fri, 06 May 2022 00:15:23 +0200 Original-Received: from localhost ([::1]:53192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmjkm-0003jk-QU for ged-emacs-devel@m.gmane-mx.org; Thu, 05 May 2022 18:15:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmjiz-0001s1-VT for emacs-devel@gnu.org; Thu, 05 May 2022 18:13:30 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46255) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmjiw-0002Sq-L1 for emacs-devel@gnu.org; Thu, 05 May 2022 18:13:28 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id C9CED5C00EF; Thu, 5 May 2022 18:13:25 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 05 May 2022 18:13:25 -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=1651788805; x=1651875205; bh=Y1 jSN5cVbBmsWaKMTO5+MrLagmP2ZE8qXRD2QXtGtOQ=; b=prZgPS6MY4i9FCaTGU nIR32My1XmTM6LsSbiPBlFmewzr9MmaAcPfcpx8swnSzW/dFK2zgPK52f5qHzhJb ryS+NWYUT23SFIPA3ox+IsHaB983Ufhahpn+6qw8QDVZTijdnnKFZmH7enwENgrz eaeOX6E1erzcZq7PHV7+xJBeey08B9r87U83sbdBN/deqYT6En0WKgKd29jD/fig XUNVWA7OxM+amCRcCytudeVmYRP4bxFaLfYt+6/+LSEbOqli8tb+gNcvPWbJSbok kdFraEjFCyoZDwfMzGU9oNggRMQpKDrBgBpgT4BmQuk/FC3y/1rw5Dh2Y72+Rugn 4C0g== 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=1651788805; x= 1651875205; bh=Y1jSN5cVbBmsWaKMTO5+MrLagmP2ZE8qXRD2QXtGtOQ=; b=J FhnhnG3o2Jl6l/w0wMAhylsj03jChOi8GIlKs5zgvLA8U3Hc9i+h/9dSwXuQdhiC w6OHYOmDCOjFTrShI+S16KLvfXH7oq9sIWIYjw17RIeP6iRqI6RKNl1JS+KaFUI3 3aU/kaf/zuUHS/fxHscjg5Mm+w5cBmtdmZuvlPLWHhXo05dBSHadHLRpHVcLUfFA /Px1GOG02MQp7l9LiNr5D1+kGfy3NnKVTm1teegpQmKBHaV5LNKHBYhvpcBzIqJ+ zHHJMEMll2y+sfOn2vQAwwxYaTV1R9cTGZ4i8dK/0LhKKH6h7b9ATYcoT+PulBQy D9ZmFyxeHM2eKy6nIsseA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfedvgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufgjfhgffffkgggtsehmtddtredtredtnecuhfhrohhmpefuvggrnhcu hghhihhtthhonhcuoehsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvgeqne cuggftrfgrthhtvghrnhepfeffhfegudeuueehkeejjefhgeelffdvveefheekvedukeeu keeuhedvueejvdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepshhpfihhihhtthhonhesshhpfihhihhtthhonhdrnhgrmhgv X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 May 2022 18:13:25 -0400 (EDT) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id AA1267E5F71; Thu, 5 May 2022 15:13:24 -0700 (MST) In-Reply-To: <871qx74or6.fsf@melete.silentflame.com> 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:289287 Archived-At: --=-=-= Content-Type: text/plain Hello, On Thu 05 May 2022 at 03:07PM -07, Sean Whitton wrote: > 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. Hopefully fixed the commit message in the attached. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Factor-out-scratch-initialization.patch >From 9731fa66ff5b6e2ed3287ef033b71c584abadd12 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 --=-=-=--