unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 4/5] emacs: add notmuch hello refresh hook to display message count change
Date: Sun,  2 Sep 2012 17:48:36 +0300	[thread overview]
Message-ID: <68598461de8be62156ce21545baeb2ab325fa817.1346596156.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1346596156.git.jani@nikula.org>
In-Reply-To: <cover.1346596156.git.jani@nikula.org>

Add a notmuch hello refresh hook to display a message about change in
message count in the database since the notmuch-hello buffer was last
refreshed manually (no-display is nil).

Signed-off-by: Jani Nikula <jani@nikula.org>
---
 emacs/notmuch-hello.el |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index fa14443..f7a3c95 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -148,6 +148,7 @@ International Bureau of Weights and Measures."
 (defcustom notmuch-hello-refresh-hook nil
   "Functions called after updating a `notmuch-hello' buffer."
   :type 'hook
+  :options '(notmuch-hello-refresh-status-message)
   :group 'notmuch-hello
   :group 'notmuch-hooks)
 
@@ -749,6 +750,43 @@ following:
     (let ((fill-column (- (window-width) notmuch-hello-indent)))
       (center-region start (point)))))
 
+(defcustom notmuch-hello-refresh-status-query "*"
+  "Query to use for `notmuch-hello-refresh-status-message' hook."
+  :type '(choice (const :tag "All messages" "*")
+		 (string :tag "Custom query"
+			 :value "tag:inbox"))
+  :group 'notmuch-hello)
+
+(defvar notmuch-hello-refresh-count 0
+  "Number of matching messages when `notmuch-hello' was last run.
+
+Used internally by `notmuch-hello-refresh-status-message'.")
+
+(defun notmuch-hello-refresh-status-message (no-display)
+  "Hook to display a status message when refreshing notmuch-hello buffer.
+
+Display a status message about the difference in message count
+matching `notmuch-hello-refresh-status-query' since the last time
+notmuch-hello was refreshed. Only takes into account explicit
+refreshes (NO-DISPLAY is nil)."
+  (unless no-display
+    (let* ((new-count
+	    (string-to-number
+	     (car (process-lines notmuch-command "count"
+				 notmuch-hello-refresh-status-query))))
+	   (diff-count (- new-count notmuch-hello-refresh-count)))
+      (cond
+       ((= notmuch-hello-refresh-count 0)
+	(message "You have %s messages."
+		 (notmuch-hello-nice-number new-count)))
+       ((> diff-count 0)
+	(message "You have %s more messages since last refresh."
+		 (notmuch-hello-nice-number diff-count)))
+       ((< diff-count 0)
+	(message "You have %s fewer messages since last refresh."
+		 (notmuch-hello-nice-number (- diff-count)))))
+      (setq notmuch-hello-refresh-count new-count))))
+
 ;;;###autoload
 (defun notmuch-hello (&optional no-display)
   "Run notmuch and display saved searches, known tags, etc.
-- 
1.7.9.5

  parent reply	other threads:[~2012-09-02 14:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02 14:48 [PATCH v2 0/5] emacs: notmuch-hello status message refresh hook, etc Jani Nikula
2012-09-02 14:48 ` [PATCH v2 1/5] emacs: document the notmuch-hello no-display argument Jani Nikula
2012-09-02 14:48 ` [PATCH v2 2/5] emacs: add no-display arg to notmuch-hello-refresh-hook Jani Nikula
2012-09-07  7:56   ` Tomi Ollila
2012-09-07  8:03     ` Jani Nikula
2012-09-02 14:48 ` [PATCH v2 3/5] test: fix hook-counter to accept the new no-display param Jani Nikula
2012-09-03 12:15   ` Michal Nazarewicz
2012-09-02 14:48 ` Jani Nikula [this message]
2012-09-02 14:48 ` [PATCH v2 5/5] NEWS: notmuch-hello refresh hook changes Jani Nikula
2012-09-02 16:00 ` [PATCH v2 0/5] emacs: notmuch-hello status message refresh hook, etc Tomi Ollila
2012-09-04 17:11 ` Michal Sojka
2012-09-04 20:30   ` Jani Nikula
2012-09-05 21:08     ` Michal Sojka
2012-09-06 15:28       ` Tomi Ollila

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=68598461de8be62156ce21545baeb2ab325fa817.1346596156.git.jani@nikula.org \
    --to=jani@nikula.org \
    --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).