help-emacs-windows
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [h-e-w] Why do replace commands sometimes not work?


From: MBR
Subject: Re: [h-e-w] Why do replace commands sometimes not work?
Date: Sun, 27 May 2012 17:54:41 -0400
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1

See 19.9.2 Regexp Replacement in the Emacs info file:
In `replace-regexp', the NEWSTRING need not be constant: it can refer to all or part of what is matched by the REGEXP.  `\&' in NEWSTRING stands for the entire match being replaced.
Mark
On 5/25/2012 12:18 PM, Raymond Zeitler wrote:
Hi MBR:

To me, the search and replace syntax you're using is incorrect.  Or perhaps \& is an undocumented feature -- you did mention that it sometimes works.

I would search for "\([A-Z]\)" and replace with "SPC\1".

HTH

- Ray

-----Original Message-----

Date: Thu, 24 May 2012 19:15:40 -0400
From: MBR <address@hidden>
To: address@hidden, address@hidden
Subject: [h-e-w] Why do replace commands sometimes not work?

-snip-
The purpose of this part of the macro is to turn CamelCase into space-separated words.

        M-<                    ;; Go to beginning of narrowed buffer
        M-x replace-regexp RET
        [A-Z] RET              ;; Find any capital letter
        C-q SPC \& RET         ;; Replace it with a space followed by itself
        M-<                    ;; Go to beginning of narrowed buffer
        C-d                    ;; Delete the unwanted space before the
        first letter

So, if the narrowed portion of the buffer contains:

        "JohnJacobJingleheimerschmidt"

after running this portion of the macro, it should contain:

        "John Jacob Jingleheimerschmidt"

Instead, when run in Emacs 23, the result is:

        "ohnJacobJingleheimerschmidt"

which is exactly what you'd expect if the M-x replace-regexp failed to do the replacement that it should have.  -snip-



No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2171 / Virus Database: 2425/5024 - Release Date: 05/26/12


reply via email to

[Prev in Thread] Current Thread [Next in Thread]