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

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

Update point in visible but non-selected buffer/window


From: Joost Kremers
Subject: Update point in visible but non-selected buffer/window
Date: Fri, 21 Oct 2016 10:39:37 +0200
User-agent: mu4e 0.9.17; emacs 25.1.2

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



reply via email to

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