From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2] emacs: show: make buttons select window
Date: Mon, 7 Jan 2013 21:07:20 +0000 [thread overview]
Message-ID: <1357592840-31155-1-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <20130107202221.GL17581@mit.edu>
Emacs has two button type objects: widgets (as used for saved searches
in notmuch-hello) and buttons as used by parts/citations and id links
in notmuch-show. These two behave subtly differently when clicked with
the mouse: widgets select the window clicked before running the
action, buttons do not.
This patch makes all of these behave the same: clicking always selects
the clicked window. It does this by defining a notmuch-button-type
supertype that the other notmuch buttons can inherit from. This
supertype binds the mouse-action to select the window and then
activate the button.
---
This versions fixes most of the comments raised by Austin's review.
The one change I didn't make was changing :supertype to 'supertype. In
principle I agree with Austin but the : form is used for inheritance
for other notmuch buttons in wash and crypto.
Best wishes
Mark
emacs/notmuch-crypto.el | 5 ++++-
emacs/notmuch-lib.el | 15 +++++++++++++++
emacs/notmuch-show.el | 4 +++-
emacs/notmuch-wash.el | 3 ++-
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index 83e5d37..5233824 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -19,6 +19,8 @@
;;
;; Authors: Jameson Rollins <jrollins@finestructure.net>
+(require 'notmuch-lib)
+
(defcustom notmuch-crypto-process-mime nil
"Should cryptographic MIME parts be processed?
@@ -76,7 +78,8 @@ mode."
(define-button-type 'notmuch-crypto-status-button-type
'action (lambda (button) (message (button-get button 'help-echo)))
'follow-link t
- 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")
+ 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
+ :supertype 'notmuch-button-type)
(defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
(let* ((status (plist-get sigstatus :status))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0407f8a..6836192 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -97,6 +97,21 @@ For example, if you wanted to remove an \"inbox\" tag and add an
:group 'notmuch-search
:group 'notmuch-show)
+;; By default clicking on a button does not select the window
+;; containing the button (as opposed to clicking on a widget which
+;; does). This means that the button action is then executed in the
+;; current selected window which can cause problems if the button
+;; changes the buffer (e.g., id: links) or moves point.
+;;
+;; This provides a button type which overrides mouse-action so that
+;; the button's window is selected before the action is run. Other
+;; notmuch buttons can get the same behaviour by inheriting from this
+;; button type.
+(define-button-type 'notmuch-button-type
+ 'mouse-action (lambda (button)
+ (select-window (posn-window (event-start last-input-event)))
+ (button-activate button)))
+
(defun notmuch-version ()
"Return a string with the notmuch version number."
(let ((long-string
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5751d98..059194d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -469,7 +469,8 @@ message at DEPTH in the current thread."
'action 'notmuch-show-part-button-default
'keymap 'notmuch-show-part-button-map
'follow-link t
- 'face 'message-mml)
+ 'face 'message-mml
+ :supertype 'notmuch-button-type)
(defvar notmuch-show-part-button-map
(let ((map (make-sparse-keymap)))
@@ -1075,6 +1076,7 @@ buttons for a corresponding notmuch search."
;; Remove the overlay created by goto-address-mode
(remove-overlays (first link) (second link) 'goto-address t)
(make-text-button (first link) (second link)
+ :type 'notmuch-button-type
'action `(lambda (arg)
(notmuch-show ,(third link)))
'follow-link t
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index d6db4fa..826b6f4 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -115,7 +115,8 @@ lower).")
(define-button-type 'notmuch-wash-button-invisibility-toggle-type
'action 'notmuch-wash-toggle-invisible-action
'follow-link t
- 'face 'font-lock-comment-face)
+ 'face 'font-lock-comment-face
+ :supertype 'notmuch-button-type)
(define-button-type 'notmuch-wash-button-citation-toggle-type
'help-echo "mouse-1, RET: Show citation"
--
1.7.9.1
next prev parent reply other threads:[~2013-01-07 21:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 18:24 [PATCH] emacs: show: make buttons select window Mark Walters
2013-01-07 20:22 ` Austin Clements
2013-01-07 21:07 ` Mark Walters [this message]
2013-01-07 21:20 ` [PATCH v2] " Austin Clements
2013-02-19 1:12 ` David Bremner
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=1357592840-31155-1-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@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).