|Subject:||Re: [h-e-w] Why do replace commands sometimes not work?|
|Date:||Fri, 25 May 2012 14:41:55 -0500|
(That is how I intended to address my last email!)
I agree with the poster who suggested transient mark mode is at fault. If you narrow to region, then there is a pre-existing region defined under transient mark mode. But when you narrowed and then went to the first character the region is ill-defined (it is null). If you simply clear the region at that time, you will be fine. Now, you can’t record that in your macro with C-g, so instead, use 3 ESC presses to clear the region. I just recorded that and tried it and it was happy.
Kevin Buchs | Senior Engineer | SPPDG | 507-538-5459 | address@hidden
Mayo Clinic | 200 First Street SW | Rochester, MN 55905 | http://www.mayo.edu/sppdg
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.
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 |
|[Prev in Thread]||Current Thread||[Next in Thread]|