GNU bug report logs -
#65347
29.1; Underscore in query replace prevents case-matching
Previous Next
Reported by: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Wed, 16 Aug 2023 21:28:02 UTC
Severity: normal
Found in version 29.1
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Spencer Baugh <sbaugh <at> janestreet.com>
>> Date: Wed, 16 Aug 2023 17:27:34 -0400
>>
>>
>> 1. emacs -Q
>> 2. (insert "Foo_bar")
>> 3. M-% foo RET quux RET
>> 4. Observe the buffer contains Quux_bar
>> 5. Undo, so the buffer contains Foo_bar again
>> 6. M-% foo_bar RET quux RET
>> 7. Observe the buffer contains quux
>>
>> Expected behavior:
>> 7. Observe the buffer contains Quux
>>
>> It seems to me that this would match the docstring better:
>>
>> Replacement transfers the case pattern of the old text to the
>> new text, if both ‘case-fold-search’ and ‘case-replace’ are
>> non-nil and FROM-STRING has no uppercase letters.
>
> This is a documentation issue: the complex heuristics used by
> replace-match to decide whether and how to "transfer the case pattern"
> depend on whether _all_ the words in the replaced text use the same
> case pattern. In your example, Foo_bar is 2 words (what is a "word"
> is determined by the buffer's syntax table), and only one of them is
> capitalized. So Emacs does not capitalize the replacement. Try doing
> the same with Foo_Bar, and you will see Quux in the replacement.
>
> These subtleties come up from time to time, so I think it's high time
> we documented that (in the hope this will stop this from popping up),
> so I've now done so on the emacs-29 branch.
>
> I think this is all we should do here, as the behavior is correct and
> justified, has been like that since time immemoriam, and we should not
> change it, therefore.
Ah, that makes sense! I have no further complaint then and we should be
able to close the bug.
Although, a further relevant question: is there some way to make _ not
be a word separator, in this specific context? Without changing the
syntax table of the buffer overall? So that foo_bar is interpreted as
one word?
Maybe some kind of escaping?
This bug report was last modified 1 year and 303 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.