unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Moving cursor on another window
@ 2011-01-19 13:20 Uday S Reddy
  2011-01-19 13:59 ` martin rudalics
  2011-01-19 15:02 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Uday S Reddy @ 2011-01-19 13:20 UTC (permalink / raw)
  To: emacs-devel

This might be a simple issue, but I could'nt find the answer.

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

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.

Cheers,
Uday




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-19 13:20 Moving cursor on another window Uday S Reddy
@ 2011-01-19 13:59 ` martin rudalics
  2011-01-19 14:24   ` Stephen J. Turnbull
  2011-01-19 15:02 ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: martin rudalics @ 2011-01-19 13:59 UTC (permalink / raw)
  To: Uday S Reddy; +Cc: emacs-devel

 > 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-19 13:59 ` martin rudalics
@ 2011-01-19 14:24   ` Stephen J. Turnbull
  2011-01-19 14:36     ` martin rudalics
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen J. Turnbull @ 2011-01-19 14:24 UTC (permalink / raw)
  To: martin rudalics; +Cc: Uday S Reddy, emacs-devel

martin rudalics writes:

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

I believe that strictly speaking those should be

    (set-window-point W (point-min B))

and

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

since the current buffer will not necessarily have the same point-min
as B.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-19 14:24   ` Stephen J. Turnbull
@ 2011-01-19 14:36     ` martin rudalics
  0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2011-01-19 14:36 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: Uday S Reddy, emacs-devel

> I believe that strictly speaking those should be
> 
>     (set-window-point W (point-min B))
> 
> and
> 
>     (dolist (W (get-buffer-window-list B nil t))
>       (set-window-point W (point-min B)))
> 
> since the current buffer will not necessarily have the same point-min
> as B.

Indeed.  Thanks for the correction.

martin




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-19 13:20 Moving cursor on another window Uday S Reddy
  2011-01-19 13:59 ` martin rudalics
@ 2011-01-19 15:02 ` Stefan Monnier
  2011-01-20 12:13   ` Uday S Reddy
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2011-01-19 15:02 UTC (permalink / raw)
  To: Uday S Reddy; +Cc: emacs-devel

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

You might like to try

  (with-selected-window (buffer-window other-buffer)
    (goto-char (point-min)))

instead.

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

Every window has its own `point' (to which you have access via
(set-)window-point and that is also influenced by
window-point-insertion-type).  When current-buffer is the buffer shown
by the selected-window, moving the buffer's point also moves the
window's point, but otherwise no.


        Stefan



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-19 15:02 ` Stefan Monnier
@ 2011-01-20 12:13   ` Uday S Reddy
  2011-01-20 12:52     ` Thierry Volpiatto
  0 siblings, 1 reply; 7+ messages in thread
From: Uday S Reddy @ 2011-01-20 12:13 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: tcross, emacs-devel

Dear Martin and Stefan, Thanks for the responses.  I understand the 
point about window-point now.

The reason for my asking the question is that I was trying to narrow 
down a possible bug in Emacs 23.2.92 pretest.  The same problem has also 
been mentioned with the recent revisions in the Emacs trunk

The way the problem is exhibited in the VM mail reader is that the 
cursor in the Summary window doesn't move after moving to a different 
message.  This movement is done in a function called 
vm-set-summary-pointer which is called from different places in VM. 
Some of these calls work fine but others don't.  I was trying to narrow 
down the difference between the contexts, but I couldn't really find 
much difference.

(vm-set-summary-pointer has the correct calls to set the window-point 
and I don't think anything is wrong with its code.  It has been working 
fine for ages.)

On the surface, this seems similar to the problem mentioned by Thierry 
Volpato a couple of days ago.

More details at the VM bug report https://bugs.launchpad.net/vm/+bug/703775

Cheers,
Uday




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Moving cursor on another window
  2011-01-20 12:13   ` Uday S Reddy
@ 2011-01-20 12:52     ` Thierry Volpiatto
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2011-01-20 12:52 UTC (permalink / raw)
  To: emacs-devel

Uday S Reddy <u.s.reddy@cs.bham.ac.uk> writes:

> Dear Martin and Stefan, Thanks for the responses.  I understand the
> point about window-point now.
>
> The reason for my asking the question is that I was trying to narrow
> down a possible bug in Emacs 23.2.92 pretest.  The same problem has
> also been mentioned with the recent revisions in the Emacs trunk
>
> The way the problem is exhibited in the VM mail reader is that the
> cursor in the Summary window doesn't move after moving to a different
> message.  This movement is done in a function called
> vm-set-summary-pointer which is called from different places in
> VM. Some of these calls work fine but others don't.  I was trying to
> narrow down the difference between the contexts, but I couldn't really
> find much difference.
>
> (vm-set-summary-pointer has the correct calls to set the window-point
> and I don't think anything is wrong with its code.  It has been
> working fine for ages.)
>
> On the surface, this seems similar to the problem mentioned by Thierry
> Volpato a couple of days ago.
I am actually using 23.2.92 with the changes on window.c made by Martin
and all work fine, maybe you can try also to apply these changes to see
if they fix your problem in VM.
Also, his patch, that is for Emacs24 now, work fine also.

> More details at the VM bug report https://bugs.launchpad.net/vm/+bug/703775
>
> Cheers,
> Uday
>
>
>

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-01-20 12:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-19 13:20 Moving cursor on another window Uday S Reddy
2011-01-19 13:59 ` martin rudalics
2011-01-19 14:24   ` Stephen J. Turnbull
2011-01-19 14:36     ` martin rudalics
2011-01-19 15:02 ` Stefan Monnier
2011-01-20 12:13   ` Uday S Reddy
2011-01-20 12:52     ` Thierry Volpiatto

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).