all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sean McAfee <eefacm@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: (save-excursion (other-window 1)) leaves me in the other window
Date: Sun, 07 Mar 2010 19:09:18 -0800	[thread overview]
Message-ID: <m2eijvldb5.fsf@gmail.com> (raw)
In-Reply-To: 87y6i4sjsn.fsf@rapttech.com.au

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.


  reply	other threads:[~2010-03-08  3:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-05 20:33 (save-excursion (other-window 1)) leaves me in the other window Sean McAfee
2010-03-05 22:21 ` Joe Fineman
2010-03-07  6:55 ` Tim X
2010-03-08  3:09   ` Sean McAfee [this message]
2010-03-08  7:26     ` Tim X
2010-03-08 16:55       ` Sean McAfee
2010-03-08 17:02         ` Sean McAfee
2010-03-08 17:24           ` David Kastrup
2010-03-09  6:45         ` Tim X

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2eijvldb5.fsf@gmail.com \
    --to=eefacm@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.