Subject: bug#63398: closed (Re: bug#63398: 28.2; Doc or behavior of replacement commands (e.g. `replace-string'))

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 10 May 2023 13:37:02 +0000

Your bug report

#63398: 28.2; Doc or behavior of replacement commands (e.g. `replace-string')

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
63398: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63398
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#63398: 28.2; Doc or behavior of replacement commands (e.g. `replace-string')
From: Eli Zaretskii <[email-masked]>
To: Drew Adams <[email-masked]>
Cc: [email-masked]
Date: Wed, 10 May 2023 16:37:09 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Drew Adams <[email-masked]>
> Date: Tue, 9 May 2023 20:13:04 +0000
> 
> The doc also says this, however, regarding replacement:
> 
>   In addition, when the NEWSTRING argument is all or partly lower case,
>   replacement commands try to preserve the case pattern of each
>   occurrence.  Thus, the command
> 
>      M-x replace-string <RET> foo <RET> bar <RET>
> 
>   replaces a lower case 'foo' with a lower case 'bar', an all-caps 'FOO'
>   with 'BAR', and a capitalized 'Foo' with 'Bar'.  (These three
>   alternatives-lower case, all caps, and capitalized, are the only ones
>   that 'replace-string' can distinguish.)
> 
> My reading of this is that, since "test 1" is lower-case, the
> replacement should "try" (meaning what, exactly? under what
> circumstances does such a trial "fail"?) to preserve the case pattern of
> the first occurrence, chaning "Test 0" to "Test 1".  That doesn't
> happen.
> 
> Is the doc wrong?  Is my reading of it wrong?  If my reading and the doc
> are right, is the behavior wrong (bugged)?

The manual says "try", and for a good reason.  There's a heuristics
involved that tries to DTRT.  The "when the NEWSTRING argument is all
or partly lower case" part is relevant.  What you expect will happen
if the original text doesn't include digits, as in

  Testing
  testing

  M-x replace-string RET testing RET foobar RET

> [It's also not very good to refer to argument NEWSTRING in a topic/node
> that doesn't define it. Users have to look backward through the doc to
> see if they can find out which argument this is talking about.]\

Fixed.

> BTW, it's unfortunate that we use an em dash char here, with no
> preceding or following space chars.  Why?  Because it reads as if it
> were a hyphen, producing adjective "replace-provided" modifying noun
> `case-fold-search'.  Since we use fixed-width fonts by default, this is
> all the more apparent.  Please reword or surround the em dash with space
> chars.

In your post the em dash was the ASCII character '-', but on my system
it is an actual em dash -- a much longer character, thus the confusion
is unlikely.  As for why there are no spaces -- that's our style.

Subject: 28.2; Doc or behavior of replacement commands (e.g. `replace-string')
From: Drew Adams <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Tue, 9 May 2023 20:13:04 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

emacs -Q

;; So `search-upper-case' is `not-yanks', and `case-fold-search' and
;; `case-replace' are both `t'.

In *scratch* enter this text:

Test 0
test 0

At bob, use `M-x replace-string RET test 0 RET test 1 RET'

(emacs) `Replacement and Lax Matches' seems to say that the result
should be this:

Test 1
test 1

But the result is this:

test 1
test 1

That doc says this:

  If the first argument of a replace command is all lower case, the
  command ignores case while searching for occurrences to replace-provided
  'case-fold-search' is non-'nil' and 'search-upper-case' is also
  non-'nil'.

OK, that's respected; both lines are found during the search.  Good.
___

BTW, it's unfortunate that we use an em dash char here, with no
preceding or following space chars.  Why?  Because it reads as if it
were a hyphen, producing adjective "replace-provided" modifying noun
`case-fold-search'.  Since we use fixed-width fonts by default, this is
all the more apparent.  Please reword or surround the em dash with space
chars.
___

The doc also says this, however, regarding replacement:

  In addition, when the NEWSTRING argument is all or partly lower case,
  replacement commands try to preserve the case pattern of each
  occurrence.  Thus, the command

     M-x replace-string <RET> foo <RET> bar <RET>

  replaces a lower case 'foo' with a lower case 'bar', an all-caps 'FOO'
  with 'BAR', and a capitalized 'Foo' with 'Bar'.  (These three
  alternatives-lower case, all caps, and capitalized, are the only ones
  that 'replace-string' can distinguish.)

My reading of this is that, since "test 1" is lower-case, the
replacement should "try" (meaning what, exactly? under what
circumstances does such a trial "fail"?) to preserve the case pattern of
the first occurrence, chaning "Test 0" to "Test 1".  That doesn't
happen.

Is the doc wrong?  Is my reading of it wrong?  If my reading and the doc
are right, is the behavior wrong (bugged)?
___

[It's also not very good to refer to argument NEWSTRING in a topic/node
that doesn't define it. Users have to look backward through the doc to
see if they can find out which argument this is talking about.]\
___

In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
 of 2022-09-13 built on AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.2846)

Configured using:
 'configure --with-modules --without-dbus --with-native-compilation
 --without-compress-install CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
XPM ZLIB

(NATIVE_COMP present but libgccjit not available)