GNU bug report logs - #65347
29.1; Underscore in query replace prevents case-matching

Previous Next

Package: emacs;

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


Message #31 received at 65347 <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 65347 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#65347: 29.1; Underscore in query replace prevents
 case-matching
Date: Fri, 18 Aug 2023 14:31:46 -0400
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Spencer Baugh <sbaugh <at> janestreet.com>
>> Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>,  65347 <at> debbugs.gnu.org
>> Date: Fri, 18 Aug 2023 12:30:48 -0400
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> >> 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.
>
> We look at this from different angles.  As an Emacs maintainer, I
> would like to see every place that deals with words to honor
> find-word-boundary-function-table, instead of inventing its own ideas
> about where a word begins and where it ends.

Understandable, I want this too of course.  Better support for case
matching in words would be good.

>> 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.
>
> Here, you look at the issue from a very narrow perspective: of words
> separated by '-' or '_', because that just happens to be the case that
> you bumped into.  But that is just one very particular use case; words
> can be separated by a lot more characters.  I would actually begin
> considering the simpler case of "Foo do action".

But no, this use case very specifically is about replacing symbols
(sexps) while matching case.  There's a body of code which frequently
uses the same symbol with different capitalization (both as a lowercase
variable name and an uppercase type name) and I want to do replacements
which match case.

I don't much care about the word boundary or superword-mode, because I'm
not dealing with words - I'm very deliberately dealing with symbols.

>> 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.
>
> Given enough user options, we could support that as optional behavior.
> But one thing is clear: we cannot simultaneously support all of the
> possible interpretations of "capitalization pattern".  And another
> thing is clear: this heuristic is confusing and rarely kept in mind as
> it is, so imagine what will happen if we add half a dozen options to
> support its variants...

Sure.  This idea is very hacky anyway.

What about the other thing I proposed?  That's what I'm more interested
in, because this is a problem of replacing symbols.  And it's much more
elegant.  Repeated here:

>>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.




This bug report was last modified 1 year and 277 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.