all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ami Fischman <usenet@fischman.org>
Subject: Re: please implement query-exchange
Date: Tue, 19 Nov 2002 11:18:24 -0800	[thread overview]
Message-ID: <m3fztxqsfz.fsf@fischman.org> (raw)
In-Reply-To: 3405-Tue19Nov2002205907+0200-eliz@is.elta.co.il

"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.

Gotcha.

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."
  (interactive)
  (setq nulstr "\000"
	rb (region-beginning)
	re (region-end)
	initialpos (point))
  (if (interactive-p)
      (progn
	(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
  usenet@fischman.org

  reply	other threads:[~2002-11-19 19:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-16  1:59 please implement query-exchange Dan Jacobson
2002-11-16 18:14 ` Eli Zaretskii
     [not found]   ` <8765uvpx52.fsf@jidanni.org>
     [not found]     ` <9003-Mon18Nov2002210929+0200-eliz@is.elta.co.il>
2002-11-18 23:37       ` Dan Jacobson
2002-11-19  6:57         ` Eli Zaretskii
2002-11-19 21:57           ` Dan Jacobson
2002-11-19 17:25   ` Ami Fischman
2002-11-19 17:59     ` Eli Zaretskii
2002-11-19 19:18       ` Ami Fischman [this message]
2002-11-19 22:10         ` Francesco Potorti`
2002-11-19 23:43           ` Dan Jacobson
2002-11-20  1:03           ` Dan Jacobson
2002-11-20 21:29             ` Ami Fischman
2002-11-21 23:22               ` Dan Jacobson
2002-11-21 17:12             ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3fztxqsfz.fsf@fischman.org \
    --to=usenet@fischman.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.