all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: (save-excursion (other-window 1)) leaves me in the other window
Date: Sun, 07 Mar 2010 17:55:04 +1100	[thread overview]
Message-ID: <87y6i4sjsn.fsf@rapttech.com.au> (raw)
In-Reply-To: m3k4tqqzk0.fsf@palantirtech.com

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


  parent reply	other threads:[~2010-03-07  6:55 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 [this message]
2010-03-08  3:09   ` Sean McAfee
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=87y6i4sjsn.fsf@rapttech.com.au \
    --to=timx@nospam.dev.null \
    --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.