* 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
[parent not found: <8765uvpx52.fsf@jidanni.org>]
* 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 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 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
* 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
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).