Thanks for the
suggestions. One or the other may prove to be an effective
workaround for this particular instance of the problem. I still
have no idea why replace-regex and replace-string occasionally
misbehave, or how to reliably reproduce that misbehavior. And
from the responses so far, it looks like nobody else remembers
encountering this problem.|
As for C-q before the space, in some version or other they added
the feature that a regular _expression_ search for a space matched
any run of spaces and tabs. To do a regular _expression_ search for
a single space and nothing else, it's necessary to quote the
space. I know that in an insert, the character space inserts as
itself. But my subconscious seems to have decided that the rule
is that spaces should be quoted everywhere in a search and
replace. Although I know quoting spaces is not necessary in the
replace string, it doesn't do any harm, and I've never gotten
around to breaking the habit.
On 5/25/2012 12:23 PM, Buchs, Kevin wrote:
I am curious as to why you include the C-q before the space. Space
inserts itself literally.
Try this regexp:
with this replacement:
and you can skip the step of deleting the first space character at the
beginning of the region and also adjusting extra spaces before each
camelcase word. This replaces every occurrence of a word constituent
followed by a capital letter with a space between the two.
If you do this often, try this lisp code:
(defun de-hump ()
"Split up CamelCase words with a space"
(replace-regexp "\\(\\w\\)\\([A-Z]\\)" "\\1 \\2" nil (point)
Which will do the replacement on the region, so there will be no need to
narrow the buffer.
Kevin Buchs | Senior Engineer | SPPDG | 507-538-5459 |
Mayo Clinic | 200 First Street SW | Rochester, MN 55905 |