all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* restore region after replace-string
@ 2011-01-14 22:57 Paul Madden
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Madden @ 2011-01-14 22:57 UTC (permalink / raw)
  To: help-gnu-emacs

I'm not sure whether to ask the general or the specific question, so I'll ask both:

Generally, I'd like the region I've defined (transient-mark-mode on) to be
restored after a command like replace-string. I often want to run many
replacements on the same region, and don't want to keep recreating it. I thought
I'd mention the real goal, in case there's a better method than what follows.

Specifically, here's what I've tried:

(defun rs1 ()
  (interactive)
  (save-excursion (call-interactively 'replace-string)))

If I create a region and M-x rs1, the replacement works, point is restored, and
then I can use C-x C-x C-x C-x to get what I want: The same region highlighted
with point at its end.

But I don't want the extra keystrokes, so try to make the function do it for me:

(defun rs2 ()
  (interactive)
  (save-excursion (call-interactively 'replace-string))
  (exchange-point-and-mark)
  (exchange-point-and-mark))

But no region is highlighted. And if I do M-x replace-string after rs2, the
replacement occurs only below point in the buffer, so it seems no region is active.

Interestingly, though:

(defun rs3 ()
  (interactive)
  (save-excursion (call-interactively 'replace-string))
  (exchange-point-and-mark)
  (exchange-point-and-mark)
  (asdf))

After rs3, my region is highlighted with point at its end, and there's a
"definition is void" message (for the bogus (asdf) call) in the minibuffer. But
I can run replace-string now and it operates on the highlighted region.

So it seems like what I want is happening in rs3 (plus an unwanted error)... but
is undone when the function returns.

Can anybody shed any light on this, or point me in a better direction?

Incidentally, this is GNU Emacs 24.0.50.1, built from source, but I just tried
21.4.1 and it behaves the same.

thanks!
paul



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

end of thread, other threads:[~2011-01-17  2:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.10.1295051790.18911.help-gnu-emacs@gnu.org>
2011-01-15 13:23 ` restore region after replace-string LanX
2011-01-15 20:07   ` Paul Madden
2011-01-16 10:28   ` Le Wang
2011-01-16 17:08     ` Paul Madden
2011-01-17  2:22       ` Le Wang
2011-01-17  2:38         ` Paul Madden
     [not found]   ` <mailman.15.1295181948.22773.help-gnu-emacs@gnu.org>
2011-01-16 18:24     ` LanX
2011-01-14 22:57 Paul Madden

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.