unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: do not put quoted reply in primary selection
@ 2013-11-17 12:04 Mark Walters
  2013-11-17 19:37 ` Jameson Graef Rollins
  2013-11-20  0:59 ` David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Walters @ 2013-11-17 12:04 UTC (permalink / raw)
  To: notmuch

In current emacs (24.3) select-active-regions is set to t by
default. The reply insertion code sets the region to the quoted
message to make it easy to delete (kill-region or C-w). These two
things combine to put the quoted message in the primary selection.

This is not what the user wanted and is a privacy risk (accidental
pasting of the quoted message). We can avoid some of the problems
by let-binding select-active-regions to nil. This fixes if the
primary selection was previously in a non-emacs window but not if
it was in an emacs window. To avoid the problem in the latter case
we deactivate mark.

One key test (which fails under many simpler "fixes") is: open emacs
24.3 with notmuch, open 2 windows (viewing different notmuch buffers),
highlight some text in one, and then reply to a message in the
other. In many of my earlier attempts to fix this big this test fails.
---

This problem was first discussed in the thread starting with jrollins
bug report in id:87vc1y6fbr.fsf@servo.finestructure.net. I couldn't
persuade the fixes mentioned in id:87hadh934c.fsf@qmul.ac.uk to work
in all cases.

The most difficult case to fix was when emacs already had a
highlighted section. The simpler fixes mentioned did fix the case when
the primary selection was in some non-emacs window (eg an xterm).

Unfortunately there are lots of cases that need checking: differnent
versions of emacs (at least 23 and 24), the various settings of
select-active-regions (nil, t, 'only), does cutting the quoted message
work, and possibly the various setting affecting whether cut text goes
in the primary-selction or the clipboard.

I have tested on emacs 23.4 and 24.3 on debian stable (ish) with all
three possibilities for select-active-regions (note 'only was
introduced in emacs 24 so is not relevant for emacs 23)

Anyway, this is the best I can manage!

Finally, note that I normally use emacs23 and this bug is not present
there (unless the user has customised select-active-regions to t) so I
have not given this patch a lot of testing.


Best wishes

Mark

 emacs/notmuch-mua.el |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 53802d2..00cd980 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -346,10 +346,25 @@ the From: address first."
 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
 the From: address first.  If REPLY-ALL is non-nil, the message
 will be addressed to all recipients of the source message."
+
+;; In current emacs (24.3) select-active-regions is set to t by
+;; default. The reply insertion code sets the region to the quoted
+;; message to make it easy to delete (kill-region or C-w). These two
+;; things combine to put the quoted message in the primary selection.
+;;
+;; This is not what the user wanted and is a privacy risk (accidental
+;; pasting of the quoted message). We can avoid some of the problems
+;; by let-binding select-active-regions to nil. This fixes if the
+;; primary selection was previously in a non-emacs window but not if
+;; it was in an emacs window. To avoid the problem in the latter case
+;; we deactivate mark.
+
   (let ((sender
 	 (when prompt-for-sender
-	   (notmuch-mua-prompt-for-sender))))
-    (notmuch-mua-reply query-string sender reply-all)))
+	   (notmuch-mua-prompt-for-sender)))
+	(select-active-regions nil))
+    (notmuch-mua-reply query-string sender reply-all)
+    (deactivate-mark)))
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-20  0:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-17 12:04 [PATCH] emacs: do not put quoted reply in primary selection Mark Walters
2013-11-17 19:37 ` Jameson Graef Rollins
2013-11-17 19:42   ` Tomi Ollila
2013-11-17 20:41     ` Mark Walters
2013-11-20  0:59 ` David Bremner

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).