* Update point in visible but non-selected buffer/window
@ 2016-10-21 8:39 Joost Kremers
2016-10-21 15:16 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2016-10-21 8:39 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi all,
I just found out the hard way that changing point programmatically
(i.e., from within an Elisp program) in a buffer that is visible
in a non-selected window doesn't (necessarily?) update the
position of the cursor, and when the window is selected again,
point is reset to the cursor position.
To be more explicit:
Suppose I have two buffers, A and B, being displayed in two
windows, W_a and W_b. W_a is selected, point is at the beginning
of the buffer. Now I select W_b. In W_a, the cursor is still
visible as a hollow box. In W_b, I execute some command that moves
point in buffer A (specifically, by using `re-search-forward'
inside a `with-current-buffer'). The cursor in W_a does not move,
however. Still, as long as I do not select W_a, point is where
`re-search-forward' left it (and thus does not correspond to the
visible cursor position). For example, when I do something like:
(with-current-buffer "A" (point))
I get the result I expect, which is not the position where I see
the (hollow) cursor.
However, if I then select window W_a, the hollow cursor is changed
back into a box, but it remains at the position where it was all
the time, i.e., at the beginning of the buffer, and point is
adjusted accordingly.
I can see why this behaviour makes sense from a user's
perspective, and I figured out that I can call `select-window'
inside `with-current-buffer' to force the cursor position to
change as well as point. But I haven't been able to find any info
on this behaviour in the Elisp manual, so I was wondering if this
has been described somewhere and whether the solution I stumbled
upon (using `select-window') is the best way to achieve the effect
I want, or whether there is a better, more canonical way.
TIA
Joost
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Update point in visible but non-selected buffer/window
2016-10-21 8:39 Update point in visible but non-selected buffer/window Joost Kremers
@ 2016-10-21 15:16 ` Eli Zaretskii
2016-10-21 21:37 ` Joost Kremers
0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2016-10-21 15:16 UTC (permalink / raw)
To: help-gnu-emacs
> From: Joost Kremers <joostkremers@fastmail.fm>
> Date: Fri, 21 Oct 2016 10:39:37 +0200
>
> I just found out the hard way that changing point programmatically
> (i.e., from within an Elisp program) in a buffer that is visible
> in a non-selected window doesn't (necessarily?) update the
> position of the cursor, and when the window is selected again,
> point is reset to the cursor position.
This is by design. That's what window-point is about. When you
select a window, the buffer shown in that window gets its point reset
to the place of window-point, and the cursor is positioned
accordingly.
> I can see why this behaviour makes sense from a user's
> perspective, and I figured out that I can call `select-window'
> inside `with-current-buffer' to force the cursor position to
> change as well as point. But I haven't been able to find any info
> on this behaviour in the Elisp manual, so I was wondering if this
> has been described somewhere and whether the solution I stumbled
> upon (using `select-window') is the best way to achieve the effect
> I want, or whether there is a better, more canonical way.
See window-point and set-window-point.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Update point in visible but non-selected buffer/window
2016-10-21 15:16 ` Eli Zaretskii
@ 2016-10-21 21:37 ` Joost Kremers
0 siblings, 0 replies; 3+ messages in thread
From: Joost Kremers @ 2016-10-21 21:37 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Fri, Oct 21 2016, Eli Zaretskii wrote:
>> From: Joost Kremers <joostkremers@fastmail.fm>
>> Date: Fri, 21 Oct 2016 10:39:37 +0200
>>
>> I just found out the hard way that changing point
>> programmatically
>> (i.e., from within an Elisp program) in a buffer that is
>> visible
>> in a non-selected window doesn't (necessarily?) update the
>> position of the cursor, and when the window is selected again,
>> point is reset to the cursor position.
>
> This is by design. That's what window-point is about. When you
> select a window, the buffer shown in that window gets its point
> reset
> to the place of window-point, and the cursor is positioned
> accordingly.
Yeah, I assumed it was by design, because it makes sense.
>> I can see why this behaviour makes sense from a user's
>> perspective, and I figured out that I can call `select-window'
>> inside `with-current-buffer' to force the cursor position to
>> change as well as point. But I haven't been able to find any
>> info
>> on this behaviour in the Elisp manual, so I was wondering if
>> this
>> has been described somewhere and whether the solution I
>> stumbled
>> upon (using `select-window') is the best way to achieve the
>> effect
>> I want, or whether there is a better, more canonical way.
>
> See window-point and set-window-point.
Thanks. I missed that.
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-21 21:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-21 8:39 Update point in visible but non-selected buffer/window Joost Kremers
2016-10-21 15:16 ` Eli Zaretskii
2016-10-21 21:37 ` Joost Kremers
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).