On Tue, 24 May 2011 16:20:34 -0700, Carl Worth <cworth@cworth.org> wrote: > On Tue, 24 May 2011 18:43:41 -0400, Austin Clements <amdragon@mit.edu> wrote: > > Saving point this way is a bit dangerous, though. For example, if > > you're near the end of the buffer and shorten the label, attempting to > > restore the point could result in an error (or, a more benign example: > > the cursor could wind up outside the label so pressing RET repeatedly > > won't toggle it). > > > > Unfortunately, I don't know of a clean solution to this, but I think I > > would rather the cursor move, but stay within the label (probably > > moving to the beginning), than have problems like the above. > > Here's my fix. Let me know what you think. > (button-end cite-button) would move the point outside the button - to the next character after it. Regards, Dmitry > -Carl > > From a32e02bf0d2b57d51695f7d4ea6cdda9acb21322 Mon Sep 17 00:00:00 2001 > From: Carl Worth <cworth@cworth.org> > Date: Mon, 23 May 2011 19:29:46 +0400 > Subject: [PATCH] Carefully preverse point when changing button text in > `notmuch-wash-toggle-invisible-action'. > > Previously, save-excursion was used to attempt to save the point, but > this was unreliable since the region containing the marker saved by > save-excursion was deleted. Instead, we save an integer position > indicating the offset of point within the old button. Then, we restore > point to the same offset within the new button, (but cap the offset to > avoid leaving the button entirely). > --- > emacs/notmuch-wash.el | 13 +++++++------ > 1 files changed, 7 insertions(+), 6 deletions(-) > > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el > index 8455eee..3dceb8b 100644 > --- a/emacs/notmuch-wash.el > +++ b/emacs/notmuch-wash.el > @@ -82,13 +82,14 @@ collapse the remaining lines into a button.") > (let* ((new-start (button-start cite-button)) > (overlay (button-get cite-button 'overlay)) > (button-label (notmuch-wash-button-label overlay)) > + (button-offset (- (point) new-start)) > (inhibit-read-only t)) > - (save-excursion > - (goto-char new-start) > - (insert button-label) > - (let ((old-end (button-end cite-button))) > - (move-overlay cite-button new-start (point)) > - (delete-region (point) old-end)))) > + (goto-char new-start) > + (insert button-label) > + (let ((old-end (button-end cite-button))) > + (move-overlay cite-button new-start (point)) > + (delete-region (point) old-end)) > + (goto-char (min (button-end cite-button) (+ new-start button-offset)))) > (force-window-update) > (redisplay t)) > > -- > 1.7.5.1 > Non-text part: application/pgp-signature