From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17186"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel@gnu.org, 55257@debbugs.gnu.org, Robert Pluim , Eli Zaretskii To: Sean Whitton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 09 20:12:14 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 1no7rh-00047q-FZ for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 20:12:13 +0200 Original-Received: from localhost ([::1]:55152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1no7rg-0005C6-68 for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 14:12:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1no7qt-0004XE-2O for emacs-devel@gnu.org; Mon, 09 May 2022 14:11:23 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1no7qp-0006jR-PS; Mon, 09 May 2022 14:11:21 -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") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=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:289544 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.