unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Sean Whitton <spwhitton@spwhitton.name>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, rpluim@gmail.com, emacs-devel@gnu.org,
	55257-submitter@debbugs.gnu.org
Subject: Re: master f2d2fe6fc8: server-execute: Initialize the *scratch* buffer
Date: Fri, 06 May 2022 12:26:46 -0700	[thread overview]
Message-ID: <871qx6ea2x.fsf@athena.silentflame.com> (raw)
In-Reply-To: <83r1571an1.fsf@gnu.org>

Hello,

On Fri 06 May 2022 at 08:40am +03, Eli Zaretskii wrote:

>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Cc: Robert Pluim <rpluim@gmail.com>, emacs-devel@gnu.org,
>>  55257-submitter@debbugs.gnu.org
>> Date: Thu, 05 May 2022 15:07:41 -0700
>>
>> -(eval-when-compile (require 'cl-lib))
>> +(eval-when-compile
>> +  (require 'cl-lib)
>> +  (require 'subr-x))
>
> Why did you need subr-x here?  AFAIR, doing this breaks bootstrap,
> which is why if-let is now in subr.el.

Ah, my mistake, I didn't know it had moved (though I'm going to get rid
of the if-let I think).

>> +(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)))))
>
> It's somewhat inelegant to explicitly test for the buffer's existence
> before you call get-buffer-create.  Is that only to avoid changing its
> contents?  If so, can't you test for that in some other way?

I had the same intuition at first, but I don't think there is another
way -- the code wants to touch the buffer at all only if it wasn't
already there.  And the code path where it already exists will be by far
the most commonly called, so it seems best to avoid calling
with-current-buffer if we don't have to.

>> +    return call0 (intern ("get-initial-buffer-create"));
>
> Instead of calling intern each time this function is called from C, it
> is better to define a symbol for it, usually named
> Qget_initial_buffer_create, and then call0 it directly.

Will do.

>>  /* 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"));
>
> get-initial-buffer-create shows the initial-scratch-message, something
> the C code you are replacing didn't do.  This is a change in behavior
> that should at least be documented, if not fixed.

This is deliberate -- to my mind I'm fixing the same bug as the one in
server.el.  other-buffer recreates *scratch* for the same sort of
reasons that 'emacsclient -nc' does.

Where were you thinking it should be documented?  The Emacs Lisp changes
section of NEWS?

> I also wonder whether we should use safe_call in these places.

Could you say more?

-- 
Sean Whitton



  reply	other threads:[~2022-05-06 19:26 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 [this message]
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
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=871qx6ea2x.fsf@athena.silentflame.com \
    --to=spwhitton@spwhitton.name \
    --cc=55257-submitter@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rpluim@gmail.com \
    /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).