[Top][All Lists]

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

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

From: Francis Wright
Subject: Re: [h-e-w] Why do replace commands sometimes not work?
Date: Fri, 25 May 2012 19:24:51 +0100

\& is documented in "Regexp Replacement" in the Emacs Manual. It represents
the whole of the matched regexp.

Mark: If I run your macro with standard Emacs settings (having started it
with the -Q flag) then I see the problem that you describe, whereas if I run
with my normal settings then I don't. I think it's a question of how the
region is handled and  the significant difference is that in my normal
environment I have Delete Selection Mode turned on, whereas by default it is
off. And it's the setting when the macro is defined that seems to matter.

If you look at the help for M-< it says "Don't use this command in Lisp
programs!", but by using it in a macro that's effectively what you are
doing. However, rather than worrying any further about precisely why your
macro is unreliable, I suggest you use Kevin Buchs' proposal.


> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On
> Of Raymond Zeitler
> Sent: 25 May 2012 5:18 pm
> To: address@hidden
> Cc: MBR
> Subject: Re: [h-e-w] Why do replace commands sometimes not work?
> 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".
> - 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
> 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
>         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
> replacement that it should have.  -snip-

reply via email to

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