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

[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: Tim X
Subject: Re: (save-excursion (other-window 1)) leaves me in the other window
Date: Tue, 04 May 2010 15:41:46 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.93 (gnu/linux)

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.
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


reply via email to

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