🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98366

(replace-regexp "^..." "" nil) fiasco

#98366
From: Dan_Jacobson
Date: Tue, 27 Aug 1991 14:53
88 lines
3952 bytes
I have collected some replies.

>>>>> On Mon, 26 Aug 91 21:43:01 -0400, rms@gnu.ai.mit.edu (Richard Stallman) said:

Richard> I don't see anything I could do to solve this problem without creating
Richard> a worse one.  But if you think you do, please try it out.  Maybe you
Richard> can find a solution.

>>>>> On Mon, 26 Aug 91 20:22:46 EDT, ryan@cs.umb.edu (Daniel R. Guilderson) said:

Daniel> Can you M-x revert-buffer?

Well, I didn't try.  By the time the smoke cleared, the auto-save file
had been updated, also.  Not to worry though, I got my file back. I
just like to make it sound more dramatic in gnu.emacs.bug :-) .

>>>>> On Tue, 27 Aug 91 13:46:10 JST, hiroshi@psisun4.isl.melco.co.jp (Hiroshi NAKASHIMA) said:

H> You posted (to gnu.emacs.bug) ;
> [18.57] Hmmm, let's strip the crud off the front of these lines:
> 
>  * to the next host in the host list.  Hosts are sorted in increasing
>  * lexicographic order.
>  */
> /*
>  * initfiles creates the chkfile structures for the shared files:
>  */
> /*
>  * mkdom makes a domain structure and adds it to domain_list.  A pointer to
> 
> I know, we'll use M-x replace-regexp "^..." "":
> 
> 
> r.
> 
> /*
> s:
> 
> /*
> 
> Holy tomatoes, my precious source code has been reduced to rubble by
> the vicious GNU Emacs editing machine.  

H> Unfortunately, it isn't a bug, but feature.  (replace-regexp FROM TO)
H> does (1) search FROM (2) replace it with TO, repeatedly.
H> Thus, at first it finds " * " of the first line and remove
H> it, then searches "^..." and incidentally finds "to " because
H> the first line is now ;

H> 	to the next ...

H> Therefore, the operation (replace-regexp "^..." "" nil) means
H> "remove all characters other than last N (= L mod 3) chars
H> from every lines whose length is L."

H> So, to remove first 3 chars of every lines, try

H> 	(replace-regexp "^...\\(.*\\)" "\\1" nil)

H> (or M-x replace-regexp<cr> ^...\(.*\)<cr> \1<cr>)

> Furthermore, hitting UNDO
> reveals that it's going to take me a thousand undoes before I can
> restore the damage from that _single_ replace-regexp.

H> This is also feature, and I read same complaint in
H> gnu.emacs.XXX many times.  If you want to _fix_ it, change
H> the function perform-replace (in replace.el) as following;

H> (a) remove (undo-boundary)
H> (b) put (undo-boundary) just before (while ...

H> Note that this modification will affect the undoing manner
H> of replace-string, query-replace, query-replace-regexp, and
H> other functions (I don't know) calling perform-replace.
H> ---------------------------------------------------------------------
H> Hiroshi Nakashima (hiroshi@isl.melco.co.jp)
H> Computer & Information Systems Lab., Mitsubishi Electric Corp.
H> 5-1-1 Ofuna, Kamakura, 247 Japan.       phone:+81-467-44-6136

>>>>> On Mon, 26 Aug 91 12:24:32 EDT, tmb@ai.mit.edu (Thomas M. Breuel) said:

Thomas> Actually, you should know to use M-x rep reg <CR>^...\(.*\)$<CR>\1<CR>

Conclusion: all this means that the replace functions are all probably
overly knotted together in the source, which I'm too lazy to check.
Therefore, if they are not going to be untangled, then appropriate
warnings should be placed in the manual, function documentation, etc.
Technical Details
Message-ID: <1991Aug27Tu095351.Dan_Jacobson@ATT.COM>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!att.com!Dan_Jacobson
References: <1991Aug22Th170556.Dan_Jacobson@ATT.COM>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,f3690386f4e03123
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-08-27 07:53:00 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!att.com!Dan_Jacobson
From: Dan_Jacobson@att.com
Newsgroups: gnu.emacs.bug
Subject: (replace-regexp "^..." "" nil) fiasco
Message-ID: <1991Aug27Tu095351.Dan_Jacobson@ATT.COM>
Date: 27 Aug 91 14:53:00 GMT
References: <1991Aug22Th170556.Dan_Jacobson@ATT.COM>
Sender: gnulists@ai.mit.edu
Reply-To: Dan_Jacobson@ihlpz.att.com
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 88
Approved: bug-gnu-emacs@prep.ai.mit.edu