Re: [PATCH] Save and restore point explicitly in `notmuch-wash-toggle-invisible-action'.
authorCarl Worth <cworth@cworth.org>
Tue, 24 May 2011 23:20:34 +0000 (16:20 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:20 +0000 (09:38 -0800)
a2/23c5a148f70249ddd61e22bc9dbb0610926615 [new file with mode: 0644]

diff --git a/a2/23c5a148f70249ddd61e22bc9dbb0610926615 b/a2/23c5a148f70249ddd61e22bc9dbb0610926615
new file mode 100644 (file)
index 0000000..a127d34
--- /dev/null
@@ -0,0 +1,144 @@
+Return-Path: <cworth@cworth.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id AC4DF431FD0\r
+       for <notmuch@notmuchmail.org>; Tue, 24 May 2011 16:20:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id GyIuJHuueBrN for <notmuch@notmuchmail.org>;\r
+       Tue, 24 May 2011 16:20:42 -0700 (PDT)\r
+Received: from arlo.cworth.org (arlo.cworth.org [50.43.72.2])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0A485431FB6\r
+       for <notmuch@notmuchmail.org>; Tue, 24 May 2011 16:20:42 -0700 (PDT)\r
+Received: from yoom.home.cworth.org (localhost [127.0.0.1])\r
+       by arlo.cworth.org (Postfix) with ESMTP id 7D5DA29A482;\r
+       Tue, 24 May 2011 16:20:40 -0700 (PDT)\r
+Received: by yoom.home.cworth.org (Postfix, from userid 1000)\r
+       id 6D5E625417E; Tue, 24 May 2011 16:20:40 -0700 (PDT)\r
+From: Carl Worth <cworth@cworth.org>\r
+To: Austin Clements <amdragon@mit.edu>,\r
+       Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+Subject: Re: [PATCH] Save and restore point explicitly in\r
+       `notmuch-wash-toggle-invisible-action'.\r
+In-Reply-To: <BANLkTi=_PszwPDRbRxVpVhkT=YRAi5dGDQ@mail.gmail.com>\r
+References: <1306090675-26982-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1306164587-20326-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <87oc2rlujb.fsf@yoom.home.cworth.org> <8762ozrfrr.fsf@gmail.com>\r
+       <87oc2rvjvj.fsf@yoom.home.cworth.org> <871uznrbh5.fsf@gmail.com>\r
+       <BANLkTi=_PszwPDRbRxVpVhkT=YRAi5dGDQ@mail.gmail.com>\r
+User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1\r
+       (i486-pc-linux-gnu)\r
+Date: Tue, 24 May 2011 16:20:34 -0700\r
+Message-ID: <87d3j7bs8t.fsf@yoom.home.cworth.org>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="==-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 24 May 2011 23:20:42 -0000\r
+\r
+--==-=-=\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+\r
+--=-=-=\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Tue, 24 May 2011 18:43:41 -0400, Austin Clements <amdragon@mit.edu> wrot=\r
+e:\r
+> Saving point this way is a bit dangerous, though.  For example, if\r
+> you're near the end of the buffer and shorten the label, attempting to\r
+> restore the point could result in an error (or, a more benign example:\r
+> the cursor could wind up outside the label so pressing RET repeatedly\r
+> won't toggle it).\r
+>=20\r
+> Unfortunately, I don't know of a clean solution to this, but I think I\r
+> would rather the cursor move, but stay within the label (probably\r
+> moving to the beginning), than have problems like the above.\r
+\r
+Here's my fix. Let me know what you think.\r
+\r
+=2DCarl\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/x-diff\r
+Content-Disposition: inline;\r
+ filename=0001-Carefully-preverse-point-when-changing-button-text-i.patch\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+From=20a32e02bf0d2b57d51695f7d4ea6cdda9acb21322 Mon Sep 17 00:00:00 2001\r
+From: Carl Worth <cworth@cworth.org>\r
+Date: Mon, 23 May 2011 19:29:46 +0400\r
+Subject: [PATCH] Carefully preverse point when changing button text in\r
+ `notmuch-wash-toggle-invisible-action'.\r
+\r
+Previously, save-excursion was used to attempt to save the point, but\r
+this was unreliable since the region containing the marker saved by\r
+save-excursion was deleted. Instead, we save an integer position\r
+indicating the offset of point within the old button. Then, we restore\r
+point to the same offset within the new button, (but cap the offset to\r
+avoid leaving the button entirely).\r
+=2D--\r
+ emacs/notmuch-wash.el |   13 +++++++------\r
+ 1 files changed, 7 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el\r
+index 8455eee..3dceb8b 100644\r
+=2D-- a/emacs/notmuch-wash.el\r
++++ b/emacs/notmuch-wash.el\r
+@@ -82,13 +82,14 @@ collapse the remaining lines into a button.")\r
+   (let* ((new-start (button-start cite-button))\r
+        (overlay (button-get cite-button 'overlay))\r
+        (button-label (notmuch-wash-button-label overlay))\r
++       (button-offset (- (point) new-start))\r
+        (inhibit-read-only t))\r
+=2D    (save-excursion\r
+=2D      (goto-char new-start)\r
+=2D      (insert button-label)\r
+=2D      (let ((old-end (button-end cite-button)))\r
+=2D    (move-overlay cite-button new-start (point))\r
+=2D    (delete-region (point) old-end))))\r
++    (goto-char new-start)\r
++    (insert button-label)\r
++    (let ((old-end (button-end cite-button)))\r
++      (move-overlay cite-button new-start (point))\r
++      (delete-region (point) old-end))\r
++    (goto-char (min (button-end cite-button) (+ new-start button-offset))))\r
+   (force-window-update)\r
+   (redisplay t))\r
+=20\r
+=2D-=20\r
+1.7.5.1\r
+\r
+\r
+--=-=-=--\r
+\r
+--==-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iEYEARECAAYFAk3cPUIACgkQ6JDdNq8qSWh5CQCfS5/Ou7cLRlPUPCR1cdsZyndT\r
+kaEAnRLbfPoD2mFfLD2Y+c7A/PqEERkY\r
+=IDmP\r
+-----END PGP SIGNATURE-----\r
+--==-=-=--\r