[notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list.
authorKeith Packard <keithp@keithp.com>
Sun, 27 Dec 2009 00:34:18 +0000 (16:34 +1600)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:56 +0000 (09:35 -0800)
36/6c6159ad7db68062f1586ade5cd56b7d7b4174 [new file with mode: 0644]

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