Subject: bug#41571: 27.0.91; "(elisp) Interpolated Strings" is under "(elisp) Text"

From: Eli Zaretskii <[email-masked]>
Date: Fri, 29 May 2020 22:41:24 +0300

> From: "Basil L. Contovounesios" <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 29 May 2020 19:35:31 +0100
> 
> How's the attached for emacs-27?

Thanks, it's much better, but it still "needs work".

(Btw, why are you attachments appear before the text?  It makes
responding harder, because I need to bring the citations to the
front.)

> +The functions described in this section accept a fixed set of
> +specification characters.  The next section describes a function
> +@code{format-spec} which accepts custom specification characters.

This would benefit from making it clear what you mean by
"specification characters".  An example would clarify that.

(It is actually a general comment to your text: you frequently use
terms that are left unexplained, which makes the reader stumble and
try to understand what you mean.  Specific examples below.)

> +It is, in some circumstances, useful to allow users to control how

The beginning of this sentence is unnecessarily complex.  A much
simpler variant would be

  Sometimes it is useful to allow Lisp programs to control...

Note that I replaced "users" with "Lisp  programs", since we are not
talking about Emacs users here.

> +A more convenient format string for such cases would be something like
> +@code{"%f %l <%e>"}, where each specification character carries more
> +semantic information and can easily be rearranged relative to other
> +specification characters.  The function @code{format-spec} described
> +in this section performs a similar function to @code{format}, except
> +it operates on format control strings that comprise arbitrary
> +specification characters.

"comprise" => "include", or even just "use"

> +@defun format-spec format specification &optional only-present
> +This function returns a string equal to the format control string

The "equal" here is confusing, because equality is not really
important here, especially since the job of this function is to
produce strings that are NOT equal to the original.

> +@var{format}, replacing any format specifications it contains with
> +values found in the alist @var{specification} (@pxref{Association
> +Lists}).
> +
> +Each key in @var{specification} is a format specification character,
> +and its associated value is the string to replace it with.  For
> +example, an alist entry @code{(?a . "alpha")} means to replace any
> +@samp{%a} specifications in @var{format} with @samp{alpha}.

You say "key in SPECIFICATION", but SPECIFICATION is an alist, and a
key in an alist has well-known meaning.  The "key" above should be
"association".  And in general I'd rearrange the text to make the
format of SPECIFICATION more explicit, something like:

  @defun format-spec template spec-alist &optional only-present
  This function returns a format string suitable for using in
  @code{format} and similar functions.  The format string is produced
  from @var{template} according to conversions specified in
  @var{spec-alist}, which is an alist (@pxref{Association Lists}) of
  the form @w{@code{(@var{letter} . @var{replacement})}}.  Each
  specification @code{%@var{letter}} in @var{template} will be
  replaced by @var{replacement} when producing the resulting format
  string.

> +Some useful properties are gained as a result of @var{specification}
> +being an alist.  The alist may contain more unique keys than there are
> +unique specification characters in @var{format}; unused keys are
> +simply ignored.  If the same key is contained more than once, the
> +first one found is used.  If @var{format} contains the same format
> +specification character more than once, then the same value found in
> +@var{specification} is used as a basis for all of that character's
> +substitutions.

Here you use "key" without first explaining what it is.  Also, this
paragraph describes several distinct features, so it is better to use
an itemized list instead of just one sentence after another: it makes
the description easier to grasp by dividing it into distinct smaller
chunks.

> +The optional argument @var{only-present} indicates how to handle
> +format specification characters in @var{format} that are not found in
> +@var{specification}.  If it is @code{nil} or omitted, an error is
> +emitted.

Passive tense alert!  Suggest to rephrase

  If it is @code{nil} or omitted, the function signals an error.

> +The syntax of format specifications accepted by @code{format-spec} is
> +similar, but not identical, to that accepted by @code{format}.  In
> +both cases, a format specification is a sequence of characters
> +beginning with @samp{%} and ending with an alphabetic letter such as
> +@samp{s}.  The only exception to this is the specification @samp{%%},
> +which is replaced with a single @samp{%}.

How is what's described in the last sentence "an exception"?  Format
strings used by 'format' also behave like that, right?

> +Unlike @code{format}, which assigns specific meanings to a fixed set
> +of specification characters, @code{format-spec} accepts arbitrary
> +specification characters and treats them all equally.  For example:
> +
> +@example
> +(format-spec "su - %u %l"
> +             `((?u . ,(user-login-name))
> +               (?l . "ls")))
> +     @result{} "su - foo ls"
> +@end example

This example stops short of explaining why this function is useful:
making the replacements fixed strings, as in "ls", is not the reason.
OTOH, the use of user-login-name is obfuscated by the backtick
notation, which seems to say that some magic is needed here.

I think the reason for having this function should be explained
better, with more meaningful examples.

> +@item 0
> +This flag causes any padding inserted by the width, if specified, to
                                ^^^^^^^^^^^^^^^^^^^^^
Width cannot insert anything, so this should be reworded.  Same in a
few other items.

> +@item <
> +This flag causes the substitution to be truncated to the given width,
> +if specified, by removing characters from the left.

"truncated ... by removing characters" is unnecessarily complicated.
Why not say simply "truncated on the left"?

> +@item >
> +This flag causes the substitution to be truncated to the given width,
> +if specified, by removing characters from the right.

Same here.

> +As is the case with @code{format}, a format specification can include
> +a width, which is a decimal number that appears after any flags.  If a
> +substitution contains fewer characters than its specified width, it is
> +extended with padding, normally comprising spaces inserted on the^^^^^
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +left:
>  ^^^^

"it is padded on the left" is simpler and more clear.

> +Here is a more complicated example that combines several
> +aforementioned features:
> +
> +@example
> +(format-spec "%<06e %<06b"
> +             '((?b . "beta")
> +               (?e . "epsilon")))
> +     @result{} "psilon 00beta"
> +@end example

Can we make this example be less trivial?  This use case doesn't
justify using format-spec at all.  Even the subtle point of having the
format specs in the order different from the alist is not evident
unless you make a point of mentioning it (something that IMO should
have been done earlier in the description).

Thanks.