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 7E447431FC0 for ; Sat, 26 Dec 2009 16:34:40 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 3WLuDcsdpD5V for ; Sat, 26 Dec 2009 16:34:39 -0800 (PST) Received: from keithp.com (home.keithp.com [63.227.221.253]) by olra.theworths.org (Postfix) with ESMTP id 3584F431FC3 for ; Sat, 26 Dec 2009 16:34:37 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id BE03E760142 for ; Sat, 26 Dec 2009 16:34:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from keithp.com ([127.0.0.1]) by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id du1rtUreSsds; Sat, 26 Dec 2009 16:34:33 -0800 (PST) Received: by keithp.com (Postfix, from userid 1033) id A2192B7C03A; Sat, 26 Dec 2009 16:34:32 -0800 (PST) Received: from koto.keithp.com (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id C8E58760142; Sat, 26 Dec 2009 16:34:30 -0800 (PST) Received: by koto.keithp.com (Postfix, from userid 1488) id F0DCE1381DF; Sat, 26 Dec 2009 16:34:20 -0800 (PST) From: Keith Packard To: notmuch@notmuchmail.org Date: Sat, 26 Dec 2009 16:34:18 -0800 Message-Id: <1261874058-13820-3-git-send-email-keithp@keithp.com> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <1261874058-13820-2-git-send-email-keithp@keithp.com> References: <1261874058-13820-1-git-send-email-keithp@keithp.com> <1261874058-13820-2-git-send-email-keithp@keithp.com> Subject: [notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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, 27 Dec 2009 00:34:40 -0000 This makes it easier to see folders with messages. Eliding empty folders is togged with the 'e' binding. Signed-off-by: Keith Packard --- lib/Makefile.local | 1 + lib/notmuch.h | 11 +++++++++++ lib/query.cc | 41 +++++++++++++++++++++++++++++++++++++++++ notmuch-new.c | 1 + notmuch.el | 29 ++++++++++++++++++++++++----- 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/lib/Makefile.local b/lib/Makefile.local index a7562c9..e42f533 100644 --- a/lib/Makefile.local +++ b/lib/Makefile.local @@ -2,6 +2,7 @@ dir=lib extra_cflags += -I$(dir) libnotmuch_c_srcs = \ + $(dir)/date.c \ $(dir)/libsha1.c \ $(dir)/message-file.c \ $(dir)/messages.c \ diff --git a/lib/notmuch.h b/lib/notmuch.h index 60834fb..f24da18 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -94,6 +94,7 @@ typedef enum _notmuch_status { NOTMUCH_STATUS_NULL_POINTER, NOTMUCH_STATUS_TAG_TOO_LONG, NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW, + NOTMUCH_STATUS_INVALID_DATE, NOTMUCH_STATUS_LAST_STATUS } notmuch_status_t; @@ -929,6 +930,16 @@ notmuch_tags_advance (notmuch_tags_t *tags); void notmuch_tags_destroy (notmuch_tags_t *tags); +/* Convert a string into a time range + * + * This parses the provided string, providing two time values + * representing the begining and end of the period. It + * returns NOTMUCH_STATUS_INVALID_DATE if the string could not be + * parsed, otherwise it return NOTMUCH_STATUS_SUCCESS + */ +notmuch_status_t +notmuch_date(const char *text, time_t *first, time_t *last); + NOTMUCH_END_DECLS #endif diff --git a/lib/query.cc b/lib/query.cc index 9106b92..f511146 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -47,6 +47,47 @@ struct _notmuch_threads { const char *thread_id; }; +static char * +notmuch_query_extract_word(notmuch_query_t *query, char *leader) +{ + char *token = strstr(query->query_string, leader); + int len = strlen(leader); + char *space; + char *word; + char *query_string; + + if (!token) + return NULL; + space = strchr(token, ' '); + if (!space) + space = token + strlen(token); + word = talloc_strndup(query, token + len, space - token - len); + query_string = talloc(query, strlen(query->query_string) - (space - token)); + strncpy(query_string, query->query_string, token - query->query_string); + strcat(query_string, space); + query->query_string = query_string; + return word; +} + +static notmuch_status_t +notmuch_query_edit(notmuch_query_t *query) +{ + char *before, *after; + time_t before_first, before_last, after_first, after_last; + + /* edit date range */ + before = notmuch_query_extract_word(query, "before:"); + if (notmuch_date(before, &before_first, &before_last) != NOTMUCH_STATUS_SUCCESS) + before = NULL; + after = notmuch_query_extract_word(query, "after:"); + if (notmuch_date(after, &after_first, &after_last) != NOTMUCH_STATUS_SUCCESS) + after = NULL; + + if (before && after) { + + } +} + notmuch_query_t * notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) diff --git a/notmuch-new.c b/notmuch-new.c index 9d20616..3974b28 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -264,6 +264,7 @@ add_files_recursive (notmuch_database_t *notmuch, case NOTMUCH_STATUS_TAG_TOO_LONG: case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: case NOTMUCH_STATUS_LAST_STATUS: + case NOTMUCH_STATUS_INVALID_DATE: INTERNAL_ERROR ("add_message returned unexpected value: %d", status); goto DONE; } diff --git a/notmuch.el b/notmuch.el index c02adc6..73917e7 100644 --- a/notmuch.el +++ b/notmuch.el @@ -1379,6 +1379,7 @@ current search results AND that are tagged with the given tag." (define-key map "x" 'kill-this-buffer) (define-key map "q" 'kill-this-buffer) (define-key map "m" 'message-mail) + (define-key map "e" 'notmuch-folder-show-empty-toggle) (define-key map ">" 'notmuch-folder-last) (define-key map "<" 'notmuch-folder-first) (define-key map "=" 'notmuch-folder) @@ -1455,14 +1456,32 @@ Currently available key bindings: (goto-char (point-max)) (forward-line -1)) +(defun notmuch-folder-count (search) + (car (process-lines notmuch-command "count" search))) + +(setq notmuch-folder-show-empty t) + +(defun notmuch-folder-show-empty-toggle () + "Toggle the listing of empty folders" + (interactive) + (setq notmuch-folder-show-empty (not notmuch-folder-show-empty)) + (notmuch-folder)) + (defun notmuch-folder-add (folders) (if folders - (let ((name (car (car folders))) + (let* ((name (car (car folders))) (inhibit-read-only t) - (search (cdr (car folders)))) - (insert name) - (indent-to 16 1) - (call-process notmuch-command nil t nil "count" search) + (search (cdr (car folders))) + (count (notmuch-folder-count search))) + (if (or notmuch-folder-show-empty + (not (equal count "0"))) + (progn + (insert name) + (indent-to 16 1) + (insert count) + (insert "\n") + ) + ) (notmuch-folder-add (cdr folders))))) (defun notmuch-folder-find-name () -- 1.6.5.4