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 EBB15431FAF for ; Mon, 7 Jan 2013 13:07:53 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 ZPKN8Vq8ZXE3 for ; Mon, 7 Jan 2013 13:07:53 -0800 (PST) Received: from mail-we0-f169.google.com (mail-we0-f169.google.com [74.125.82.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 16C8B431FAE for ; Mon, 7 Jan 2013 13:07:52 -0800 (PST) Received: by mail-we0-f169.google.com with SMTP id t49so10749696wey.0 for ; Mon, 07 Jan 2013 13:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=MU+UfucF2Eb5RQAEcssOyEUqlKpovFtQgmZgC1Jin0s=; b=BfGBZrIy15xiruJ/fEClF06hQp7trCQhtwxzqfQZBDWueFKj6Sb+pCUmvjLKVRajqY 2LHHhBG0K/NTcK1Y0uFEU2VmUXgJTZ1WOnjbF5VjixSJPLqRDXidywrlFb8F2YRDecYK tmRTr6x7OMYjStRiLdNsvdxZORaC9sKjkl+I8DDE/FY8Fcb/ewHedHfFhg+SMFWmZaxv EAViikgZ0lDx1Ud9sua5tVDCU449cnjZjxS9ImV5mdxNkL+TcaF++x+3HkYL6+G8a75d XK6l19GYSxXp30KxQ0JFurowCQrJfGNJBLczQwMO3PvcwBr9wAhjbC2KdzVj+FNWkTtx Ld0A== X-Received: by 10.194.77.13 with SMTP id o13mr98163019wjw.58.1357592871846; Mon, 07 Jan 2013 13:07:51 -0800 (PST) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPS id dm3sm13815777wib.9.2013.01.07.13.07.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 07 Jan 2013 13:07:50 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: show: make buttons select window Date: Mon, 7 Jan 2013 21:07:20 +0000 Message-Id: <1357592840-31155-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <20130107202221.GL17581@mit.edu> References: <20130107202221.GL17581@mit.edu> 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: Mon, 07 Jan 2013 21:07:54 -0000 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 +(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