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 1AD57431FDE for ; Sun, 11 May 2014 01:35:07 -0700 (PDT) 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 sHsNimsaWPZQ for ; Sun, 11 May 2014 01:35:02 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A000E431FC4 for ; Sun, 11 May 2014 01:34:56 -0700 (PDT) Received: by mail-wi0-f179.google.com with SMTP id bs8so3127287wib.0 for ; Sun, 11 May 2014 01:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IpMfDVDE2qHBwlzwRRn1AMd+cpFwdKfkM+Gl0aVpQ00=; b=e6gusMWkHSxbyWhRwiGh7JBf5lGhvG/F2QwcEq1IFypc+WxLH8NLZpUQ7qQraw+z/b /MnqGWYqva1elTGSm7AzZLCLdeZMZZBQz25lgRcJxTh8HoOURt2mXO3BFqSjnuS0tm/x xIPe7EArOe3kgTWgH0jrCB3mH+b/P1hR9dhSZElFlZ5qG9GQNrOV9Nej2iB54Cb6gyK2 lVS2rIDht67IyDjN9hEFVKDATdmSFi0f1EH2GQmGkVYcbDzCtYR/OJaox2kJJ5g27wrq oZkwI760To0lR+X1OWIy6221bA7TwLb6xPWEFur1H0v46KxvWKurX5rOkVSVwNCHQR/k XrjA== X-Received: by 10.194.175.70 with SMTP id by6mr16128915wjc.3.1399797294441; Sun, 11 May 2014 01:34:54 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by mx.google.com with ESMTPSA id fi2sm9107958wib.2.2014.05.11.01.34.53 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 11 May 2014 01:34:53 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH 4/7] emacs: hello: add a threads-and-messages function Date: Sun, 11 May 2014 09:34:39 +0100 Message-Id: <1399797282-20389-5-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com> References: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com> 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, 11 May 2014 08:35:07 -0000 This is an example of a possible display function. It displays the count for a search as messages/threads. This will be slow on a large search but could be useful for a small search. It also extends and renames the existing (unused) notmuch-saved-search-count function to count threads if wanted. The rename is done because the function is not saved-search specific. --- emacs/notmuch-hello.el | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index e11006b..6b2dedc 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -90,8 +90,13 @@ (define-widget 'notmuch-saved-search-plist 'list (const :tag "Default" nil) (const :tag "Oldest-first" oldest-first) (const :tag "Newest-first" newest-first))) - (group :format "%v" :inline t (const :format "Display-function: " :display-function) (function :format "%v"))))) - + (group :format "%v" :inline t + (const :format "" :display-function) + (choice :tag " Display function" + (const :tag "Default (messages)" nil) + (function-item :tag "messages/threads" + notmuch-hello-display-count-threads-and-messages) + function))))) (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox") (:name "unread" :query "tag:unread")) @@ -435,9 +440,6 @@ (defun notmuch-hello-widget-search (widget &rest ignore) (widget-get widget :notmuch-search-oldest-first))) -(defun notmuch-saved-search-count (search) - (car (process-lines notmuch-command "count" search))) - (defun notmuch-hello-tags-per-line (widest) "Determine how many tags to show per line and how wide they should be. Returns a cons cell `(tags-per-line width)'." @@ -487,6 +489,24 @@ (defun notmuch-hello-filtered-query (query filter) (concat "(" query ") and (" filter ")")) (t query))) +(defun notmuch-hello-count (query &optional threads) + (let ((arg (if threads "--output=threads" "--output=messages"))) + (string-to-number + (car (process-lines notmuch-command "count" arg query))))) + +(defun notmuch-hello-display-count-threads-and-messages (&rest args) + "Display the saved search count as messages/threads. + +This will be slow for large queries." + (let* ((current (plist-get args :current)) + (query (plist-get current :query)) + (messages (notmuch-hello-count query nil)) + (threads (notmuch-hello-count query t)) + (display (concat (notmuch-hello-nice-number messages) + "/" + (notmuch-hello-nice-number threads)))) + (plist-put current :count display))) + (defun notmuch-hello-batch-message-count (elem-plist options) "Update the message count for a saved search. -- 1.7.10.4