Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id AC4DF431FD0 for ; Tue, 24 May 2011 16:20:42 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GyIuJHuueBrN for ; Tue, 24 May 2011 16:20:42 -0700 (PDT) Received: from arlo.cworth.org (arlo.cworth.org [50.43.72.2]) by olra.theworths.org (Postfix) with ESMTP id 0A485431FB6 for ; Tue, 24 May 2011 16:20:42 -0700 (PDT) Received: from yoom.home.cworth.org (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 7D5DA29A482; Tue, 24 May 2011 16:20:40 -0700 (PDT) Received: by yoom.home.cworth.org (Postfix, from userid 1000) id 6D5E625417E; Tue, 24 May 2011 16:20:40 -0700 (PDT) From: Carl Worth To: Austin Clements , Dmitry Kurochkin Subject: Re: [PATCH] Save and restore point explicitly in `notmuch-wash-toggle-invisible-action'. In-Reply-To: References: <1306090675-26982-1-git-send-email-dmitry.kurochkin@gmail.com> <1306164587-20326-1-git-send-email-dmitry.kurochkin@gmail.com> <87oc2rlujb.fsf@yoom.home.cworth.org> <8762ozrfrr.fsf@gmail.com> <87oc2rvjvj.fsf@yoom.home.cworth.org> <871uznrbh5.fsf@gmail.com> User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) Date: Tue, 24 May 2011 16:20:34 -0700 Message-ID: <87d3j7bs8t.fsf@yoom.home.cworth.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2011 23:20:42 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Transfer-Encoding: quoted-printable On Tue, 24 May 2011 18:43:41 -0400, Austin Clements wrot= e: > 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). >=20 > 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. =2DCarl --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Carefully-preverse-point-when-changing-button-text-i.patch Content-Transfer-Encoding: quoted-printable From=20a32e02bf0d2b57d51695f7d4ea6cdda9acb21322 Mon Sep 17 00:00:00 2001 From: Carl Worth 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). =2D-- 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 =2D-- 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)) =2D (save-excursion =2D (goto-char new-start) =2D (insert button-label) =2D (let ((old-end (button-end cite-button))) =2D (move-overlay cite-button new-start (point)) =2D (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)) =20 =2D-=20 1.7.5.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk3cPUIACgkQ6JDdNq8qSWh5CQCfS5/Ou7cLRlPUPCR1cdsZyndT kaEAnRLbfPoD2mFfLD2Y+c7A/PqEERkY =IDmP -----END PGP SIGNATURE----- --==-=-=--