From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Ami Fischman Newsgroups: gmane.emacs.bugs Subject: Re: please implement query-exchange Date: Tue, 19 Nov 2002 11:18:24 -0800 Sender: bug-gnu-emacs-admin@gnu.org Message-ID: References: <87isyynuk3.fsf@jidanni.org> <1438-Sat16Nov2002211425+0200-eliz@is.elta.co.il> <3405-Tue19Nov2002205907+0200-eliz@is.elta.co.il> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1037733467 27578 80.91.224.249 (19 Nov 2002 19:17:47 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 19 Nov 2002 19:17:47 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18EDsX-0007AX-00 for ; Tue, 19 Nov 2002 20:17:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18EDtq-0005r0-00; Tue, 19 Nov 2002 14:19:07 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18EDtW-0005jE-00 for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2002 14:18:46 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18EDtT-0005io-00 for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2002 14:18:45 -0500 Original-Received: from main.gmane.org ([80.91.224.249]) by monty-python.gnu.org with esmtp (Exim 4.10) id 18EDtS-0005ii-00 for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2002 14:18:43 -0500 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18EDrb-00075q-00 for ; Tue, 19 Nov 2002 20:16:47 +0100 Original-To: bug-gnu-emacs@gnu.org X-Injected-Via-Gmane: http://gmane.org/ Original-Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18EDrK-00074U-00 for ; Tue, 19 Nov 2002 20:16:30 +0100 Original-Path: not-for-mail Original-Lines: 40 Original-NNTP-Posting-Host: 12-228-169-213.client.attbi.com Original-X-Trace: main.gmane.org 1037733390 26408 12.228.169.213 (19 Nov 2002 19:16:30 GMT) Original-X-Complaints-To: usenet@main.gmane.org Original-NNTP-Posting-Date: Tue, 19 Nov 2002 19:16:30 +0000 (UTC) Mail-Copies-To: nobody User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2.50 (i686-pc-linux-gnu) Cancel-Lock: sha1:7hYRIQf8o6n/Ls5jZLUSYTcaJls= Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:3912 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:3912 "Eli Zaretskii" 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