unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* please implement query-exchange
@ 2002-11-16  1:59 Dan Jacobson
  2002-11-16 18:14 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Dan Jacobson @ 2002-11-16  1:59 UTC (permalink / raw)


Maybe there should be a query-exchange function, e.g.  I want to make
all the x's become y, and all the y's become x, in
atan(x()-$xc,y()-$yc). It seems one would have a hard time doing that
with existing emacs tools.  One would have to query-replace to make x
into a temp string, then do y->x, then do temp->y: to tough for the
average user.  Therefor please implement query-exchange: looks and
feels like query-replace, but does exchanges...
-- 
http://jidanni.org/ Taiwan(04)25854780

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-16  1:59 please implement query-exchange Dan Jacobson
@ 2002-11-16 18:14 ` Eli Zaretskii
       [not found]   ` <8765uvpx52.fsf@jidanni.org>
  2002-11-19 17:25   ` Ami Fischman
  0 siblings, 2 replies; 14+ messages in thread
From: Eli Zaretskii @ 2002-11-16 18:14 UTC (permalink / raw)


> From: Dan Jacobson <jidanni@dman.ddts.net>
> Date: 16 Nov 2002 09:59:40 +0800
> 
> Maybe there should be a query-exchange function, e.g.  I want to make
> all the x's become y, and all the y's become x, in
> atan(x()-$xc,y()-$yc).

Can't you do that with query-replace-regexp using parenthesized
subexpressions and the \N feature (where N is a digit)?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
       [not found]     ` <9003-Mon18Nov2002210929+0200-eliz@is.elta.co.il>
@ 2002-11-18 23:37       ` Dan Jacobson
  2002-11-19  6:57         ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Dan Jacobson @ 2002-11-18 23:37 UTC (permalink / raw)


Um, there is some misunderstanding here.  I want someone to add a
command to emacs: (query-exchange "x" "y") which will change all x's
to y's, just like query-replace, but it will also change all y's to
x's at the same time.

Eli on the other hand feels the existing tools with proper instruction
are enough.

I say that adding my nice command is much more convenient for the
simple user than the Eli Boot Camp: It all started when I wanted to
exchange x and y in

>>> atan(x()-$xc,y()-$yc).
>> 
Eli> Can't you do that with query-replace-regexp using parenthesized
Eli> subexpressions and the \N feature (where N is a digit)?
>> 
>> Maybe you could, and if so maybe you could write up just how one does
>> it and add it to the Info page.  Sounds rather advanced.

Eli> M-x query-replace-regexp RET
Eli> \(x\)\(.*\)\(xc\)\(.*\)\(y\)\(.*\)\(yc\) RET \5\2\7\4\1\6\3 RET

Eli> does this for me.  Is it really advanced?

Naw.  Kid stuff. \5\2\7\4\1\6\3 ? Why of course.  Mom taught that to
me when I was 5 years old.

$ echo 'atan(x()-$xc,y()-$yc)'|tr x B|tr y x|tr B y
atan(y()-$yc,x()-$xc)
is all I am trying to do, by the way.
-- 
http://jidanni.org/ Taiwan(04)25854780

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-18 23:37       ` Dan Jacobson
@ 2002-11-19  6:57         ` Eli Zaretskii
  2002-11-19 21:57           ` Dan Jacobson
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2002-11-19  6:57 UTC (permalink / raw)
  Cc: bug-gnu-emacs


On 19 Nov 2002, Dan Jacobson wrote:

> Naw.  Kid stuff. \5\2\7\4\1\6\3 ? Why of course.  Mom taught that to
> me when I was 5 years old.

Thank you so much for mocking me in a public forum.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-16 18:14 ` Eli Zaretskii
       [not found]   ` <8765uvpx52.fsf@jidanni.org>
@ 2002-11-19 17:25   ` Ami Fischman
  2002-11-19 17:59     ` Eli Zaretskii
  1 sibling, 1 reply; 14+ messages in thread
From: Ami Fischman @ 2002-11-19 17:25 UTC (permalink / raw)


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

[...]

> Can't you do that with query-replace-regexp using parenthesized
> subexpressions and the \N feature (where N is a digit)?

Is this really possible?  When I first read your post, I just said to
myself "oh, yeah, that's right; that should take care of it" but later on I
actually tried to implement a query-exchange function using only one
query-replace-regexp, and couldn't figure out how to do it.  I see from (a
private email?) that Dan posted to the list that you suggested to him a
regexp that would take care of his particular string of text, but I'm now
more curious about the general problem.  Can anyone here implement an
exchange in a single RE replace?  More an academic challenge than an emacs
bug (or even feature request) since what Dan was asking for can be done
in a lisp function anyway.

