From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Re: (save-excursion (other-window 1)) leaves me in the other window Date: Sun, 07 Mar 2010 19:09:18 -0800 Message-ID: References: <87y6i4sjsn.fsf@rapttech.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1272990540 6575 80.91.229.12 (4 May 2010 16:29:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 16:29:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 04 18:28:59 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9KzS-0000TR-F9 for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 18:28:58 +0200 Original-Received: from localhost ([127.0.0.1]:37591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9KzR-0004ea-Qi for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 12:28:57 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Sun, 07 Mar 2010 21:09:22 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) Cancel-Lock: sha1:Bv6ZcCgh72hyoSaxdMHfNqik9iA= Original-Lines: 54 Original-X-Trace: sv3-bxeOOUqY5iVZFj7/AaB2sgMw/pWA5xoAd8m8J5p1jVRtaHOFJjnJVBd/kF9+OzR237PV599K1wvnDYW!8Wei+sC/yYURpECkFUHJH9N4pRoV4yA19yH+liZqC4/ELionv115CQKh Original-X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: usenet.stanford.edu gnu.emacs.help:177394 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72929 Archived-At: Tim X writes: > Sean McAfee 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.