[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (save-excursion (other-window 1)) leaves me in the other window
From: |
Sean McAfee |
Subject: |
Re: (save-excursion (other-window 1)) leaves me in the other window |
Date: |
Tue, 04 May 2010 15:41:49 -0000 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) |
Tim X <timx@nospam.dev.null> writes:
> Sean McAfee <eefacm@gmail.com> writes:
>> A native reimplementation of scroll-other-window doesn't work as I'd
>> expect:
>>
>> (save-excursion
>> (other-window 1)
>> (scroll-up))
>>
>> The problem is that the current window isn't restored, which surprised
>> me considerably. Why doesn't this work, and how would I write a
>> function to go do some stuff in the other window and then come back?
>
> As emacs already has the command to scroll the other window, I'm
> assuming your example is a simplification of what you really want to do.
True. The situation is this:
I have a frame, split horizontally into two windows. One window shows
text that came from an OCR process; the other window, in image-mode,
shows the (large) image that was the input to that OCR process. What I
want to do is work in the text window, shifting the image in the other
window around as I check it against the text. I assumed I could do
something like this:
(defmacro in-other-window (&rest body)
`(save-excursion (other-window 1) ,@body))
And then:
(global-set-key [(shift down)]
(lambda () (interactive) (in-other-window (image-next-line))))
...and similarly for the other three directions.
Although the documentation for save-excursion says that it saves and
restores the current buffer, it doesn't in this case. I still don't
really know why. I tried using save-window-excursion instead as Joe
Fineman suggested, but while that worked for image-next-line and
image-previous-line, it doesn't for image-forward-hscroll, which I need
for scrolling horizontally. I guess the horizontal scroll amount is
something that's saved and restored by save-window-excursion. So I
finally settled on this:
(defmacro in-other-window (&rest body)
`(progn
(other-window 1)
(unwind-protect
(progn ,@body)
(other-window -1))))
I just have to be careful not to alter the window configuration from
within in-other-window.
- (save-excursion (other-window 1)) leaves me in the other window, Sean McAfee, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, Joe Fineman, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, Tim X, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window,
Sean McAfee <=
- Re: (save-excursion (other-window 1)) leaves me in the other window, Tim X, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, Sean McAfee, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, Tim X, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, Sean McAfee, 2010/05/04
- Re: (save-excursion (other-window 1)) leaves me in the other window, David Kastrup, 2010/05/04