emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Moving cursor on another window


From: martin rudalics
Subject: Re: Moving cursor on another window
Date: Wed, 19 Jan 2011 14:59:15 +0100
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

> If I have multiple windows showing (with different buffers in them), and
> I want to move the cursor in a window other than the current one, how is
> that supposed to be done?  The following pattern of code doesn't seem to
> work:
>
>   (with-current-buffer other-buffer
>      (beginning-of-buffer))

If the pattern did work as you intended, showing the same buffer
simultaneously in two windows would not make sense: Whenever you moved
the cursor in one window it would move in the other window to the same
position.

> It works if the other-buffer is not currently displayed in a window. But
> if it is displayed, the cursor remains unchanged.  I guess there is some
> implicit save-excursion at the top level somewhere.  I can't see how to
> get around it.

It depends on what you want.  To move point in a specific window W use
(set-window-point W (point-min)).  To move it in all windows showing a
buffer B use

(dolist (W (get-buffer-window-list B nil t))
  (set-window-point W (point-min)))

Any of these will move the buffer's point if and only if W is the
selected window when you call `set-window-point'.  If you want to make
sure that the buffer's point moves too use

(with-current-buffer B
  (goto-char (point-min))

since the doc-string of `beginning-of-buffer' tells you
"Don't use this command in Lisp programs!" ;-)

martin



reply via email to

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