From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: (save-excursion (other-window 1)) leaves me in the other window Date: Sun, 07 Mar 2010 17:55:04 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <87y6i4sjsn.fsf@rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1272990215 5317 80.91.229.12 (4 May 2010 16:23:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 16:23:35 +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:23:34 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 1O9KuC-00068d-IJ for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 18:23:32 +0200 Original-Received: from localhost ([127.0.0.1]:36470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9KuB-000229-PH for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 12:23:31 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.93 (gnu/linux) Cancel-Lock: sha1:zEtGYNf5TzkWxb1pl9aKB8zkXF0= Original-Lines: 65 Original-NNTP-Posting-Host: 2b1dc460.news.astraweb.com Original-X-Trace: DXC=On=6d1bNd=]A<6n_>>]9G[L?0kYOcDh@Za30YlQ[TC>ZbgIl@OC:[Y]aCb3`j`aPhYP90; oj 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:72924 Archived-At: 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. However, if you were writing your own version as a learning exercise, the best soruce of help is to look at the source for scroll-other-window. That will probably give you more valuable insight than any of the responses you will get here and you can be fairly confident that the information you get is correct! I'd highly recommend reading the Introduction to Emacs Lisp book that comes with emacs. You will also benefit by doing a high level scan and skim reading of the elisp reference manual. A couple of things to consider. Windows are really the interface for us humans and not necessary the right abstraction to work at if you just want to do non-interactive manipulation of data using elisp. Have a look at buffers. This is where you will generally focus. Often the general approach is 1. Save important data 2. switch to a buffer 3. Do stuff in that buffer 4. Possibly make that buffer *visible* by showing it or just return to wehre you were. The point is, you don't have to do stuff only in a visible buffer. More often than not, you will do stuff in the buffer and either return to where you were, never making what you did visible right then or maybe you will make the work you have done visible once you hve finished doing it. You usually only make the buffer visible prior to doing som eprocessing if you need that to be interactive and the user needs to see what your doing or you are making interface changes, such as scrolling. Also, in addition to save-excursion, have a look at unwind-protect, save-match-data, save-window-excursion, with-current-buffer, with-temp-buffer, set-buffer, current-buffer etc I would also be careful about using constructs like (other-window 1) in elisp code - you don't know what that other window is as it will be different depending on what you are doing. Usually best to work with buffer names when you can. Tim -- tcross (at) rapttech dot com dot au