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

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Tue May 24 13:43:20 PDT 2011


Hi Carl.

On Tue, 24 May 2011 13:20:56 -0700, Carl Worth <cworth at cworth.org> wrote:
> On Mon, 23 May 2011 19:29:46 +0400, Dmitry Kurochkin <dmitry.kurochkin at gmail.com> wrote:
> > Before the change, save-excursion was used to save the point.
> > But the restored position is affected by buffer modifications,
> > which results in jumping cursor.  The patch saves and restores
> > point explicitly by using a variable instead of save-excursion.
> 
> Dmitry,
> 
> Thanks so much for the improvement to the button text! This will be a
> nice thing to add.
> 
> But this patch confuses me. I can understand how a buffer-position
> variable can cause the cursor to jump. That's usually the kind of thing
> that can be fixed by switching from an integer position to a marker
> instead, (since markers are updated when the corresponding text is
> updated).
> 

So we need to switch from marker to an integer position, right?

> But in this case, I don't see how:
> 
> 	(let ((old-point (point)))
>         	... code here ...
> 	  (goto-char old-point))
> 
> is distinct from:
> 
> 	(save-excursion
> 		... code here ...
> 	 )
> 
> except that save-excursion actually does the right thing in the case of
> abnormal exit (throw or error).
> 
> Can you help me understand what I'm missing here?
> 

Unfortunately, I am not an Emacs lisp expert.  I just noticed that the
cursor jumps and did the first thing that came to mind.  And it worked.

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.

Regards,
  Dmitry

> -Carl
> 
> -- 
> carl.d.worth at intel.com
Non-text part: application/pgp-signature


More information about the notmuch mailing list