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 D4F8E429E55 for ; Sun, 22 Jan 2012 00:56:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 G8MVN0CvHFxS for ; Sun, 22 Jan 2012 00:56:43 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 37F20429E54 for ; Sun, 22 Jan 2012 00:56:43 -0800 (PST) Received: by werb10 with SMTP id b10so1658214wer.26 for ; Sun, 22 Jan 2012 00:56:42 -0800 (PST) Received: by 10.216.136.23 with SMTP id v23mr1872636wei.48.1327222602028; Sun, 22 Jan 2012 00:56:42 -0800 (PST) Received: from localhost ([109.131.95.182]) by mx.google.com with ESMTPS id cb8sm2331723wib.0.2012.01.22.00.56.41 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 Jan 2012 00:56:41 -0800 (PST) From: Pieter Praet To: Mark Anderson , Aaron Ecay , David Edmondson , Jameson Graef Rollins Subject: [PATCH v4 2/3] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message if it exists Date: Sun, 22 Jan 2012 09:54:28 +0100 Message-Id: <1327222469-29487-2-git-send-email-pieter@praet.org> X-Mailer: git-send-email 1.7.8.1 In-Reply-To: <871uqsku4h.fsf@praet.org> References: <871uqsku4h.fsf@praet.org> Cc: Notmuch Mail 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: Sun, 22 Jan 2012 08:56:44 -0000 * emacs/notmuch-show.el (notmuch-show-found-target-p): new predicate function that uses notmuch(1) 'count' to see if a query turns up any results. * emacs/notmuch-show.el (notmuch-show-if-found): new function that only shows a message/thread if present in the database and otherwise returns an error. * emacs/notmuch-show.el (notmuch-show-buttonize-links): some deduplication, and use new function `notmuch-show-if-found' instead of `notmuch-show' to prevent showing a blank screen for Message-Id's which aren't present in the database. --- emacs/notmuch-show.el | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 57dd232..972ac79 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -908,14 +908,17 @@ a corresponding notmuch search." (save-excursion (goto-char start) (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t) - ;; remove the overlay created by goto-address-mode - (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t) - (make-text-button (match-beginning 0) (match-end 0) - 'action `(lambda (arg) - (notmuch-show ,(match-string-no-properties 0))) - 'follow-link t - 'help-echo "Mouse-1, RET: search for this message" - 'face goto-address-mail-face)))) + (let ((message-id (match-string-no-properties 0)) + (string-start (match-beginning 0)) + (string-end (match-end 0))) + ;; remove the overlay created by goto-address-mode + (remove-overlays string-start string-end 'goto-address t) + (make-text-button string-start string-end + 'action `(lambda (arg) + (notmuch-show-if-found ,message-id)) + 'follow-link t + 'help-echo "Mouse-1, RET: search for this message" + 'face goto-address-mail-face))))) ;;;###autoload (defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch) @@ -1005,6 +1008,18 @@ thread id. If a prefix is given, crypto processing is toggled." (notmuch-kill-this-buffer) (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto))) +(defun notmuch-show-found-target-p (target) + (let ((args `("count" ,target))) + (> (string-to-number + (with-output-to-string + (apply 'call-process notmuch-command nil standard-output nil args))) + 0))) + +(defun notmuch-show-if-found (target &rest args) + (if (notmuch-show-found-target-p target) + (notmuch-show target args) + (error "Can't find target: %s" target))) + (defvar notmuch-show-stash-map (let ((map (make-sparse-keymap))) (define-key map "c" 'notmuch-show-stash-cc) -- 1.7.8.1