unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Sean Whitton <spwhitton@spwhitton.name>
Cc: emacs-devel@gnu.org,  55257@debbugs.gnu.org,
	 Robert Pluim <rpluim@gmail.com>,  Eli Zaretskii <eliz@gnu.org>
Subject: Re: master f2d2fe6fc8: server-execute: Initialize the *scratch* buffer
Date: Mon, 09 May 2022 14:11:14 -0400	[thread overview]
Message-ID: <jwvr152prjh.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <871qx4lvgl.fsf@melete.silentflame.com> (Sean Whitton's message of "Sat, 07 May 2022 17:27:38 -0700")

> 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.




  reply	other threads:[~2022-05-09 18:11 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <165162665935.26821.8964921720746152690@vcs2.savannah.gnu.org>
     [not found] ` <20220504011059.9F667C009A8@vcs2.savannah.gnu.org>
2022-05-04  2:14   ` master f2d2fe6fc8: server-execute: Initialize the *scratch* buffer Stefan Monnier
2022-05-04  5:40     ` Sean Whitton
2022-05-04 12:47       ` Stefan Monnier
2022-05-04 14:23         ` Sean Whitton
2022-05-04 14:34           ` Robert Pluim
2022-05-04 14:46             ` Sean Whitton
2022-05-04 14:56               ` Robert Pluim
2022-05-04 14:42           ` Stefan Monnier
2022-05-04 15:41             ` Sean Whitton
2022-05-04 16:26               ` Stefan Monnier
2022-05-05 22:07                 ` Sean Whitton
2022-05-05 22:13                   ` Sean Whitton
2022-05-06 11:34                     ` Stefan Monnier
2022-05-06 19:20                       ` Sean Whitton
2022-05-06 19:24                         ` Lars Ingebrigtsen
2022-05-06  5:40                   ` Eli Zaretskii
2022-05-06 19:26                     ` Sean Whitton
2022-05-07  5:30                       ` Eli Zaretskii
2022-05-07 13:51                         ` Stefan Monnier
2022-05-07 14:12                           ` Eli Zaretskii
2022-05-07 16:29                         ` Sean Whitton
2022-05-07 16:41                           ` Eli Zaretskii
2022-05-07 17:02                             ` Sean Whitton
2022-05-06  7:41                   ` Juri Linkov
2022-05-06 19:28                     ` Sean Whitton
2022-05-08  0:27                   ` bug#55257: " Sean Whitton
2022-05-09 18:11                     ` Stefan Monnier [this message]
2022-05-10  1:49                       ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvr152prjh.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=55257@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rpluim@gmail.com \
    --cc=spwhitton@spwhitton.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).