Re: [notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list.

2010-02-08 Thread Carl Worth
On Sat, 26 Dec 2009 16:34:18 -0800, Keith Packard  wrote:
> This makes it easier to see folders with messages.
> Eliding empty folders is togged with the 'e' binding.
> 
> Signed-off-by: Keith Packard 

Thanks for the patches, Keith!

These are all very useful, and I've pushed all three...

>  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(-)

...except that on this last one I only pushed changes to notmuch.el. ;-)

-Carl


pgpjZZUyMWBcB.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list.

2010-02-08 Thread Carl Worth
On Sat, 26 Dec 2009 16:34:18 -0800, Keith Packard  wrote:
> This makes it easier to see folders with messages.
> Eliding empty folders is togged with the 'e' binding.
> 
> Signed-off-by: Keith Packard 

Thanks for the patches, Keith!

These are all very useful, and I've pushed all three...

>  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(-)

...except that on this last one I only pushed changes to notmuch.el. ;-)

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list.

2009-12-26 Thread Keith Packard
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)))
(inhib

[notmuch] [PATCH 3/3] Allow folders with no messages to be elided from list.

2009-12-26 Thread Keith Packard
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-rea