Subject: bug#65347: 29.1; Underscore in query replace prevents case-matching

From: Spencer Baugh <[email-masked]>
Date: Fri, 18 Aug 2023 12:30:48 -0400

Eli Zaretskii <[email-masked]> writes:
>> From: Stefan Monnier <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
>> Date: Thu, 17 Aug 2023 22:04:53 -0400
>> 
>> > 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?
>> 
>> There's `superword-mode`, but I suspect that query-replace does not
>> honor it in this case.  Could be considered as a bug in
>> `superword-mode`.
>
> Actually, I think it's a bug in replace-match: it doesn't honor
> find-word-boundary-function-table.  I think it should.  Patches
> welcome.

I suppose this is a bit of an XY problem - the real thing I (speaking
for the user who reported this to me) want is to have case-matching for
symbols instead of words.

e.g. if I have Foo-do-action and I do a replace of foo-do-action with
bar-do-action, I want the replacement to be Bar-do-action.

That seems like a reasonable customization... I could add support for
this to replace-match - it would just be a matter of teaching it to
conditionally use symbol boundaries instead of word boundaries.

Alternatively, much more interestingly, the case-matching could *always*
detect case patterns both for symbols and for words.  And if there's no
case pattern for words, but there is a case pattern for symbols, apply
that case pattern to symbols in the replacement.  We could even turn
that on by default.  Does that sound like a good change?  I can make
that change if it sounds desirable.

Alternatively, much more simply, maybe the case-matching could just
detect if the first word is capitalized, and then also capitalize the
first word in the replacement?  That would work for this specific usage.