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

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

search&replace macro puzzle please help...


From: Chris Seberino
Subject: search&replace macro puzzle please help...
Date: Mon, 17 Sep 2001 13:33:46 -0700
User-agent: Mutt/1.2.5i

Hello! 

I want a search and replace command that 

1. works thru entire doc
2. ends up in same place as before

I got this so far...

(defun new-replace-string(search-string replace-string)
   (interactive "ssearch string: \nsreplace string: ")
   (setq total-fix 0)
   (setq fix-per-replacement (- (length replace-string)
                                (length search-string)
                                )
      )
   (setq initial-shift (- (point) 1))
   (backward-char initial-shift)
   (while (search-forward  search-string nil t)
      (replace-match replace-string nil t)
      (setq total-fix (+ total-fix fix-per-replacement))
      )
   (backward-char (- (point) 1))
   (forward-char (+ initial-shift 0))
)

THE TRICKY PART IS GETTING CURSOR BACK TO ORIGINAL
POSITION.  THE MATH IS TRICKY DUE TO DIFFERENT
LENGTH OF search-string & replace-string and
probably also because of tabs.

Any help would be greatly appreciate.

Sincerely,

Chris
-- 
=======================================================
| Dr. Christian Seberino  || (619) 553-7811 (office1) |
| SPAWARSYSCEN 2733       || (619) 553-2564 (office2) |
| 53560 HULL ST           || (619) 553-6307 (fax)     |
| SAN DIEGO CA 92152-5001 || seberino@spawar.navy.mil |
=======================================================



reply via email to

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