Cheers,
-- 
  Ami Fischman
  usenet@fischman.org

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-19 17:25   ` Ami Fischman
@ 2002-11-19 17:59     ` Eli Zaretskii
  2002-11-19 19:18       ` Ami Fischman
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2002-11-19 17:59 UTC (permalink / raw)
  Cc: bug-gnu-emacs

> From: Ami Fischman <usenet@fischman.org>
> Date: Tue, 19 Nov 2002 09:25:19 -0800
> 
> "Eli Zaretskii" <eliz@is.elta.co.il> writes:
> 
> [...]
> 
> > Can't you do that with query-replace-regexp using parenthesized
> > subexpressions and the \N feature (where N is a digit)?
> 
> Is this really possible?  When I first read your post, I just said to
> myself "oh, yeah, that's right; that should take care of it" but later on I
> actually tried to implement a query-exchange function using only one
> query-replace-regexp, and couldn't figure out how to do it.  I see from (a
> private email?) that Dan posted to the list that you suggested to him a
> regexp that would take care of his particular string of text, but I'm now
> more curious about the general problem.

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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-19 17:59     ` Eli Zaretskii
@ 2002-11-19 19:18       ` Ami Fischman
  2002-11-19 22:10         ` Francesco Potorti`
  0 siblings, 1 reply; 14+ messages in thread
From: Ami Fischman @ 2002-11-19 19:18 UTC (permalink / raw)


"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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-19  6:57         ` Eli Zaretskii
@ 2002-11-19 21:57           ` Dan Jacobson
  0 siblings, 0 replies; 14+ messages in thread
From: Dan Jacobson @ 2002-11-19 21:57 UTC (permalink / raw)


Anyway, how about we dispose of my bug by merely adding to the
query-replace Info pages:

  But what if you want to say, _exchange_ x and y: replace x's with
  y's, but at the same time replace y's with x's?  Well, try something
  like
  (query-replace "x" "@TEMP@")
  (query-replace "y" "x")
  (query-replace "@TEMP@" "y")
-- 
http://jidanni.org/ Taiwan(04)25854780

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-19 19:18       ` Ami Fischman
@ 2002-11-19 22:10         ` Francesco Potorti`
  2002-11-19 23:43           ` Dan Jacobson
  2002-11-20  1:03           ` Dan Jacobson
  0 siblings, 2 replies; 14+ messages in thread
From: Francesco Potorti` @ 2002-11-19 22:10 UTC (permalink / raw)


Untested:

(defun query-exchange ( &optional fstr sstr )
  "Exchanges all occurences of fstr with sstr and vice-versa in the region."
  (interactive)
  (if (interactive-p)
      (progn
	(setq fstr (read-from-minibuffer "First string: "))
	(setq sstr (read-from-minibuffer "Second string: "))))
  (save-excursion
    (goto-char (region-beginning)
    (while (re-search-forward 
             (concat "\\(" fstr "\\)\\|\\(" sstr "\\)) (region-end) t)
      (if (nilp (match-beginning 1))
        (replace-match fstr)
       (replace-match sstr)))))))

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-19 22:10         ` Francesco Potorti`
@ 2002-11-19 23:43           ` Dan Jacobson
  2002-11-20  1:03           ` Dan Jacobson
  1 sibling, 0 replies; 14+ messages in thread
From: Dan Jacobson @ 2002-11-19 23:43 UTC (permalink / raw)


F> 	(setq fstr (read-from-minibuffer "First string: "))
F> 	(setq sstr (read-from-minibuffer "Second string: "))))

why don't you guys make it ask like query-replace:
Query replace x with: y
as seen in the minibuffer, so
Query exchange x with: y

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  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 17:12             ` Richard Stallman
  1 sibling, 2 replies; 14+ messages in thread
From: Dan Jacobson @ 2002-11-20  1:03 UTC (permalink / raw)


Um fellas, where's the 'query' action of your functions?  You are
supposed to ask at each occurrence.  Otherwise call it
exchange-string, and go on to write an additional query-exchange.

With no region defined it should still do something, as query-replace
does.

And in the docstring expand "fstr" to English...

And make sure the final product gets into Emacs.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  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
  1 sibling, 1 reply; 14+ messages in thread
From: Ami Fischman @ 2002-11-20 21:29 UTC (permalink / raw)


Dan, you seem to be misunderstanding at least my intent in posting here.  I
have no write access to the emacs CVS tree, nor do I have any interest in
writing a version polished enough to be included in the official tree.  The
only reason I posted any code at all was that I wrote it for myself and
thought you (and anyone searching the archives in the future) might be
interested.  

Cheers,
-- 
  Ami Fischman
  usenet@fischman.org

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-20  1:03           ` Dan Jacobson
  2002-11-20 21:29             ` Ami Fischman
@ 2002-11-21 17:12             ` Richard Stallman
  1 sibling, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2002-11-21 17:12 UTC (permalink / raw)
  Cc: bug-gnu-emacs

I have doubts that query-exchange is sufficiently useful to be added
to Emacs.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: please implement query-exchange
  2002-11-20 21:29             ` Ami Fischman
@ 2002-11-21 23:22               ` Dan Jacobson
  0 siblings, 0 replies; 14+ messages in thread
From: Dan Jacobson @ 2002-11-21 23:22 UTC (permalink / raw)


>>>>> "A" == Ami Fischman <usenet@fischman.org> writes:

A> Dan, you seem to be misunderstanding at least my intent in posting here.  I
A> have no write access to the emacs CVS tree, nor do I have any interest in
A> writing a version polished enough to be included in the official tree.  The
A> only reason I posted any code at all was that I wrote it for myself and
A> thought you (and anyone searching the archives in the future) might be
A> interested.  

I got my editing job done with my alternate suggestions, but I was
concerned about the, <emotion=on>kids</>, of course, who might be
stuck trying to solve it.

RMS[mail]> I will add something like that to search.texi.

OK good.  Anyway, anything I post to a *.bugs group is for improvement
of the package.  Otherwise I would post to *.help .  The Don Rickles
Attitude is just a bonus so you won't get bored.  That all I POST are
BUGS and no calls for HELP is because the DOCS are not placed in the
right ORDER so I get the ANSWERS :-)
-- 
http://jidanni.org/ Taiwan(04)25854780

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-11-21 23:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).