help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: restore region after replace-string


From: Paul Madden
Subject: Re: restore region after replace-string
Date: Sat, 15 Jan 2011 13:07:59 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

Hi Rolf,

> hmm I tried to find any switch in the documentation, but AFAIS it's an
> integral feature of transient-mark-mode to disable the highlighting
> after any changes in the buffer: 'Changing the buffer "deactivates"
> the mark.'

Definitely: I don't expect to stop the deactivation of the mark but only hope to
re-establish the region *after* replace-string has deactivated it.

I'm confused as to why C-x C-x C-x C-x works perfectly when I actually type the
keystrokes after my replace-string wrapper function returns, but the equivalent
two calls to (exchange-point-and-mark) inside my function fail. And having the
calls in a function isn't the problem, because if I

(defun zzz () (interactive) (exchange-point-and-mark) (exchange-point-and-mark))

and M-x zzz after calling my replace-string wrapper, it works just as well as
typing C-x C-x C-x C-x. It seems something else is happening inside

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

that kills the re-established region when the function returns.

And the region does seem to be re-established -- as mentioned in my previous
email, if I prevent a normal return from the function by adding a final bogus
call to a non-existent function in rs, I can see that the region has been
re-established and highlighted. But if rs returns normally, the new region gets
killed again. Maybe it's a bug.

> - either explicitely mark the region by memorizing point and mark or
> getting those positions from the mark-ring

It seems to me that point and mark are still valid, and the two calls to
(exchange-point-and-mark) are supposed, as you say, to explicitly mark the
region. But, to be more explicit, I also tried this:

(defun rs()
  (interactive)
  (point-to-register 1)
  (call-interactively 'replace-string)
  (exchange-point-and-mark)
  (push-mark (point) t t)
  (jump-to-register 1))

This behaves exactly the same way as the function above, and if I add a bogus
call at the end:

(defun rs()
  (interactive)
  (point-to-register 1)
  (call-interactively 'replace-string)
  (exchange-point-and-mark)
  (push-mark (point) t t)
  (jump-to-register 1)
  (asdf))

I again see the region re-established, but a message in the minibuffer about
void symbol asdf. In fact, if I could ignore the error message (hard to do),
this function does exactly what I want. But why?

> - or use narrow-to-region and widen afterwords, like this you can use
> anything you want on the region.

I tried that earlier, too. But I like the behavior of replace-string and don't
want to try to write a clone. Plus, I will want to similarly wrap other
functions like query-replace, replace-regexp, etc. and don't want to to
reimplement them as well.

I'm still trying things, and more ideas are always appreciated.

paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]