[PATCH v4 2/3] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message...
authorPieter Praet <pieter@praet.org>
Sun, 22 Jan 2012 08:54:28 +0000 (09:54 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:55 +0000 (09:42 -0800)
82/62fbc9ce23b03ff7d7ea89acf61d295b218033 [new file with mode: 0644]

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