unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Carl Worth <cworth@cworth.org>
To: Austin Clements <amdragon@mit.edu>,
	Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH] Save and restore point explicitly in `notmuch-wash-toggle-invisible-action'.
Date: Tue, 24 May 2011 16:20:34 -0700	[thread overview]
Message-ID: <87d3j7bs8t.fsf@yoom.home.cworth.org> (raw)
In-Reply-To: <BANLkTi=_PszwPDRbRxVpVhkT=YRAi5dGDQ@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 659 bytes --]

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.

-Carl


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Carefully-preverse-point-when-changing-button-text-i.patch --]
[-- Type: text/x-diff, Size: 1751 bytes --]

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


[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

  parent reply	other threads:[~2011-05-24 23:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22 18:57 [PATCH 1/3] Use different labels for wash buttons when text is visible or hidden Dmitry Kurochkin
2011-05-22 18:57 ` [PATCH 2/3] test: fix expected output for emacs tests after the wash button label changes Dmitry Kurochkin
2011-05-22 18:57 ` [PATCH 3/3] test: add test for hiding/showing signature in notmuch-show view Dmitry Kurochkin
2011-05-23 15:29 ` [PATCH] Save and restore point explicitly in `notmuch-wash-toggle-invisible-action' Dmitry Kurochkin
2011-05-24 20:20   ` Carl Worth
2011-05-24 20:43     ` Dmitry Kurochkin
2011-05-24 22:01       ` Carl Worth
2011-05-24 22:16         ` Dmitry Kurochkin
2011-05-24 22:22           ` Carl Worth
2011-05-24 22:43           ` Austin Clements
2011-05-24 22:57             ` Carl Worth
2011-05-24 23:00             ` Dmitry Kurochkin
2011-05-24 23:02               ` Dmitry Kurochkin
2011-05-24 23:20             ` Carl Worth [this message]
2011-05-24 23:27               ` Dmitry Kurochkin
2011-05-24 23:36                 ` Carl Worth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d3j7bs8t.fsf@yoom.home.cworth.org \
    --to=cworth@cworth.org \
    --cc=amdragon@mit.edu \
    --cc=dmitry.kurochkin@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).