[PATCH] Save and restore point explicitly in `notmuch-wash-toggle-invisible-action'.

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Tue May 24 15:16:06 PDT 2011


On Tue, 24 May 2011 15:01:04 -0700, Carl Worth <cworth at cworth.org> wrote:
> On Wed, 25 May 2011 00:43:20 +0400, Dmitry Kurochkin <dmitry.kurochkin at gmail.com> wrote:
> > Now, looking at Emacs source code, save_excursion_save() uses
> > point_marker() to save the point.  As you said above, markers are
> > updated when the corresponding text is updated.  That explains why the
> > cursor jumps when using `save-excursion'.
> > 
> > On the other hand, `point' returns position as an integer.  Which is
> > just what we need.
> 
> Ah. So that explains why your patch is actually making a difference.
> 
> But I've usually had "jumping cursor" problems when using an integer,
> (and switching to a marker fixes it). For example, imagine the following
> operation:
> 
> 	User positions cursor on some word
> 	Our code saves point as an integer
> 	Some operation inserts new text before point
> 	Our code restores the cursor to the saved integer
> 
> This sequence restores point to the same integer position in the buffer,
> but logically makes the cursor appear to "jump" to the user, (since the
> cursor will no longer be on the word it was on before but will now be
> earlier in the buffer).
> 
> The fix for the above is to switch from an integer to a marker.
> 

Ah, I see now.

> So I'm curious to know the case you're hitting where you getbetter
> behavior by switching from a marker to an integer. Can you describe it
> in a bit more detail?
> 

I did not find a better way to update the button label than to:

1. insert the new label
2. move the button overlay from the old label to the new one
3. remove the old label

When a user clicks the button, the cursor is somewhere inside the old
label.  If we save the point as a marker, after step 3 it would end up
at the position where the old label was.  If the new label is inserted
before the old one, that means after the new label.  So the cursor jumps
from inside the button to the position after the button.  Since the new
button is placed at the same position where the old one was, restoring
the point to the same offset it was at the beginning works as we need.

Regards,
  Dmitry

> -Carl
Non-text part: application/pgp-signature


More information about the notmuch mailing list