[Top][All Lists]

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

Re: please implement query-exchange

From: Ami Fischman
Subject: Re: please implement query-exchange
Date: Tue, 19 Nov 2002 11:18:24 -0800
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2.50 (i686-pc-linux-gnu)

"Eli Zaretskii" <eliz@is.elta.co.il> writes:


> I didn't mean to suggest a general solution.  I meant to say that for
> each specific case one can devise a regexp and a replacement string
> with \N that solves that particular case.


I liked the idea of the request, though, so wrote the following.  Posting
since it might be useful to others (including the OP).  Lisp is far from my
forte, so this can probably be done much more simply/quickly.

(defun query-exchange ( &optional fstr sstr )
  "Exchanges all occurences of fstr with sstr and vice-versa in the region.  
   Both strings must not contain any NUL (\000) characters."
  (setq nulstr "\000"
        rb (region-beginning)
        re (region-end)
        initialpos (point))
  (if (interactive-p)
        (setq fstr (read-from-minibuffer "First string: "))
        (setq sstr (read-from-minibuffer "Second string: "))))
  (goto-char rb)
  (while (search-forward nulstr re t)
    (setq nulstr (concat nulstr nulstr))
    (goto-char rb))
  (replace-string fstr nulstr nil rb re)
  (replace-string sstr fstr nil rb re)
  (replace-string nulstr sstr nil rb re)
  (goto-char initialpos))
;; Mark following line, then eval (query-exchange "x" "y") or M-x query-exchange
;; atan(x()-$xc,y()-$yc y)

  Ami Fischman

reply via email to

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