unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Pieter Praet <pieter@praet.org>
To: David Edmondson <dme@dme.org>,
	Jameson Graef Rollins <jrollins@finestructure.net>
Cc: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH v2] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message if it exists
Date: Mon, 16 Jan 2012 17:51:59 +0100	[thread overview]
Message-ID: <1326732719-23493-1-git-send-email-pieter@praet.org> (raw)
In-Reply-To: <87lip7a8yh.fsf@praet.org>

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

---

v2:  (corrections by David Edmondson [1])

 - `notmuch-show-found-target-p' : removed useless `substring'.
 - `notmuch-show-if-found' : remove redundant `format'.

... and added a missing closing paren due to badly splitting up the
original commit.

[1] id:"cun7h0r50v6.fsf@hotblack-desiato.hh.sledj.net"


 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 f101d76..7a79d06 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -803,14 +803,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)
@@ -903,6 +906,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

  reply	other threads:[~2012-01-16 16:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-23  4:59 [PATCH v2] emacs: call notmuch-show instead of notmuch-search in buttonised id: links Jameson Graef Rollins
2011-12-23  7:48 ` David Edmondson
2011-12-23 10:10   ` Xavier Maillard
2011-12-23 10:25     ` David Edmondson
2011-12-24 21:51 ` David Bremner
2012-01-12 17:20 ` Pieter Praet
2012-01-12 17:23   ` [PATCH 1/3] emacs: s/buttonise/buttonize/g Pieter Praet
2012-01-12 17:23     ` [PATCH 2/3] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message if it exists Pieter Praet
2012-01-16 11:43       ` David Edmondson
2012-01-16 16:49         ` Pieter Praet
2012-01-16 16:51           ` Pieter Praet [this message]
2012-01-16 17:06             ` [PATCH v2] " David Edmondson
2012-01-12 17:23     ` [PATCH 3/3] emacs: colorize buttonized 'id:' links depending on the target message's state Pieter Praet
2012-01-16 11:45       ` David Edmondson
2012-01-16 16:53         ` Pieter Praet
2012-01-16 16:54         ` Pieter Praet
2012-01-16 16:57           ` [PATCH] v2 " Pieter Praet
2012-01-16 17:07             ` David Edmondson
2012-01-16 21:43             ` Aaron Ecay
2012-01-18 10:08               ` Pieter Praet
2012-01-18 12:48                 ` [PATCH 3/3 v3] " Pieter Praet
2012-01-20 19:15                 ` [PATCH] v2 " Mark Anderson
2012-01-22  8:40                   ` Pieter Praet
2012-01-22  8:54                     ` [PATCH v4 1/3] emacs: s/buttonise/buttonize/g Pieter Praet
2012-01-22  8:54                     ` [PATCH v4 2/3] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message if it exists Pieter Praet
2012-01-22 11:10                       ` Mark Walters
2012-01-25  0:41                         ` Pieter Praet
2014-05-07 15:22                       ` David Edmondson
2017-03-05 11:52                         ` David Bremner
2012-01-22  8:54                     ` [PATCH v4 3/3] emacs: colorize buttonized 'id:' links depending on the target message's state Pieter Praet
2012-01-16 11:38     ` [PATCH 1/3] emacs: s/buttonise/buttonize/g David Edmondson
2012-01-25 11:16     ` David Bremner
2012-01-26 13:00       ` Pieter Praet
2012-01-26 14:34         ` Tomi Ollila
2017-03-05 11:51   ` [PATCH v2] emacs: call notmuch-show instead of notmuch-search in buttonised id: links 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=1326732719-23493-1-git-send-email-pieter@praet.org \
    --to=pieter@praet.org \
    --cc=dme@dme.org \
    --cc=jrollins@finestructure.net \
    --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).