From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#55257: master f2d2fe6fc8: server-execute: Initialize the *scratch* buffer Date: Mon, 09 May 2022 14:11:14 -0400 Message-ID: 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> <871qx4lvgl.fsf@melete.silentflame.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17639"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Robert Pluim , 55257@debbugs.gnu.org, Eli Zaretskii , emacs-devel@gnu.org To: Sean Whitton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 09 20:12:19 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1no7rn-0004Hp-Fl for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 May 2022 20:12:19 +0200 Original-Received: from localhost ([::1]:55320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1no7rm-0005JD-Gy for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 May 2022 14:12:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1no7rX-0005H8-00 for bug-gnu-emacs@gnu.org; Mon, 09 May 2022 14:12:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37256) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1no7rW-0006qA-N9 for bug-gnu-emacs@gnu.org; Mon, 09 May 2022 14:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1no7rW-0007u0-FG for bug-gnu-emacs@gnu.org; Mon, 09 May 2022 14:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 May 2022 18:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55257 X-GNU-PR-Package: emacs Original-Received: via spool by 55257-submit@debbugs.gnu.org id=B55257.165211988630225 (code B ref 55257); Mon, 09 May 2022 18:12:02 +0000 Original-Received: (at 55257) by debbugs.gnu.org; 9 May 2022 18:11:26 +0000 Original-Received: from localhost ([127.0.0.1]:59386 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1no7qv-0007rP-FM for submit@debbugs.gnu.org; Mon, 09 May 2022 14:11:25 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55895) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1no7qt-0007qv-EG for 55257@debbugs.gnu.org; Mon, 09 May 2022 14:11:23 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 1CF451001CB; Mon, 9 May 2022 14:11:18 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 2473F100118; Mon, 9 May 2022 14:11:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1652119876; bh=DmxyQLuuL+Gr/wenyPD9eT6C+NVwFndZMHMaCpxyG+0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=AKy2Ld1HN0W6r780s+vieWDyFczErJOjxjaCJh6wujhGqqvZJOxW1RvzVzOEK1/O4 nEt6aSPjJIRCyB1K94RCY1GcRL/emllfEwUIInD5VNHlVObOycwrZOmtF9+/7BTTs4 5HUsi1NRpKip2XDZyxgLTvHWC296Dr7ki8qP77JxGB1P2iStphceLuGpeNUpDTTgGi z/rdWiu0HhulLRq9/L8H3eyJSGoge1Xbve5WB2HSJjFn+gZCpt4kDbrzUQbG4CFd6s kpQbd52VyMgL33K9j6QR4osVZFdY2HV2b5JGx3kGJIOQfLFj+Mvtv0D8rrolvaDzz+ g8FtgQg8xvM4w== Original-Received: from alfajor (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id F2682120B95; Mon, 9 May 2022 14:11:15 -0400 (EDT) In-Reply-To: <871qx4lvgl.fsf@melete.silentflame.com> (Sean Whitton's message of "Sat, 07 May 2022 17:27:38 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:231769 Archived-At: > Here's an updated patch. LGTM, thank you (feel free to push, as far as I'm concerned). See further comments below. Stefan > +** Functions which recreate the *scratch* buffer now also initialize it. > +When functions like 'other-buffer' and 'server-execute' recreate > +*scratch*, they now also insert 'initial-scratch-message' and change > +the major mode according to 'initial-major-mode', like at Emacs > +startup. Previously, these functions ignored > +'initial-scratch-message' and left *scratch* in 'fundamental-mode'. I'd say "set the major mode" rather than "change the major mode". > +(defun get-initial-buffer-create () I know you didn't like my `scratch-buffer--create` suggestion because of the double dash, but I think at least "scratch" would be very welcome in it. > + "Return the \*scratch\* buffer, creating a new one if needed." > + (or (get-buffer "*scratch*") > + (let ((scratch (get-buffer-create "*scratch*"))) > + ;; Don't touch the buffer contents or mode unless we know that > + ;; we just created it. > + (with-current-buffer scratch > + (when initial-scratch-message > + (insert (substitute-command-keys initial-scratch-message)) > + (set-buffer-modified-p nil)) > + (funcall initial-major-mode)) > + scratch))) > + > (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))) Now that I look at it again, it occurs to me that maybe we should do something like: (defun scratch-buffer (&optional display) "Create the \*scratch\* buffer. If the buffer doesn't exist, create it first. If DISPLAY (or when used interactively), switch to it." (interactive (list t)) (let ((buf (get-buffer "*scratch*"))) (unless buf ;; Don't touch the buffer contents or mode unless we know that ;; we just created it. (with-current-buffer (setq buf (get-buffer-create "*scratch*")) (when initial-scratch-message (insert (substitute-command-keys initial-scratch-message)) (set-buffer-modified-p nil)) (funcall initial-major-mode))) (when display (pop-to-buffer-same-window buf)) buf)) i.e. combine the new function with the existing command, so we don't need to come up with a new name.