2

I have a string in a buffer "THIS_IS_A_TEST" (the quotes are part of the string).

I want to turn this in to "ThisIsATest". I'm attempting to do this using a query-replace-regexp where I substitute \(\w+\)_? with \,(capitalize \1). However, the upcased words are not being capitalized.

Running M-c (capitalize-word) on any of those words works fine, and if my test string is changed to "this_is_a_test", then I get the desired result ("ThisIsATest").

What's going wrong? Is this a bug in capitalize?

(Note that this still happens without an init file loaded)

0

1 Answer 1

2

It works for me if I set case-replace to nil. I'm not sure why this doesn't do the same thing for the lower case string, though...

Sign up to request clarification or add additional context in comments.

4 Comments

For me it works fine for both (lowercase and uppercase tests). Note, however, that there are two variables that govern the behavior here: case-replace and case-fold-search.
I haven't modified either case-replace or case-fold-search but I would not expect (capitalize "FOO") to have different semantics depending on whether I'm using it in a search or not. If this is the 'expected' behaviour, rather than my misuse of it (somehow), then I propose that this is a bug.
MrBones: Note that capitalize isn't doing anything unexpected (if you type ? for help during the replacement query, it will show you that the call to capitalize returned the expected value). The behaviour here is a question of what Emacs does when the replacement word is identical, save for case, to the original (or a case-modified original); and the variables mentioned control that behaviour.
So capitalize is doing capitalizing, but case-replace combined with case-fold-search is undoing it? IMO, that's a bug

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.