badri@warren.mentorg.com (Badri Lokanathan) (05/14/91)
I am running Micro Emacs 3.10 alpha on a Mac. I encountered a couple of problems with the replace command: (1) Suppose I need to do two global substitutions on a file: - Insert XX at the beginning of each line - delete YY at the end of each line I set mode to MAGIC, then execute replace ^ with XX. Now when I try to replace YY$ with <nothing>, I am unable to get rid of the former replacement string XX. Of course, I can always switch the order of execution, but that is not the answer I am looking for :-) (2) Is it possible to "remember" a matched pattern and interpolate it into the replacement pattern (ala vi)? For those who are familiar with vi, how does one achieve something like s/\([a-z0-9]*\)_\([a-z0-9]*\)/\2_\1/ -- Badri Lokanathan Go ahead, flame away. badri@sdl.scs.com (or) Make my day. ...!uunet!sdl!badri
wirzeniu@kruuna.Helsinki.FI (Lars Wirzenius) (05/16/91)
In article <BADRI.91May14150327@elysium.warren.mentor.com> badri@warren.mentorg.com (Badri Lokanathan) writes: >I set mode to MAGIC, then execute replace ^ with XX. Now when I try >to replace YY$ with <nothing>, I am unable to get rid of the former >replacement string XX. M-^X set $replace "" (Execute command line which sets the value of the variable $replace to the empty string.) -- Lars Wirzenius wirzenius@cc.helsinki.fi
decouty@irisa.fr (Bertrand Decouty) (05/17/91)
In article <1991May16.090143.12277@klaava.Helsinki.FI> wirzeniu@kruuna.Helsinki.FI (Lars Wirzenius) writes: | In article <BADRI.91May14150327@elysium.warren.mentor.com> badri@warren.mentorg.com (Badri Lokanathan) writes: | >I set mode to MAGIC, then execute replace ^ with XX. Now when I try | >to replace YY$ with <nothing>, I am unable to get rid of the former | >replacement string XX. | | M-^X set $replace "" | | (Execute command line which sets the value of the variable $replace to | the empty string.) | | -- | Lars Wirzenius wirzenius@cc.helsinki.fi This has been fixed in 3.11 beta. ^K deletes the current replace string, when asked for the replace string, and inserts an empty string. A very nice feature! -- [ Bertrand DECOUTY | EMAIL : decouty@irisa.fr, decouty@irisa.uucp ] [ IRISA - INRIA (Atelier) | {uunet,mcsun,inria}!irisa!decouty ] [ Campus de Beaulieu | PHONE : +33 99 36 20 00 ] [ F-35042 Rennes Cedex - FRANCE| FAX : +33 99 38 38 32 | TELEX: 950473 UNIRISA]
tony@mwuk.UUCP (Tony Mountifield) (05/17/91)
In article <BADRI.91May14150327@elysium.warren.mentor.com> badri@warren.mentorg.com (Badri Lokanathan) writes:
-> I am running Micro Emacs 3.10 alpha on a Mac.
-> I encountered a couple of problems with the replace command:
->
-> (1) Suppose I need to do two global substitutions on a file:
-> - Insert XX at the beginning of each line
-> - delete YY at the end of each line
->
-> I set mode to MAGIC, then execute replace ^ with XX. Now when I try
-> to replace YY$ with <nothing>, I am unable to get rid of the former
-> replacement string XX.
->
-> Of course, I can always switch the order of execution, but that is not
-> the answer I am looking for :-)
You could always try replacing YY<NL> with <NL>
Or define a macro which does:
set $replace ""
and then bind that macro to an unused key such as ^_
-> (2) Is it possible to "remember" a matched pattern and interpolate it
-> into the replacement pattern (ala vi)? For those who are familiar with
-> vi, how does one achieve something like
->
-> s/\([a-z0-9]*\)_\([a-z0-9]*\)/\2_\1/
I don't think it is possible. You just have the ability to insert the
WHOLE of the matched pattern using &
-> --
-> Badri Lokanathan Go ahead, flame away.
-> badri@sdl.scs.com (or) Make my day.
-> ...!uunet!sdl!badri
Tony.
--
Tony Mountifield. | Microware Systems (UK) Ltd.
MAIL: tony@mwuk.uucp | Leylands Farm, Nobs Crook,
INET: tony%mwuk.uucp@ukc.ac.uk | Colden Common, WINCHESTER, SO21 1TH.
UUCP: ...!mcsun!ukc!mwuk!tony | Tel: 0703 601990 Fax: 0703 601991
**** OS-9, OS-9000 Real Time Systems **** MS-DOS - just say "No!" ****
rpj@echo.canberra.edu.au (Ross Johnson) (05/19/91)
In <BADRI.91May14150327@elysium.warren.mentor.com> badri@warren.mentorg.com (Badri Lokanathan) writes: >I am running Micro Emacs 3.10 alpha on a Mac. >I encountered a couple of problems with the replace command: >(2) Is it possible to "remember" a matched pattern and interpolate it >into the replacement pattern (ala vi)? For those who are familiar with >vi, how does one achieve something like >s/\([a-z0-9]*\)_\([a-z0-9]*\)/\2_\1/ If you have or can get a version of "sed" for Macs then you could use the filter-buffer (^X#) command using: sed -e "s/\([a-z0-9]*\)_\([a-z0-9]*\)/\2_\1/" as the filter command line. This works on both PC and Unix MicroEmacs (I just checked). Cheers, PS. I'm assuming Macs can do filtering, can they? -- +----------------------+---+ | Ross Johnson | | E-Mail: rpj@ise.canberra.edu.au | Info Sciences and Eng|___| | University of Canberra | UUCP : uunet!munnari!ise.canberra.edu.au!rpj | PO Box 1 | JANET : rpj%au.edu.canberra.ise@EAN-RELAY | Belconnen ACT 2616 | BITNET: rpj%ise.canberra.edu.au@relay.cs.net | AUSTRALIA | +--------------------------+