[PATCH v2] emacs: Leave blank subjects alone by default.

2012-02-06 Thread David Edmondson
Add `notmuch-blank-subject' to control how empty or whitespace only
subjects are treated. The default behaviour is to leave them
alone. The user can choose a string to use as a replacement.

Modify code that cannot handle blank subjects to use a fixed string.
---

Fix the non-string subject case (again, sigh).

 emacs/notmuch-lib.el   |   21 ++---
 emacs/notmuch-print.el |4 ++--
 emacs/notmuch-show.el  |2 +-
 emacs/notmuch.el   |4 ++--
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index d315f76..95e3c29 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -67,6 +67,13 @@
   :type 'boolean
   :group 'notmuch-search)

+(defcustom notmuch-blank-subject nil
+  "How should subjects that are empty or whitespace only be
+treated?"
+  :type '(choice (const :tag "Leave them alone" nil)
+(string :tag "Replacement string" "[No Subject]"))
+  :group 'notmuch)
+
 ;;

 (defvar notmuch-search-history nil
@@ -133,13 +140,21 @@ the user hasn't set this variable with the old or new 
value."
   (interactive)
   (kill-buffer (current-buffer)))

-(defun notmuch-prettify-subject (subject)
+(defun notmuch-pretty-non-empty-subject (subject)
+  (let ((subject (notmuch-pretty-subject subject)))
+(if (and subject
+(string-match "^[ \t]*$" subject))
+   "no subject"
+  subject)))
+
+(defun notmuch-pretty-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
   (save-match-data
-(if (and subject
+(if (and (stringp notmuch-blank-subject)
+subject
 (string-match "^[ \t]*$" subject))
-   "[No Subject]"
+   notmuch-blank-subject
   subject)))

 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6653d97..dda082a 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -60,7 +60,7 @@ Optional OUTPUT allows passing a list of flags to muttprint."

 (defun notmuch-print-ps-print (msg)
   "Print a message buffer using the ps-print package."
-  (let ((subject (notmuch-prettify-subject
+  (let ((subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer)))
@@ -68,7 +68,7 @@ Optional OUTPUT allows passing a list of flags to muttprint."
 (defun notmuch-print-ps-print/evince (msg)
   "Preview a message buffer using ps-print and evince."
   (let ((ps-file (make-temp-file "notmuch"))
-   (subject (notmuch-prettify-subject
+   (subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer ps-file)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4a23cc2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1261,7 +1261,7 @@ Some useful entries are:
   (notmuch-show-get-prop :depth))

 (defun notmuch-show-get-pretty-subject ()
-  (notmuch-prettify-subject (notmuch-show-get-subject)))
+  (notmuch-pretty-subject (notmuch-show-get-subject)))

 (defun notmuch-show-set-tags (tags)
   "Set the tags of the current message."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index cd04ffd..aab6946 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -467,7 +467,7 @@ Complete list of currently available key bindings:
   "Display the currently selected thread."
   (interactive "P")
   (let ((thread-id (notmuch-search-find-thread-id))
-   (subject (notmuch-prettify-subject (notmuch-search-find-subject
+   (subject (notmuch-pretty-non-empty-subject 
(notmuch-search-find-subject
 (if (> (length thread-id) 0)
(notmuch-show thread-id
  (current-buffer)
@@ -850,7 +850,7 @@ non-authors is found, assume that all of the authors match."
  (insert (concat "Error: Unexpected output from 
notmuch search:\n" (substring string line (match-beginning 1)) "\n")))
  (let ((beg (point)))
(notmuch-search-show-result date count authors
-   (notmuch-prettify-subject 
subject) tags)
+   (notmuch-pretty-subject 
subject) tags)
(notmuch-search-color-line beg (point) tag-list)
(put-text-property beg (point) 
'notmuch-search-thread-id thread-id)
(put-text-property beg (point) 'notmuch-search-authors 
authors)
-- 
1.7.8.3



[PATCH v2 3/3] cli: reach previously unreachable cleanup code in "notmuch show"

2012-02-06 Thread Jani Nikula
The last lines of notmuch_show_command() function were
unreachable. Fix it by using a variable for return value.

Signed-off-by: Jani Nikula 
---
 notmuch-show.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index b358278..c8fbd79 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1064,7 +1064,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 notmuch_database_t *notmuch;
 notmuch_query_t *query;
 char *query_string;
-int opt_index;
+int opt_index, ret;
 const notmuch_show_format_t *format = _text;
 notmuch_show_params_t params = { .part = -1 };
 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
@@ -1169,9 +1169,9 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 }

 if (params.part >= 0)
-   return do_show_single (ctx, query, format, );
+   ret = do_show_single (ctx, query, format, );
 else
-   return do_show (ctx, query, format, );
+   ret = do_show (ctx, query, format, );

 notmuch_query_destroy (query);
 notmuch_database_close (notmuch);
@@ -1179,5 +1179,5 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 if (params.cryptoctx)
g_object_unref(params.cryptoctx);

-return 0;
+return ret;
 }
-- 
1.7.5.4



[PATCH v2 2/3] cli: convert "notmuch show" to use the new argument parser

2012-02-06 Thread Jani Nikula
Use the new notmuch argument parser to handle arguments in "notmuch
show". There are three minor functional changes:

1) Also set params.raw = TRUE when defaulting to raw format when part
   is requested but format is not specified. This was a bug, and
   --part=0 without --format=raw did not work previously.

2) Set params.decrypt = FALSE if crypto context creation fails.

3) Only use the parameters for the last --format if specified multiple
   times. Previously this could have resulted in a non-working mixture
   of parameters.

Signed-off-by: Jani Nikula 
---
 notmuch-show.c |  149 
 1 files changed, 75 insertions(+), 74 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index e04b3cc..b358278 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1049,6 +1049,14 @@ do_show (void *ctx,
 return 0;
 }

+enum {
+NOTMUCH_FORMAT_NOT_SPECIFIED,
+NOTMUCH_FORMAT_JSON,
+NOTMUCH_FORMAT_TEXT,
+NOTMUCH_FORMAT_MBOX,
+NOTMUCH_FORMAT_RAW
+};
+
 int
 notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
 {
@@ -1056,92 +1064,94 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 notmuch_database_t *notmuch;
 notmuch_query_t *query;
 char *query_string;
-char *opt;
+int opt_index;
 const notmuch_show_format_t *format = _text;
-notmuch_show_params_t params;
-int mbox = 0;
-int format_specified = 0;
-int i;
+notmuch_show_params_t params = { .part = -1 };
+int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
+notmuch_bool_t verify = FALSE;
+
+notmuch_opt_desc_t options[] = {
+   { NOTMUCH_OPT_KEYWORD, _sel, "format", 'f',
+ (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
+ { "text", NOTMUCH_FORMAT_TEXT },
+ { "mbox", NOTMUCH_FORMAT_MBOX },
+ { "raw", NOTMUCH_FORMAT_RAW },
+ { 0, 0 } } },
+   { NOTMUCH_OPT_INT, , "part", 'p', 0 },
+   { NOTMUCH_OPT_BOOLEAN, _thread, "entire-thread", 't', 0 },
+   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, , "verify", 'v', 0 },
+   { 0, 0, 0, 0, 0 }
+};

-params.entire_thread = FALSE;
-params.raw = FALSE;
-params.part = -1;
-params.cryptoctx = NULL;
-params.decrypt = FALSE;
+opt_index = parse_arguments (argc, argv, options, 1);
+if (opt_index < 0) {
+   /* diagnostics already printed */
+   return 1;
+}

-argc--; argv++; /* skip subcommand argument */
+if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
+   /* if part was requested and format was not specified, use format=raw */
+   if (params.part >= 0)
+   format_sel = NOTMUCH_FORMAT_RAW;
+   else
+   format_sel = NOTMUCH_FORMAT_TEXT;
+}

-for (i = 0; i < argc && argv[i][0] == '-'; i++) {
-   if (strcmp (argv[i], "--") == 0) {
-   i++;
-   break;
+switch (format_sel) {
+case NOTMUCH_FORMAT_JSON:
+   format = _json;
+   params.entire_thread = TRUE;
+   break;
+case NOTMUCH_FORMAT_TEXT:
+   format = _text;
+   break;
+case NOTMUCH_FORMAT_MBOX:
+   if (params.part > 0) {
+   fprintf (stderr, "Error: specifying parts is incompatible with mbox 
output format.\n");
+   return 1;
}
-   if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
-   opt = argv[i] + sizeof ("--format=") - 1;
-   if (strcmp (opt, "text") == 0) {
-   format = _text;
-   } else if (strcmp (opt, "json") == 0) {
-   format = _json;
-   params.entire_thread = TRUE;
-   } else if (strcmp (opt, "mbox") == 0) {
-   format = _mbox;
-   mbox = 1;
-   } else if (strcmp (opt, "raw") == 0) {
-   format = _raw;
-   params.raw = TRUE;
-   } else {
-   fprintf (stderr, "Invalid value for --format: %s\n", opt);
-   return 1;
-   }
-   format_specified = 1;
-   } else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {
-   params.part = atoi(argv[i] + sizeof ("--part=") - 1);
-   } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
-   params.entire_thread = TRUE;
-   } else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||
-  (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
-   if (params.cryptoctx == NULL) {
+   format = _mbox;
+   break;
+case NOTMUCH_FORMAT_RAW:
+   format = _raw;
+   /* If --format=raw specified without specifying part, we can only
+* output single message, so set part=0 */
+   if (params.part < 0)
+   params.part = 0;
+   params.raw = TRUE;
+   break;
+}
+
+if (params.decrypt || verify) {
 #ifdef GMIME_ATLEAST_26
-   /* TODO: 

[PATCH v2 1/3] cli: use notmuch_bool_t for boolean fields in notmuch_show_params_t

2012-02-06 Thread Jani Nikula
Use notmuch_bool_t instead of int for entire_thread, raw, and decrypt
boolean fields in notmuch_show_params_t. No functional changes.

Signed-off-by: Jani Nikula 
---
 notmuch-client.h |6 +++---
 notmuch-reply.c  |7 +++
 notmuch-show.c   |   14 +++---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..60828aa 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -98,15 +98,15 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;

 typedef struct notmuch_show_params {
-int entire_thread;
-int raw;
+notmuch_bool_t entire_thread;
+notmuch_bool_t raw;
 int part;
 #ifdef GMIME_ATLEAST_26
 GMimeCryptoContext* cryptoctx;
 #else
 GMimeCipherContext* cryptoctx;
 #endif
-int decrypt;
+notmuch_bool_t decrypt;
 } notmuch_show_params_t;

 /* There's no point in continuing when we've detected that we've done
diff --git a/notmuch-reply.c b/notmuch-reply.c
index f55b1d2..6b244e6 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -661,7 +661,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_show_params_t params = { .part = -1 };
 int format = FORMAT_DEFAULT;
 int reply_all = TRUE;
-notmuch_bool_t decrypt = FALSE;

 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, , "format", 'f',
@@ -672,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
  (notmuch_keyword_t []){ { "all", TRUE },
  { "sender", FALSE },
  { 0, 0 } } },
-   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
{ 0, 0, 0, 0, 0 }
 };

@@ -687,7 +686,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 else
reply_format_func = notmuch_reply_format_default;

-if (decrypt) {
+if (params.decrypt) {
 #ifdef GMIME_ATLEAST_26
/* TODO: GMimePasswordRequestFunc */
params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");
@@ -697,8 +696,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 #endif
if (params.cryptoctx) {
g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) 
params.cryptoctx, FALSE);
-   params.decrypt = TRUE;
} else {
+   params.decrypt = FALSE;
fprintf (stderr, "Failed to construct gpg context.\n");
}
 #ifndef GMIME_ATLEAST_26
diff --git a/notmuch-show.c b/notmuch-show.c
index dec799c..e04b3cc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1063,11 +1063,11 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 int format_specified = 0;
 int i;

-params.entire_thread = 0;
-params.raw = 0;
+params.entire_thread = FALSE;
+params.raw = FALSE;
 params.part = -1;
 params.cryptoctx = NULL;
-params.decrypt = 0;
+params.decrypt = FALSE;

 argc--; argv++; /* skip subcommand argument */

@@ -1082,13 +1082,13 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
format = _text;
} else if (strcmp (opt, "json") == 0) {
format = _json;
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
} else if (strcmp (opt, "mbox") == 0) {
format = _mbox;
mbox = 1;
} else if (strcmp (opt, "raw") == 0) {
format = _raw;
-   params.raw = 1;
+   params.raw = TRUE;
} else {
fprintf (stderr, "Invalid value for --format: %s\n", opt);
return 1;
@@ -1097,7 +1097,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
} else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {
params.part = atoi(argv[i] + sizeof ("--part=") - 1);
} else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
} else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||
   (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
if (params.cryptoctx == NULL) {
@@ -1117,7 +1117,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 #endif
}
if (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)
-   params.decrypt = 1;
+   params.decrypt = TRUE;
} else {
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
-- 
1.7.5.4



[PATCH 0/3] notmuch show argument parsing

2012-02-06 Thread Jani Nikula
Hi all, 

v2 addressing Austin's comments in id:"20120206041205.GP10898 at mit.edu".
Separate the bool cleanup into a new patch, cleaning up notmuch reply
while at it. No functional changes since v1.

For reviewing convenience, the diff between v1 and v2 is at the end of
this cover letter.

BR,
Jani.

Jani Nikula (3):
  cli: use notmuch_bool_t for boolean fields in notmuch_show_params_t
  cli: convert "notmuch show" to use the new argument parser
  cli: reach previously unreachable cleanup code in "notmuch show"

 notmuch-client.h |6 +-
 notmuch-reply.c  |7 +--
 notmuch-show.c   |  155 +++---
 3 files changed, 84 insertions(+), 84 deletions(-)

-- 
1.7.5.4

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..60828aa 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -98,15 +98,15 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;

 typedef struct notmuch_show_params {
-int entire_thread;
-int raw;
+notmuch_bool_t entire_thread;
+notmuch_bool_t raw;
 int part;
 #ifdef GMIME_ATLEAST_26
 GMimeCryptoContext* cryptoctx;
 #else
 GMimeCipherContext* cryptoctx;
 #endif
-int decrypt;
+notmuch_bool_t decrypt;
 } notmuch_show_params_t;

 /* There's no point in continuing when we've detected that we've done
diff --git a/notmuch-reply.c b/notmuch-reply.c
index f55b1d2..6b244e6 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -661,7 +661,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_show_params_t params = { .part = -1 };
 int format = FORMAT_DEFAULT;
 int reply_all = TRUE;
-notmuch_bool_t decrypt = FALSE;

 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, , "format", 'f',
@@ -672,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
  (notmuch_keyword_t []){ { "all", TRUE },
  { "sender", FALSE },
  { 0, 0 } } },
-   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
{ 0, 0, 0, 0, 0 }
 };

@@ -687,7 +686,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 else
reply_format_func = notmuch_reply_format_default;

-if (decrypt) {
+if (params.decrypt) {
 #ifdef GMIME_ATLEAST_26
/* TODO: GMimePasswordRequestFunc */
params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");
@@ -697,8 +696,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 #endif
if (params.cryptoctx) {
g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) 
params.cryptoctx, FALSE);
-   params.decrypt = TRUE;
} else {
+   params.decrypt = FALSE;
fprintf (stderr, "Failed to construct gpg context.\n");
}
 #ifndef GMIME_ATLEAST_26
diff --git a/notmuch-show.c b/notmuch-show.c
index b18e279..c8fbd79 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1068,9 +1068,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 const notmuch_show_format_t *format = _text;
 notmuch_show_params_t params = { .part = -1 };
 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
-notmuch_bool_t decrypt = FALSE;
 notmuch_bool_t verify = FALSE;
-notmuch_bool_t entire_thread = FALSE;

 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, _sel, "format", 'f',
@@ -1080,8 +1078,8 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
  { "raw", NOTMUCH_FORMAT_RAW },
  { 0, 0 } } },
{ NOTMUCH_OPT_INT, , "part", 'p', 0 },
-   { NOTMUCH_OPT_BOOLEAN, _thread, "entire-thread", 't', 0 },
-   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, _thread, "entire-thread", 't', 0 },
+   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
{ NOTMUCH_OPT_BOOLEAN, , "verify", 'v', 0 },
{ 0, 0, 0, 0, 0 }
 };
@@ -1092,8 +1090,6 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
return 1;
 }

-params.entire_thread = entire_thread;
-
 if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
/* if part was requested and format was not specified, use format=raw */
if (params.part >= 0)
@@ -1105,7 +1101,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 switch (format_sel) {
 case NOTMUCH_FORMAT_JSON:
format = _json;
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
break;
 case NOTMUCH_FORMAT_TEXT:
format = _text;
@@ -1123,11 +1119,11 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 * output single message, so set part=0 */
if (params.part < 0)
params.part = 0;
-   params.raw = 1;
+   params.raw = TRUE;
break;
 }

-if 

[PATCH] emacs: Leave blank subjects alone by default.

2012-02-06 Thread David Edmondson
Add `notmuch-blank-subject' to control how empty or whitespace only
subjects are treated. The default behaviour is to leave them
alone. The user can choose a string to use as a replacement.

Modify code that cannot handle blank subjects to use a fixed string.
---
 emacs/notmuch-lib.el   |   20 +---
 emacs/notmuch-print.el |4 ++--
 emacs/notmuch-show.el  |2 +-
 emacs/notmuch.el   |4 ++--
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index d315f76..2edc868 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -67,6 +67,13 @@
   :type 'boolean
   :group 'notmuch-search)

+(defcustom notmuch-blank-subject nil
+  "How should subjects that are empty or whitespace only be
+treated?"
+  :type '(choice (const :tag "Leave them alone" nil)
+(string :tag "Replacement string" "[No Subject]"))
+  :group 'notmuch)
+
 ;;

 (defvar notmuch-search-history nil
@@ -133,13 +140,20 @@ the user hasn't set this variable with the old or new 
value."
   (interactive)
   (kill-buffer (current-buffer)))

-(defun notmuch-prettify-subject (subject)
+(defun notmuch-pretty-non-empty-subject (subject)
+  (let ((subject (notmuch-pretty-subject subject)))
+(if (string-match "^[ \t]*$" subject)
+   "no subject"
+  subject)))
+
+(defun notmuch-pretty-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
   (save-match-data
-(if (and subject
+(if (and (stringp notmuch-blank-subject)
+subject
 (string-match "^[ \t]*$" subject))
-   "[No Subject]"
+   notmuch-blank-subject
   subject)))

 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6653d97..dda082a 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -60,7 +60,7 @@ Optional OUTPUT allows passing a list of flags to muttprint."

 (defun notmuch-print-ps-print (msg)
   "Print a message buffer using the ps-print package."
-  (let ((subject (notmuch-prettify-subject
+  (let ((subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer)))
@@ -68,7 +68,7 @@ Optional OUTPUT allows passing a list of flags to muttprint."
 (defun notmuch-print-ps-print/evince (msg)
   "Preview a message buffer using ps-print and evince."
   (let ((ps-file (make-temp-file "notmuch"))
-   (subject (notmuch-prettify-subject
+   (subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer ps-file)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4a23cc2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1261,7 +1261,7 @@ Some useful entries are:
   (notmuch-show-get-prop :depth))

 (defun notmuch-show-get-pretty-subject ()
-  (notmuch-prettify-subject (notmuch-show-get-subject)))
+  (notmuch-pretty-subject (notmuch-show-get-subject)))

 (defun notmuch-show-set-tags (tags)
   "Set the tags of the current message."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index cd04ffd..aab6946 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -467,7 +467,7 @@ Complete list of currently available key bindings:
   "Display the currently selected thread."
   (interactive "P")
   (let ((thread-id (notmuch-search-find-thread-id))
-   (subject (notmuch-prettify-subject (notmuch-search-find-subject
+   (subject (notmuch-pretty-non-empty-subject 
(notmuch-search-find-subject
 (if (> (length thread-id) 0)
(notmuch-show thread-id
  (current-buffer)
@@ -850,7 +850,7 @@ non-authors is found, assume that all of the authors match."
  (insert (concat "Error: Unexpected output from 
notmuch search:\n" (substring string line (match-beginning 1)) "\n")))
  (let ((beg (point)))
(notmuch-search-show-result date count authors
-   (notmuch-prettify-subject 
subject) tags)
+   (notmuch-pretty-subject 
subject) tags)
(notmuch-search-color-line beg (point) tag-list)
(put-text-property beg (point) 
'notmuch-search-thread-id thread-id)
(put-text-property beg (point) 'notmuch-search-authors 
authors)
-- 
1.7.8.3



[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread David Edmondson
On Mon, 06 Feb 2012 11:19:46 -0800, Jameson Graef Rollins  wrote:
> On Mon, 06 Feb 2012 08:56:34 +, David Edmondson  wrote:
> > With blank subjects the printing code generated an error (because
> > `rename-buffer' doesn't like an empty string as the first argument), so
> > _some_ change is required.
> 
> This sounds like something that could easily be fixed in the printing
> code, without changing the show and search behavior.

Yes.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/343aa34f/attachment-0001.pgp>


[PATCH] Free the results of scandir()

2012-02-06 Thread Ethan Glasser-Camp
From: Ethan Glasser-Camp 

scandir() returns "strings allocated via malloc(3)" which are then
"collected in array namelist which is allocated via
malloc(3)". Currently we just free the array namelist. Instead, free
all the entries of namelist, and then free namelist.

entry only points to elements of namelist, so we don't free it
separately.
---

This should fix a minor memory leak in notmuch-new. Please confirm I'm
reading the manpage correctly ;)

 notmuch-new.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..c536873 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch,
   DONE:
 if (next)
talloc_free (next);
-if (entry)
-   free (entry);
 if (dir)
closedir (dir);
-if (fs_entries)
+if (fs_entries){
+   for (i = 0; i < num_fs_entries; i++){
+   free (fs_entries[i]);
+   }
free (fs_entries);
+}
 if (db_subdirs)
notmuch_filenames_destroy (db_subdirs);
 if (db_files)
-- 
1.7.5.4



[PATCH v2 1/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
On Mon,  6 Feb 2012 16:08:21 +, David Edmondson  wrote:
> Except for where invisibility is involved, replace the use of overlays
> in `notmuch-show-mode' with text properties, which are more efficient
> and can be merged together more effectively.

Austin reviewed this (id:"20120124161511.GC16740 at mit.edu"), but
suggested that someone else should look it over. Any volunteers?
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/49a838ee/attachment.pgp>


[PATCH 0/3] notmuch show argument parsing

2012-02-06 Thread Austin Clements
Quoth Jani Nikula on Feb 06 at  9:57 pm:
> Hi all, 
> 
> v2 addressing Austin's comments in id:"20120206041205.GP10898 at mit.edu".
> Separate the bool cleanup into a new patch, cleaning up notmuch reply
> while at it. No functional changes since v1.

LGTM.

(Heads up: I never received patch 1/3, though I found it in the online
archive, so it may have been a local problem.)


[PATCH v2 2/2] test: Update test to match previous patch.

2012-02-06 Thread David Edmondson
Indentation now uses tabs where possible.
---
 ...hread-maildir-storage-with-fourfold-indentation |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
 
b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
index b0bf93e..1f7801e 100644
--- 
a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
+++ 
b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
@@ -69,7 +69,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
 notmuch mailing list
 notmuch at notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
-Lars Kellogg-Stedman  (2009-11-17) (inbox 
signed unread)
+   Lars Kellogg-Stedman  (2009-11-17) (inbox 
signed unread)
Subject: Re: [notmuch] Working with Maildir storage?
To: Mikhail Gusarov 
Cc: notmuch at notmuchmail.org
@@ -101,7 +101,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
notmuch mailing list
notmuch at notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch
-Mikhail Gusarov  (2009-11-17) (inbox 
unread)
+   Mikhail Gusarov  (2009-11-17) (inbox 
unread)
Subject: [notmuch] Working with Maildir storage?
To: notmuch at notmuchmail.org
Date: Wed, 18 Nov 2009 02:50:48 +0600
@@ -129,7 +129,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
Desc: not available
URL:


-Keith Packard  (2009-11-17) (inbox unread)
+   Keith Packard  (2009-11-17) (inbox unread)
Subject: [notmuch] Working with Maildir storage?
To: notmuch at notmuchmail.org
Date: Tue, 17 Nov 2009 13:24:13 -0800
@@ -151,7 +151,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
Thanks to everyone for trying out notmuch!

-keith
-Lars Kellogg-Stedman  (2009-11-18) 
(inbox signed unread)
+   Lars Kellogg-Stedman  (2009-11-18) 
(inbox signed unread)
Subject: Re: [notmuch] Working with Maildir storage?
To: Keith Packard 
Cc: notmuch at notmuchmail.org
-- 
1.7.8.3



[PATCH v2 1/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
Except for where invisibility is involved, replace the use of overlays
in `notmuch-show-mode' with text properties, which are more efficient
and can be merged together more effectively.
---
 emacs/notmuch-show.el |   66 +++-
 emacs/notmuch-wash.el |8 -
 2 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..13d2e81 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -264,10 +264,10 @@ operation on the contents of the current buffer."
   (t
'message-header-other

-(overlay-put (make-overlay (point) (re-search-forward ":"))
-'face 'message-header-name)
-(overlay-put (make-overlay (point) (re-search-forward ".*$"))
-'face face)))
+(put-text-property (point) (re-search-forward ":")
+  'face 'message-header-name)
+(put-text-property (point) (re-search-forward ".*$")
+  'face face)))

 (defun notmuch-show-colour-headers ()
   "Apply some colouring to the current headers."
@@ -284,12 +284,11 @@ operation on the contents of the current buffer."
   "Update the displayed tags of the current message."
   (save-excursion
 (goto-char (notmuch-show-message-top))
-(if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
-   (let ((inhibit-read-only t))
- (replace-match (concat "("
-(propertize (mapconcat 'identity tags " ")
-'face 'notmuch-tag-face)
-")"))
+(when (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
+  (let ((inhibit-read-only t))
+   (replace-match (propertize (mapconcat 'identity tags " ")
+  'face '(notmuch-tag-face 
notmuch-message-summary-face))
+  nil nil nil 1)

 (defun notmuch-show-clean-address (address)
   "Try to clean a single email ADDRESS for display.  Return
@@ -352,15 +351,26 @@ unchanged ADDRESS if parsing fails."
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
   (let ((start (point)))
-(insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width 
depth))
-   (notmuch-show-clean-address (plist-get headers :From))
-   " ("
-   date
-   ") ("
-   (propertize (mapconcat 'identity tags " ")
-   'face 'notmuch-tag-face)
-   ")\n")
-(overlay-put (make-overlay start (point)) 'face 
'notmuch-message-summary-face)))
+(insert
+ (propertize (concat (notmuch-show-clean-address (plist-get headers :From))
+" ("
+date
+") (")
+'face 'notmuch-message-summary-face)
+ (propertize (mapconcat 'identity tags " ")
+'face '(notmuch-tag-face notmuch-message-summary-face))
+ (propertize ")\n"
+'face 'notmuch-message-summary-face))
+
+;; Ensure that any insertions at the start of this line (usually
+;; just spaces for indentation purposes) inherit the face of the
+;; rest of the line...
+(put-text-property start (1+ start)
+  'front-sticky '(face))
+;; ...and that insertions at the end of this region do _not_
+;; inherit the face of the rest of this line.
+(put-text-property (1- (point)) (point)
+  'rear-nonsticky '(face

 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
@@ -796,8 +806,15 @@ current buffer, if possible."
 (defun notmuch-show-insert-bodypart (msg part depth)
   "Insert the body part PART at depth DEPTH in the current thread."
   (let ((content-type (downcase (plist-get part :content-type)))
-   (nth (plist-get part :id)))
-(notmuch-show-insert-bodypart-internal msg part content-type nth depth 
content-type))
+   (nth (plist-get part :id))
+   (start (point)))
+(notmuch-show-insert-bodypart-internal msg part content-type nth depth 
content-type)
+
+;; Ensure that face properties applied to text in the buffer by
+;; the part handler don't leak into the following text.
+(put-text-property start (point-max)
+  'rear-nonsticky '(face)))
+
   ;; Some of the body part handlers leave point somewhere up in the
   ;; part, so we make sure that we're down at the end.
   (goto-char (point-max))
@@ -888,11 +905,12 @@ current buffer, if possible."
 (setq body-end (point-marker))
 (setq content-end (point-marker))

-;; Indent according to the depth in the thread.
-(indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth))
-
 (setq message-end (point-max-marker))

+;; Indent according to the depth in the thread.
+(indent-rigidly message-start message-end
+

[PATCH v2 0/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
v2:
- simple rebase.

David Edmondson (2):
  emacs: Use text properties rather than overlays in
`notmuch-show-mode'.
  test: Update test to match previous patch.

 emacs/notmuch-show.el  |   66 ---
 emacs/notmuch-wash.el  |8 ++-
 ...hread-maildir-storage-with-fourfold-indentation |8 +-
 3 files changed, 52 insertions(+), 30 deletions(-)

-- 
1.7.8.3



[PATCH v3 3/3] emacs: Don't insert a part header if it's the first part and text/*.

2012-02-06 Thread David Edmondson
Previously this logic applied only to text/plain. Allow it for other
text/* parts as well.
---
 emacs/notmuch-show.el |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index ce79762..c60e613 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -412,7 +412,9 @@ CONTENT-TYPE parts."
 (defun notmuch-show-insert-part-header (nth content-type declared-type
 name comment
 button-parameters)
-  (unless (notmuch-show-hidden-part-header content-type)
+  (unless (or (notmuch-show-hidden-part-header content-type)
+ (and (= nth 1)
+  (string-match "text/*" content-type)))
 (apply #'insert-button
   (concat "[ "
   (if name (concat name ": ") "")
@@ -703,10 +705,7 @@ current buffer, if possible."

 (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth 
declared-type)
   (let ((start (point)))
-;; If this text/plain part is not the first part in the message,
-;; insert a header to make this clear.
-(if (> nth 1)
-   (notmuch-show-insert-part-header nth declared-type content-type 
(plist-get part :filename)))
+(notmuch-show-insert-part-header nth declared-type content-type (plist-get 
part :filename))
 (insert (notmuch-show-get-bodypart-content msg part nth))
 (save-excursion
   (save-restriction
-- 
1.7.8.3



[PATCH v3 2/3] emacs: Optionally hide some part headers.

2012-02-06 Thread David Edmondson
Add a regexp, `notmuch-show-part-headers-hidden' and if the
content-type of a part matches, don't show the part header.
---
 emacs/notmuch-show.el |   43 ---
 1 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 079d7cb..ce79762 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -125,6 +125,12 @@ indentation."
 (const :tag "View interactively"
notmuch-show-interactively-view-part)))

+(defcustom notmuch-show-part-headers-hidden nil
+  "Headers for parts whose content-type matches this regexp will
+not be shown."
+  :group 'notmuch
+  :type 'regexp)
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -397,24 +403,31 @@ message at DEPTH in the current thread."
   "Submap for button commands")
 (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)

+(defun notmuch-show-hidden-part-header (content-type)
+  "Return non-nil if a part header should be hidden for
+CONTENT-TYPE parts."
+  (and notmuch-show-part-headers-hidden
+   (string-match notmuch-show-part-headers-hidden content-type)))
+
 (defun notmuch-show-insert-part-header (nth content-type declared-type
 name comment
 button-parameters)
-  (apply #'insert-button
-(concat "[ "
-(if name (concat name ": ") "")
-declared-type
-(if (not (string-equal declared-type content-type))
-(concat " (as " content-type ")")
-  "")
-(or comment "")
-" ]")
-:type 'notmuch-show-part-button-type
-:notmuch-part nth
-:notmuch-filename name
-:notmuch-content-type content-type
-button-parameters)
-  (insert "\n"))
+  (unless (notmuch-show-hidden-part-header content-type)
+(apply #'insert-button
+  (concat "[ "
+  (if name (concat name ": ") "")
+  declared-type
+  (if (not (string-equal declared-type content-type))
+  (concat " (as " content-type ")")
+"")
+  (or comment "")
+  " ]")
+  :type 'notmuch-show-part-button-type
+  :notmuch-part nth
+  :notmuch-filename name
+  :notmuch-content-type content-type
+  button-parameters)
+(insert "\n")))

 ;; Functions handling particular MIME parts.

-- 
1.7.8.3



[PATCH v3 1/3] emacs: Don't return the button from `notmuch-show-insert-part-header'.

2012-02-06 Thread David Edmondson
Instead, allow the caller to specify some parameters for the
button. Rework `notmuch-show-insert-part-multipart/signed' and
`notmuch-show-insert-part-multipart/encrypted' accordingly.
---
 emacs/notmuch-show.el |   86 +---
 1 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..079d7cb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -397,25 +397,24 @@ message at DEPTH in the current thread."
   "Submap for button commands")
 (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)

-(defun notmuch-show-insert-part-header (nth content-type declared-type 
 name comment)
-  (let ((button))
-(setq button
- (insert-button
-  (concat "[ "
-  (if name (concat name ": ") "")
-  declared-type
-  (if (not (string-equal declared-type content-type))
-  (concat " (as " content-type ")")
-"")
-  (or comment "")
-  " ]")
-  :type 'notmuch-show-part-button-type
-  :notmuch-part nth
-  :notmuch-filename name
-  :notmuch-content-type content-type))
-(insert "\n")
-;; return button
-button))
+(defun notmuch-show-insert-part-header (nth content-type declared-type
+name comment
+button-parameters)
+  (apply #'insert-button
+(concat "[ "
+(if name (concat name ": ") "")
+declared-type
+(if (not (string-equal declared-type content-type))
+(concat " (as " content-type ")")
+  "")
+(or comment "")
+" ]")
+:type 'notmuch-show-part-button-type
+:notmuch-part nth
+:notmuch-filename name
+:notmuch-content-type content-type
+button-parameters)
+  (insert "\n"))

 ;; Functions handling particular MIME parts.

@@ -602,15 +601,18 @@ current buffer, if possible."
   t)

 (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth 
depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type 
content-type nil)))
-(button-put button 'face 'notmuch-crypto-part-header)
-;; add signature status button if sigstatus provided
-(if (plist-member part :sigstatus)
-   (let* ((from (notmuch-show-get-header :From msg))
-  (sigstatus (car (plist-get part :sigstatus
- (notmuch-crypto-insert-sigstatus-button sigstatus from))
-  ;; if we're not adding sigstatus, tell the user how they can get it
-  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic mime parts.")))
+  ;; Add signature status button if sigstatus provided.
+  (if (plist-member part :sigstatus)
+  (let ((from (notmuch-show-get-header :From msg))
+   (sigstatus (car (plist-get part :sigstatus
+   (notmuch-show-insert-part-header nth declared-type content-type nil nil 
+'face 'notmuch-crypto-part-header)
+   (notmuch-crypto-insert-sigstatus-button sigstatus from))
+
+;; If we're not adding sigstatus, tell the user how to enable it.
+(notmuch-show-insert-part-header nth declared-type content-type nil nil 
+'face 'notmuch-crypto-part-header
+'help-echo "Set 
notmuch-crypto-process-mime to process cryptographic mime parts."))

   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -624,19 +626,21 @@ current buffer, if possible."
   t)

 (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth 
depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type 
content-type nil)))
-(button-put button 'face 'notmuch-crypto-part-header)
-;; add encryption status button if encstatus specified
-(if (plist-member part :encstatus)
-   (let ((encstatus (car (plist-get part :encstatus
- (notmuch-crypto-insert-encstatus-button encstatus)
- ;; add signature status button if sigstatus specified
- (if (plist-member part :sigstatus)
- (let* ((from (notmuch-show-get-header :From msg))
-(sigstatus (car (plist-get part :sigstatus
-   (notmuch-crypto-insert-sigstatus-button sigstatus from
-  ;; if we're not adding encstatus, tell the user how they can get it
-  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic mime parts.")))
+  ;; Add encryption status button if encstatus provided.
+  (if (plist-member part :encstatus)
+  (let ((encstatus (car (plist-get part :encstatus
+   (notmuch-show-insert-part-header nth declared-type content-type nil nil 
+

[PATCH v2] emacs: Add more processing of displayed headers.

2012-02-06 Thread David Edmondson
Wrap headers to the width of the window and indent continuations.
---
 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..a589d37 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -68,9 +68,16 @@ any given message."
   :type 'boolean
   :group 'notmuch-show)

-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
+(defcustom notmuch-show-markup-headers-hook '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
   "A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.")
+`notmuch-message-headers'."
+  :type 'hook
+  :options '(notmuch-show-colour-headers
+notmuch-show-fill-headers
+notmuch-show-indent-continuations)
+  :group 'notmuch-show)

 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
   "Functions called after populating a `notmuch-show' buffer."
@@ -269,13 +276,35 @@ operation on the contents of the current buffer."
 (overlay-put (make-overlay (point) (re-search-forward ".*$"))
 'face face)))

-(defun notmuch-show-colour-headers ()
+(defun notmuch-show-colour-headers (depth)
   "Apply some colouring to the current headers."
   (goto-char (point-min))
   (while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
 (notmuch-show-fontify-header)
 (forward-line)))

+(defun notmuch-show-fill-headers (depth)
+  "Wrap the text of the current headers."
+
+  ;; '-5' to allow for the indentation code.
+  (let ((fill-column (- (window-width) depth 5)))
+(goto-char (point-min))
+(while (not (eobp))
+  (let ((start (point)))
+   (end-of-line)
+   ;; We're left at the start of the next line, so there's no need
+   ;; to move forward after filling.
+   (fill-region-as-paragraph start (point))
+
+(defun notmuch-show-indent-continuations (depth)
+  "Indent any continuation lines."
+  (goto-char (point-min))
+  (while (not (eobp))
+(if (not (looking-at "^[A-Za-z][-A-Za-z0-9]*:"))
+   ;; Four spaces tends to work well with 'To' and 'Cc' headers.
+   (insert ""))
+(forward-line)))
+
 (defun notmuch-show-spaces-n (n)
   "Return a string comprised of `n' spaces."
   (make-string n ? ))
@@ -366,7 +395,7 @@ message at DEPTH in the current thread."
   "Insert a single header."
   (insert header ": " header-value "\n"))

-(defun notmuch-show-insert-headers (headers)
+(defun notmuch-show-insert-headers (headers depth)
   "Insert the headers of the current message."
   (let ((start (point)))
 (mapc (lambda (header)
@@ -379,7 +408,7 @@ message at DEPTH in the current thread."
 (save-excursion
   (save-restriction
(narrow-to-region start (point-max))
-   (run-hooks 'notmuch-show-markup-headers-hook)
+   (run-hook-with-args 'notmuch-show-markup-headers-hook depth)

 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
@@ -671,7 +700,7 @@ current buffer, if possible."
 ;; Override `notmuch-message-headers' to force `From' to be
 ;; displayed.
 (let ((notmuch-message-headers '("From" "Subject" "To" "Cc" "Date")))
-  (notmuch-show-insert-headers (plist-get message :headers)))
+  (notmuch-show-insert-headers (plist-get message :headers) 0))

 ;; Blank line after headers to be compatible with the normal
 ;; message display.
@@ -864,7 +893,7 @@ current buffer, if possible."
 ;; Set `headers-start' to point after the 'Subject:' header to be
 ;; compatible with the existing implementation. This just sets it
 ;; to after the first header.
-(notmuch-show-insert-headers headers)
+(notmuch-show-insert-headers headers depth)
 (save-excursion
   (goto-char content-start)
   ;; If the subject of this message is the same as that of the
-- 
1.7.8.3



[PATCH v3 0/3] part header code tidying and options

2012-02-06 Thread David Edmondson
v3:
- simple rebase.

The previous version of this had 'LGTM' for each of the three
parts. jrollins asked some questions, all of which were answered.

David Edmondson (3):
  emacs: Don't return the button from
`notmuch-show-insert-part-header'.
  emacs: Optionally hide some part headers.
  emacs: Don't insert a part header if it's the first part and text/*.

 emacs/notmuch-show.el |   84 +
 1 files changed, 50 insertions(+), 34 deletions(-)

-- 
1.7.8.3



[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Antoine Beaupré
On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins  wrote:
> Sorry to be so late on this, but I'm not a big fan of this new feature.
> I would prefer to always see the subject (or any other field for that
> matter) as is.

I agree. as a native french speaker, for example, it's annoying having
to change those settings everywhere I got...

a.
-- 
To be naive and easily deceived is impermissible, today more than
ever, when the prevailing untruths may lead to a catastrophe because
they blind people to real dangers and real possibilities.
- Erich Fromm
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/9c13fe07/attachment.pgp>


Installation on Mac OS X Lion

2012-02-06 Thread Blake Sweeney

Quoting Saurabh Nanda (2012-02-05 03:27:38)
>Hi,
>
>I'm trying to install notmuchmail on my Mac box, but have (obviously) 
>run into dependancy issues (Xapian, GMime, Glib, talloc). Has anyone 
>managed to install notmuchmail on Mac OS X? How painful is it? Is it 
>possible to have a binary package for this?

I have notmuch installed on os x though I'm on 10.5. I used homebrew
(http://mxcl.github.com/homebrew/) to install it orginally. It took care of all
the dependencies. There may be macports of fink packages, but I haven't checked.
I later upgraded to 10.2 by installing notmuch manually. I had some troubles
with the python bindings, but I think that was just because my glib was too old.
Installing a glib a newer 2.4.x glib fixed it.


Blake



[PATCH v7 0/8] reworked crypto toggle, plus a few other toggles

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 09:21:14 +, David Edmondson  wrote:
> v7:
> - Simple rebase.

The whole patch series applied cleanly (git am) on top of current origin/master
+ Dmitry's patchset id:"1328426033-21480-2-git-send-email-dmitry.kurochkin at 
gmail.com"

> David Edmondson (8):
>   emacs: Rework crypto switch toggle.

I don't currently have any data (on this particular machine) to test 
crypto switch toggle. Rest of the patches (2-8) worked fine.

So, +1 for those. 

Tomi

>   emacs: Allow `notmuch-show-mode' to display only matching messages.
>   emacs: Allow the indentation of content to be toggled.
>   emacs: Add a binding (t) to toggle the truncation of long lines.
>   emacs: Optionally retain the state of the buffer during
> `notmuch-show-refresh-view'.
>   emacs: Check that the parent buffer is alive before using it.
>   emacs: Add `notmuch-show-only-matching-messages'.
>   emacs: A prefix argument to `notmuch-show' should invert the matching
> message behaviour.
> 
>  emacs/notmuch-show.el |  224 
> ++---
>  emacs/notmuch.el  |7 +-
>  2 files changed, 158 insertions(+), 73 deletions(-)


newbie questions

2012-02-06 Thread Jesse Rosenthal
On Mon, 06 Feb 2012 08:51:15 +0200, Tomi Ollila  wrote:
> On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp  wrote:
> > 
> > 1. How can I restrict searches (eg of my inbox) to the last few
> > messages (eg 50-100) or some date (eg last 2 weeks)?  I am using the
> > Emacs interface.
> 
> Currently, if you have GNU date you can run from command line:
> 
> date +%s.. --date '2 weeks ago'
> 
> Then paste the string 1327300096.. to the search field.

FWIW, I actually have a hacky date parser baked into my
remote-usage-and-other-stuff script (a more idiosyncratc python
version of the bash script on the wiki). I found that I needed
date-searching pretty frequently, since language and senders seem to be
repeated pretty often in my world. It just parses a "date:" term, passes
it to GNU date, and proceeds with a term in notmuch language. It also
does some day-rounding, since by "date:'2 days ago'..yesterday", I mean
"beginning of day before yesterday to end of yesterday," not "48 hours
ago until 24 hours ago."

I'm not swearing by its efficiency, or even its correctness, but it has
made my life easier. The basics are as follows:

DATE_PATTERN = re.compile(r'^date:([^.]+)(\.\.)?([^.]+)?')

def replace_date_args(st):
out = subprocess.check_output([GNU_DATE, "+%s", "-d", st])
return out.strip()

def round_day_down(timestamp):
tup = datetime.fromtimestamp(int(timestamp)).date().timetuple()
return time.mktime(tup)

def round_day_up(timestamp):
date = datetime.fromtimestamp(int(timestamp)).date()
date += timedelta(days=1)
tup = date.timetuple()
return time.mktime(tup)

def parse_date_args(st):
re_match = DATE_PATTERN.match(st)
if re_match:
grps = re_match.groups()
start_term = grps[0]
if not (grps[1] or grps[2]):
stop_term = start_term
elif not grps[2]:
stop_term = "now"
else:
stop_term = grps[2]

try:
start = round_day_down(replace_date_args(start_term))
stop = round_day_up(replace_date_args(stop_term))
return "%d..%d" % (start, stop)
except OSError:
return st
else:
return st

And then in the main routine, I have a parse-and-replace step:

args = sys.argv[1:]
try:
if args[-1] == ")'":
args = args[:-2] + shlex.split(sys.argv[-2]) + [")'"]
else:
args = args[:-1] + shlex.split(sys.argv[-1])
except IndexError, ValueError:
pass

args = [parse_date_args(a) for a in args] 

I'm only giving the relevant parts here, of course.

Best,
Jesse




[PATCH v2] emacs: Add more processing of displayed headers.

2012-02-06 Thread David Edmondson
Wrap headers to the width of the window and indent continuations.
---
 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..a589d37 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -68,9 +68,16 @@ any given message."
   :type 'boolean
   :group 'notmuch-show)

-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
+(defcustom notmuch-show-markup-headers-hook '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
   "A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.")
+`notmuch-message-headers'."
+  :type 'hook
+  :options '(notmuch-show-colour-headers
+notmuch-show-fill-headers
+notmuch-show-indent-continuations)
+  :group 'notmuch-show)

 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
   "Functions called after populating a `notmuch-show' buffer."
@@ -269,13 +276,35 @@ operation on the contents of the current buffer."
 (overlay-put (make-overlay (point) (re-search-forward ".*$"))
 'face face)))

-(defun notmuch-show-colour-headers ()
+(defun notmuch-show-colour-headers (depth)
   "Apply some colouring to the current headers."
   (goto-char (point-min))
   (while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
 (notmuch-show-fontify-header)
 (forward-line)))

+(defun notmuch-show-fill-headers (depth)
+  "Wrap the text of the current headers."
+
+  ;; '-5' to allow for the indentation code.
+  (let ((fill-column (- (window-width) depth 5)))
+(goto-char (point-min))
+(while (not (eobp))
+  (let ((start (point)))
+   (end-of-line)
+   ;; We're left at the start of the next line, so there's no need
+   ;; to move forward after filling.
+   (fill-region-as-paragraph start (point))
+
+(defun notmuch-show-indent-continuations (depth)
+  "Indent any continuation lines."
+  (goto-char (point-min))
+  (while (not (eobp))
+(if (not (looking-at "^[A-Za-z][-A-Za-z0-9]*:"))
+   ;; Four spaces tends to work well with 'To' and 'Cc' headers.
+   (insert ""))
+(forward-line)))
+
 (defun notmuch-show-spaces-n (n)
   "Return a string comprised of `n' spaces."
   (make-string n ? ))
@@ -366,7 +395,7 @@ message at DEPTH in the current thread."
   "Insert a single header."
   (insert header ": " header-value "\n"))

-(defun notmuch-show-insert-headers (headers)
+(defun notmuch-show-insert-headers (headers depth)
   "Insert the headers of the current message."
   (let ((start (point)))
 (mapc (lambda (header)
@@ -379,7 +408,7 @@ message at DEPTH in the current thread."
 (save-excursion
   (save-restriction
(narrow-to-region start (point-max))
-   (run-hooks 'notmuch-show-markup-headers-hook)
+   (run-hook-with-args 'notmuch-show-markup-headers-hook depth)

 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
@@ -671,7 +700,7 @@ current buffer, if possible."
 ;; Override `notmuch-message-headers' to force `From' to be
 ;; displayed.
 (let ((notmuch-message-headers '("From" "Subject" "To" "Cc" "Date")))
-  (notmuch-show-insert-headers (plist-get message :headers)))
+  (notmuch-show-insert-headers (plist-get message :headers) 0))

 ;; Blank line after headers to be compatible with the normal
 ;; message display.
@@ -864,7 +893,7 @@ current buffer, if possible."
 ;; Set `headers-start' to point after the 'Subject:' header to be
 ;; compatible with the existing implementation. This just sets it
 ;; to after the first header.
-(notmuch-show-insert-headers headers)
+(notmuch-show-insert-headers headers depth)
 (save-excursion
   (goto-char content-start)
   ;; If the subject of this message is the same as that of the
-- 
1.7.8.3



[PATCH v2] Wrap and indent headers in show mode

2012-02-06 Thread David Edmondson
v2:
- Simple rebase.

David Edmondson (1):
  emacs: Add more processing of displayed headers.

 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

-- 
1.7.8.3



[PATCH v6 2/3] add support for user-specified files & directories to ignore

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 11:28:24 +0200, Tomi Ollila  wrote:
> A new configuration key 'new.ignore' is used to determine which
> files and directories user wants not to be scanned as new mails.
> 
> Mark the corresponding test as no longer broken.
> 
> This work merges my previous attempts and Andreas Amann's work
> in id:"ylp7hi23mw8.fsf at tyndall.ie"

I marked this patch with 'needs-review' for consistency with
the 2 other patches. No code changes to the previous version.

Tomi



[PATCH v6 3/3] NEWS: add news section for new.ignore

2012-02-06 Thread Tomi Ollila
Added NEWS section 'Mail store folder/file ignore'.
---
 NEWS |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 5c5b645..59da584 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,12 @@ Tag exclusion

 notmuch config set search.exclude_tags deleted spam

+Mail store folder/file ignore
+
+  New configuration option `new.ignore` is used to inform notmuch about
+  folders and files that are not mail files or contain material that is
+  not desired to be known by notmuch.
+
 Emacs Interface
 ---

-- 
1.7.6.5



[PATCH v6 2/3] add support for user-specified files & directories to ignore

2012-02-06 Thread Tomi Ollila
A new configuration key 'new.ignore' is used to determine which
files and directories user wants not to be scanned as new mails.

Mark the corresponding test as no longer broken.

This work merges my previous attempts and Andreas Amann's work
in id:"ylp7hi23mw8.fsf at tyndall.ie"
---
 notmuch-client.h |9 +
 notmuch-config.c |   30 +-
 notmuch-new.c|   45 +
 test/new |1 -
 4 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..f1762ae 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 const char *new_tags[],
 size_t length);

+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config,
+  size_t *length);
+
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *new_ignore[],
+  size_t length);
+
 notmuch_bool_t
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);

diff --git a/notmuch-config.c b/notmuch-config.c
index a124e34..1f01128 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -44,7 +44,10 @@ static const char new_config_comment[] =
 " The following options are supported here:\n"
 "\n"
 "\ttagsA list (separated by ';') of the tags that will be\n"
-"\tadded to all messages incorporated by \"notmuch new\".\n";
+"\tadded to all messages incorporated by \"notmuch new\".\n"
+"\n"
+"\tignore  A list (separated by ';') of file and directory names\n"
+"\tthat will not be searched for messages by \"notmuch new\".\n";

 static const char user_config_comment[] =
 " User configuration\n"
@@ -105,6 +108,8 @@ struct _notmuch_config {
 size_t user_other_email_length;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;
 notmuch_bool_t maildir_synchronize_flags;
 const char **search_exclude_tags;
 size_t search_exclude_tags_length;
@@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
 config->user_other_email_length = 0;
 config->new_tags = NULL;
 config->new_tags_length = 0;
+config->new_ignore = NULL;
+config->new_ignore_length = 0;
 config->maildir_synchronize_flags = TRUE;
 config->search_exclude_tags = NULL;
 config->search_exclude_tags_length = 0;
@@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
notmuch_config_set_new_tags (config, tags, 2);
 }

+if (notmuch_config_get_new_ignore (config, ) == NULL) {
+   notmuch_config_set_new_ignore (config, NULL, 0);
+}
+
 if (notmuch_config_get_search_exclude_tags (config, ) == NULL) {
if (is_new) {
const char *tags[] = { "deleted", "spam" };
@@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   
size_t *length)
 &(config->new_tags_length), length);
 }

+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
+{
+return _config_get_list (config, "new", "ignore",
+&(config->new_ignore),
+&(config->new_ignore_length), length);
+}
+
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
 const char *list[],
@@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 &(config->new_tags));
 }

+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *list[],
+  size_t length)
+{
+_config_set_list (config, "new", "ignore", list, length,
+&(config->new_ignore));
+}
+
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t 
*length)
 {
diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..8a615e6 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -39,6 +39,8 @@ typedef struct {
 int verbose;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;

 int total_files;
 int processed_files;
@@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int 
count)
 return 0;
 }

+/* Test if the file/directory is to be ignored.
+ */
+static notmuch_bool_t
+_entry_in_ignore_list (const char *entry, add_files_state_t *state)
+{
+size_t i;
+
+for (i = 0; i < state->new_ignore_length; i++)
+   if (strcmp (entry, state->new_ignore[i]) == 0)
+   return TRUE;
+
+return FALSE;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,

[PATCH v6 1/3] test: add tests wrt ignoring user-specified files and directories

2012-02-06 Thread Tomi Ollila
Files and directories which are specified in 'new.ignore' in the
config file shouldn't be indexed nor reported by `notmuch new'.

This is basically Pieter's work with Austin's comments addressed.
---
 test/new |   22 ++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/test/new b/test/new
index 49f390d..5ce8811 100755
--- a/test/new
+++ b/test/new
@@ -153,4 +153,26 @@ rm -rf "${MAIL_DIR}"/two
 output=$(NOTMUCH_NEW)
 test_expect_equal "$output" "No new mail. Removed 3 messages."

+# This test depends that notmuch new has been run at least once.
+test_begin_subtest "Skip and report non-mail files"
+generate_message
+mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
+touch "${MAIL_DIR}"/ignored_file
+touch "${MAIL_DIR}"/.ignored_hidden_file
+output=$(NOTMUCH_NEW 2>&1)
+test_expect_equal "$output" \
+"Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
+Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
+Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
+Added 1 new message to the database."
+
+test_begin_subtest "Ignore files and directories specified in new.ignore"
+test_subtest_known_broken
+generate_message
+notmuch config set new.ignore .git ignored_file .ignored_hidden_file
+touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
+output=$(NOTMUCH_NEW 2>&1)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+
 test_done
-- 
1.7.6.5



[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Jameson Graef Rollins
On Mon, 06 Feb 2012 08:56:34 +, David Edmondson  wrote:
> With blank subjects the printing code generated an error (because
> `rename-buffer' doesn't like an empty string as the first argument), so
> _some_ change is required.

This sounds like something that could easily be fixed in the printing
code, without changing the show and search behavior.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/a9c13a3a/attachment.pgp>


[PATCH v7 8/8] emacs: A prefix argument to `notmuch-show' should invert the matching message behaviour.

2012-02-06 Thread David Edmondson
Allow the user to open a thread with inverted
`notmuch-show-only-matching-messages' behaviour using a prefix
argument.
---
 emacs/notmuch-show.el |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 8c24f38..9c1d8fc 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1034,8 +1034,11 @@ function is used."
 ;; buffer.
 (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
 ;; Set the default value for
-;; `notmuch-show-elide-non-matching-messages' in this buffer.
+;; `notmuch-show-elide-non-matching-messages' in this buffer. If
+;; there is a prefix argument, invert the default.
 (setq notmuch-show-elide-non-matching-messages 
notmuch-show-only-matching-messages)
+(if current-prefix-arg
+   (setq notmuch-show-elide-non-matching-messages (not 
notmuch-show-elide-non-matching-messages)))

 (setq notmuch-show-thread-id thread-id
  notmuch-show-parent-buffer parent-buffer
-- 
1.7.8.3



[PATCH v7 7/8] emacs: Add `notmuch-show-only-matching-messages'.

2012-02-06 Thread David Edmondson
Allow the user to choose that only matching messages are shown by
default.
---
 emacs/notmuch-show.el |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index ec36767..8c24f38 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -125,6 +125,11 @@ indentation."
 (const :tag "View interactively"
notmuch-show-interactively-view-part)))

+(defcustom notmuch-show-only-matching-messages nil
+  "Only matching messages are shown by default."
+  :type 'boolean
+  :group 'notmuch-show)
+
 (defvar notmuch-show-thread-id nil)
 (make-variable-buffer-local 'notmuch-show-thread-id)
 (put 'notmuch-show-thread-id 'permanent-local t)
@@ -1028,6 +1033,9 @@ function is used."
 ;; Set the default value for `notmuch-show-process-crypto' in this
 ;; buffer.
 (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
+;; Set the default value for
+;; `notmuch-show-elide-non-matching-messages' in this buffer.
+(setq notmuch-show-elide-non-matching-messages 
notmuch-show-only-matching-messages)

 (setq notmuch-show-thread-id thread-id
  notmuch-show-parent-buffer parent-buffer
-- 
1.7.8.3



[PATCH v7 6/8] emacs: Check that the parent buffer is alive before using it.

2012-02-06 Thread David Edmondson
---
 emacs/notmuch-show.el |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f23aa8d..ec36767 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1683,7 +1683,7 @@ added."
   (interactive "P")
   (let ((parent-buffer notmuch-show-parent-buffer))
 (notmuch-kill-this-buffer)
-(when parent-buffer
+(when (buffer-live-p parent-buffer)
   (switch-to-buffer parent-buffer)
   (notmuch-search-next-thread)
   (if show-next
-- 
1.7.8.3



[PATCH v7 5/8] emacs: Optionally retain the state of the buffer during `notmuch-show-refresh-view'.

2012-02-06 Thread David Edmondson
With an argument, record and reply the state of the buffer during
`notmuch-show-refresh-view'.

In this context, "state" is defined as:
 - the open/closed state of each message,
 - the current message.

Traditional use of refresh with the = key does not retain the
state. The recently introduced toggle commands ($, !, < and >) do
retain the state.
---
 emacs/notmuch-show.el |   56 ++---
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index db9292c..f23aa8d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -948,7 +948,7 @@ current buffer, if possible."
   (message (if notmuch-show-process-crypto
   "Processing cryptographic MIME parts."
 "Not processing cryptographic MIME parts."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-toggle-elide-non-matching ()
   "Toggle the display of non-matching messages."
@@ -957,7 +957,7 @@ current buffer, if possible."
   (message (if notmuch-show-elide-non-matching-messages
   "Showing matching messages only."
 "Showing all messages."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-toggle-thread-indentation ()
   "Toggle the indentation of threads."
@@ -966,7 +966,7 @@ current buffer, if possible."
   (message (if notmuch-show-indent-content
   "Content is indented."
 "Content is not indented."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
@@ -1070,14 +1070,54 @@ function is used."

 (notmuch-show-mark-read)))

-(defun notmuch-show-refresh-view ()
+(defun notmuch-show-capture-state ()
+  "Capture the state of the current buffer.
+
+This includes:
+ - the list of open messages,
+ - the current message."
+  (list (notmuch-show-get-message-id) 
(notmuch-show-get-message-ids-for-open-messages)))
+
+(defun notmuch-show-apply-state (state)
+  "Apply STATE to the current buffer.
+
+This includes:
+ - opening the messages previously opened,
+ - closing all other messages,
+ - moving to the correct current message."
+  (let ((current (car state))
+   (open (cadr state)))
+
+;; Open those that were open.
+(goto-char (point-min))
+(loop do (notmuch-show-message-visible 
(notmuch-show-get-message-properties)
+  (member 
(notmuch-show-get-message-id) open))
+ until (not (notmuch-show-goto-message-next)))
+
+;; Go to the previously open message.
+(goto-char (point-min))
+(unless (loop if (string= current (notmuch-show-get-message-id))
+ return t
+ until (not (notmuch-show-goto-message-next)))
+  (goto-char (point-min))
+  (message "Previously current message not found."))
+(notmuch-show-message-adjust)))
+
+(defun notmuch-show-refresh-view ( retain-state)
   "Refresh the current view.

-Refreshes the current view, observing changes in cryptographic preferences."
+Refreshes the current view, observing changes in display
+preferences. If RETAIN-STATE is non-nil then the state of the
+buffer is stored and re-applied after the refresh."
   (interactive)
-  (let ((inhibit-read-only t))
-(erase-buffer))
-  (notmuch-show-worker))
+  (let ((inhibit-read-only t)
+   state)
+(if retain-state
+   (setq state (notmuch-show-capture-state)))
+(erase-buffer)
+(notmuch-show-worker)
+(if state
+   (notmuch-show-apply-state state

 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
-- 
1.7.8.3



[PATCH v7 4/8] emacs: Add a binding (t) to toggle the truncation of long lines.

2012-02-06 Thread David Edmondson
---
 emacs/notmuch-show.el |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 89663ee..db9292c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1131,6 +1131,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences."
(define-key map "!" 'notmuch-show-toggle-elide-non-matching)
(define-key map "$" 'notmuch-show-toggle-process-crypto)
(define-key map "<" 'notmuch-show-toggle-thread-indentation)
+   (define-key map "t" 'toggle-truncate-lines)
map)
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
-- 
1.7.8.3



[PATCH v7 3/8] emacs: Allow the indentation of content to be toggled.

2012-02-06 Thread David Edmondson
Very deeply indented content is sometimes difficult to
read (particular for something like patches). Allow the indentation of
the content to be toggled with '<'.

Indentation of the header lines is not affected, so it remains
possible to see the structure of the thread.
---
 emacs/notmuch-show.el |   26 ++
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 39f19d3..89663ee 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -145,6 +145,10 @@ indentation."
 (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
 (put 'notmuch-show-elide-non-matching-messages 'permanent-local t)

+(defvar notmuch-show-indent-content t)
+(make-variable-buffer-local 'notmuch-show-indent-content)
+(put 'notmuch-show-indent-content 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -255,10 +259,12 @@ operation on the contents of the current buffer."
 (all (buffer-substring (notmuch-show-message-top)
(notmuch-show-message-bottom)))

-(props (notmuch-show-get-message-properties)))
+(props (notmuch-show-get-message-properties))
+(indenting notmuch-show-indent-content))
 (with-temp-buffer
   (insert all)
-  (indent-rigidly (point-min) (point-max) (- depth))
+  (if indenting
+ (indent-rigidly (point-min) (point-max) (- depth)))
   ;; Remove the original header.
   (goto-char (point-min))
   (re-search-forward "^$" (point-max) nil)
@@ -896,7 +902,8 @@ current buffer, if possible."
 (setq body-start (point-marker))
 ;; A blank line between the headers and the body.
 (insert "\n")
-(notmuch-show-insert-body msg (plist-get msg :body) depth)
+(notmuch-show-insert-body msg (plist-get msg :body)
+ (if notmuch-show-indent-content depth 0))
 ;; Ensure that the body ends with a newline.
 (unless (bolp)
   (insert "\n"))
@@ -904,7 +911,8 @@ current buffer, if possible."
 (setq content-end (point-marker))

 ;; Indent according to the depth in the thread.
-(indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth))
+(if notmuch-show-indent-content
+   (indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth)))

 (setq message-end (point-max-marker))

@@ -951,6 +959,15 @@ current buffer, if possible."
 "Showing all messages."))
   (notmuch-show-refresh-view))

+(defun notmuch-show-toggle-thread-indentation ()
+  "Toggle the indentation of threads."
+  (interactive)
+  (setq notmuch-show-indent-content (not notmuch-show-indent-content))
+  (message (if notmuch-show-indent-content
+  "Content is indented."
+"Content is not indented."))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -1113,6 +1130,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences."
(define-key map "#" 'notmuch-show-print-message)
(define-key map "!" 'notmuch-show-toggle-elide-non-matching)
(define-key map "$" 'notmuch-show-toggle-process-crypto)
+   (define-key map "<" 'notmuch-show-toggle-thread-indentation)
map)
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
-- 
1.7.8.3



[PATCH v7 2/8] emacs: Allow `notmuch-show-mode' to display only matching messages.

2012-02-06 Thread David Edmondson
The current behaviour (all messages shown, non-matching collapsed)
is retained as the default. Type '!' to switch to showing only
the matching messages - non-matching messages are not available.
'!' will switch back to showing everything.
---
 emacs/notmuch-show.el |   18 +-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 4b29dbd..39f19d3 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -141,6 +141,10 @@ indentation."
 (make-variable-buffer-local 'notmuch-show-process-crypto)
 (put 'notmuch-show-process-crypto 'permanent-local t)

+(defvar notmuch-show-elide-non-matching-messages nil)
+(make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
+(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -938,11 +942,22 @@ current buffer, if possible."
 "Not processing cryptographic MIME parts."))
   (notmuch-show-refresh-view))

+(defun notmuch-show-toggle-elide-non-matching ()
+  "Toggle the display of non-matching messages."
+  (interactive)
+  (setq notmuch-show-elide-non-matching-messages (not 
notmuch-show-elide-non-matching-messages))
+  (message (if notmuch-show-elide-non-matching-messages
+  "Showing matching messages only."
+"Showing all messages."))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
(replies (cadr tree)))
-(notmuch-show-insert-msg msg depth)
+(if (or (not notmuch-show-elide-non-matching-messages)
+   (plist-get msg :match))
+   (notmuch-show-insert-msg msg depth))
 (notmuch-show-insert-thread replies (1+ depth

 (defun notmuch-show-insert-thread (thread depth)
@@ -1096,6 +,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences."
(define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)
(define-key map (kbd "RET") 'notmuch-show-toggle-message)
(define-key map "#" 'notmuch-show-print-message)
+   (define-key map "!" 'notmuch-show-toggle-elide-non-matching)
(define-key map "$" 'notmuch-show-toggle-process-crypto)
map)
   "Keymap for \"notmuch show\" buffers.")
-- 
1.7.8.3



[PATCH v7 1/8] emacs: Rework crypto switch toggle.

2012-02-06 Thread David Edmondson
Re-work the existing crypto switch toggle to be based on a persistant
buffer-local variable.

To allow this, modify `notmuch-show-refresh-view' to erase and re-draw
in the current buffer rather than killing the current buffer and
creating a new one. (This will also allow more per-buffer behaviour in
future patches.)

Add a binding ('$') to toggle crypto processing of the current buffer
and remove the prefix argument approach that achieves a similar
result.
---
 emacs/notmuch-show.el |  126 
 emacs/notmuch.el  |7 +--
 2 files changed, 66 insertions(+), 67 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4b29dbd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -125,6 +125,22 @@ indentation."
 (const :tag "View interactively"
notmuch-show-interactively-view-part)))

+(defvar notmuch-show-thread-id nil)
+(make-variable-buffer-local 'notmuch-show-thread-id)
+(put 'notmuch-show-thread-id 'permanent-local t)
+
+(defvar notmuch-show-parent-buffer nil)
+(make-variable-buffer-local 'notmuch-show-parent-buffer)
+(put 'notmuch-show-parent-buffer 'permanent-local t)
+
+(defvar notmuch-show-query-context nil)
+(make-variable-buffer-local 'notmuch-show-query-context)
+(put 'notmuch-show-query-context 'permanent-local t)
+
+(defvar notmuch-show-process-crypto nil)
+(make-variable-buffer-local 'notmuch-show-process-crypto)
+(put 'notmuch-show-process-crypto 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message ( body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -421,14 +437,11 @@ message at DEPTH in the current thread."

 (defmacro notmuch-with-temp-part-buffer (message-id nth  body)
   (declare (indent 2))
-  (let ((process-crypto (make-symbol "process-crypto")))
-`(let ((,process-crypto notmuch-show-process-crypto))
-   (with-temp-buffer
-(setq notmuch-show-process-crypto ,process-crypto)
-;; Always acquires the part via `notmuch part', even if it is
-;; available in the JSON output.
-(insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
-, at body
+  `(with-temp-buffer
+ ;; Always acquires the part via `notmuch part', even if it is
+ ;; available in the JSON output.
+ (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
+ , at body))

 (defun notmuch-show-save-part (message-id nth  filename content-type)
   (notmuch-with-temp-part-buffer message-id nth
@@ -610,7 +623,7 @@ current buffer, if possible."
   (sigstatus (car (plist-get part :sigstatus
  (notmuch-crypto-insert-sigstatus-button sigstatus from))
   ;; if we're not adding sigstatus, tell the user how they can get it
-  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic mime parts.")))
+  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic MIME parts.")))

   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -636,7 +649,7 @@ current buffer, if possible."
 (sigstatus (car (plist-get part :sigstatus
(notmuch-crypto-insert-sigstatus-button sigstatus from
   ;; if we're not adding encstatus, tell the user how they can get it
-  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic mime parts.")))
+  (button-put button 'help-echo "Set notmuch-crypto-process-mime to 
process cryptographic MIME parts.")))

   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -763,8 +776,6 @@ current buffer, if possible."

 ;; Helper for parts which are generally not included in the default
 ;; JSON output.
-;; Uses the buffer-local variable notmuch-show-process-crypto to
-;; determine if parts should be decrypted first.
 (defun notmuch-show-get-bodypart-internal (message-id part-number)
   (let ((args '("show" "--format=raw"))
(part-arg (format "--part=%s" part-number)))
@@ -918,6 +929,15 @@ current buffer, if possible."
 ;; criteria.
 (notmuch-show-message-visible msg (plist-get msg :match

+(defun notmuch-show-toggle-process-crypto ()
+  "Toggle the processing of cryptographic MIME parts."
+  (interactive)
+  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))
+  (message (if notmuch-show-process-crypto
+  "Processing cryptographic MIME parts."
+"Not processing cryptographic MIME parts."))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -933,15 +953,6 @@ current buffer, if possible."
   "Insert the forest of threads FOREST."
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))

-(defvar notmuch-show-thread-id nil)

[PATCH v7 0/8] reworked crypto toggle, plus a few other toggles

2012-02-06 Thread David Edmondson
v7:
- Simple rebase.

David Edmondson (8):
  emacs: Rework crypto switch toggle.
  emacs: Allow `notmuch-show-mode' to display only matching messages.
  emacs: Allow the indentation of content to be toggled.
  emacs: Add a binding (t) to toggle the truncation of long lines.
  emacs: Optionally retain the state of the buffer during
`notmuch-show-refresh-view'.
  emacs: Check that the parent buffer is alive before using it.
  emacs: Add `notmuch-show-only-matching-messages'.
  emacs: A prefix argument to `notmuch-show' should invert the matching
message behaviour.

 emacs/notmuch-show.el |  224 ++---
 emacs/notmuch.el  |7 +-
 2 files changed, 158 insertions(+), 73 deletions(-)

-- 
1.7.8.3



[PATCH 1/2] cli: convert "notmuch show" to use the new argument parser

2012-02-06 Thread Austin Clements
Quoth Jani Nikula on Feb 06 at  7:54 am:
> On Sun, 5 Feb 2012 23:12:05 -0500, Austin Clements  
> wrote:
> > Yikes.  I don't envy you this patch.  Two minor nits, otherwise this
> > and the next patch LGTM.
> 
> Thanks for the review. I'll roll another version, I think it will be
> better with your suggestions incorporated.
> 
> > Quoth Jani Nikula on Feb 04 at 12:41 am:
> > > Use the new notmuch argument parser to handle arguments in "notmuch
> > > show". There are two corner case functional changes:
> > > 
> > > 1) Also set params.raw = 1 when defaulting to raw format when part is
> > >requested but format is not specified.
> > 
> > Huh.  So "notmuch show --part=0 " was broken before.
> 
> Hmm, yes, it seems so. Do you think I should make this a separate fix?

I wouldn't bother.  Since this usage would throw --format=raw into
"useless mode", clearly no one cared.  No sense throwing good code
after bad.


[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread David Edmondson
On Mon, 06 Feb 2012 00:06:54 -0800, Jameson Graef Rollins  wrote:
> On Mon, 06 Feb 2012 07:47:38 +, David Edmondson  wrote:
> > On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins  > finestructure.net> wrote:
> > > Sorry to be so late on this, but I'm not a big fan of this new feature.
> > > I would prefer to always see the subject (or any other field for that
> > > matter) as is.
> > 
> > The Emacs UI always replaced blank subjects with '[No Subject]' in
> > buffer names. The printing code also needed something other than a blank
> > subject for buffer renaming.
> 
> I don't much care what the buffer name is.  That seems to be a
> completely different issue to me.

I agree that they could be treated differently.

With blank subjects the printing code generated an error (because
`rename-buffer' doesn't like an empty string as the first argument), so
_some_ change is required.

> > Updating `notmuch-prettify-subject' to use a user configurable string
> > (that can be set to the empty string) sounds like a good idea. Please
> > ensure that the various other bits of code that require something other
> > than a blank subject still work properly.
> 
> I am actually perfectly happy to see this patch reverted.

Whatever bremner decides.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/5804f252/attachment.pgp>


newbie questions

2012-02-06 Thread Tomi Ollila
On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp  wrote:
> Hi,
> 
> I just started using notmuch.  It is fascinating, but I still need to
> figure out a few things:
> 
> 1. How can I restrict searches (eg of my inbox) to the last few
> messages (eg 50-100) or some date (eg last 2 weeks)?  I am using the
> Emacs interface.

Currently, if you have GNU date you can run from command line:

date +%s.. --date '2 weeks ago'

Then paste the string 1327300096.. to the search field.

> 2. Could someone point me to some guides on workflow with notmuch in
> Emacs?  So far I have been using mutt, and I guess I need to rethink a
> few things.

guides??? what guides??? ;) http://notmuchmail.org/ has some (old)
practices available...

> 3. If I have multiple accounts, how can I change my e-mail address
> (From:) when I am writing messages (within emacs, using the m key).

This is something I've long been planning to look out but so far
my needs have been so small that the effort threshold has not been 
passed...

> Thanks,
> 
> Tamas

Tomi


NEWS: add entries for the changes in the python bindings

2012-02-06 Thread Tomi Ollila
On Mon, 06 Feb 2012 00:21:58 -, Justus Winter <4winter at 
informatik.uni-hamburg.de> wrote:
> Quoting Tomi Ollila (2012-02-05 22:19:16)
> >On Sun, 29 Jan 2012 18:08:50 +0100, Justus Winter <4winter at 
> >informatik.uni-hamburg.de> wrote:
> >> This patch series adds a section for the python binding changes to the
> >> NEWS file.
> >
> >I marked patches 2/3 and 3/3 stale as git-am doesn't accept those anymore
> >on top of 2c6710e3ba22f5af6e5813dad8bee732e6c5d02c.
> 
> come on... these are patches for the NEWS file, it's as much work for
> me to merge these as for anyone else ;)

Yes I just happened to add the 'notmuch::patch' tag without checking
that the patches apply (and those appeared to ready list)... So I did
not have much choice for the time being...


> Justus

Tomi


[PATCH 1/2] cli: convert "notmuch show" to use the new argument parser

2012-02-06 Thread Jani Nikula
On Sun, 5 Feb 2012 23:12:05 -0500, Austin Clements  wrote:
> Yikes.  I don't envy you this patch.  Two minor nits, otherwise this
> and the next patch LGTM.

Thanks for the review. I'll roll another version, I think it will be
better with your suggestions incorporated.

> Quoth Jani Nikula on Feb 04 at 12:41 am:
> > Use the new notmuch argument parser to handle arguments in "notmuch
> > show". There are two corner case functional changes:
> > 
> > 1) Also set params.raw = 1 when defaulting to raw format when part is
> >requested but format is not specified.
> 
> Huh.  So "notmuch show --part=0 " was broken before.

Hmm, yes, it seems so. Do you think I should make this a separate fix?

BTW an alternative would be to require setting --format if --part is
specified, and not adapt the default format depending on --part.

> > 2) Do not set params.decrypt if crypto context creation fails.
> 
> Technically this also behaves differently if given multiple --format
> arguments, but I'll let that slide.

Ugh, right, the old parsing was broken also that way. Luckily that falls
in the corner case department too.

> > 
> > Signed-off-by: Jani Nikula 
> > ---
> >  notmuch-show.c |  153 
> > +---
> >  1 files changed, 79 insertions(+), 74 deletions(-)
> > 
> > diff --git a/notmuch-show.c b/notmuch-show.c
> > index dec799c..f93e121 100644
> > --- a/notmuch-show.c
> > +++ b/notmuch-show.c
> > @@ -1049,6 +1049,14 @@ do_show (void *ctx,
> >  return 0;
> >  }
> >  
> > +enum {
> > +NOTMUCH_FORMAT_NOT_SPECIFIED,
> > +NOTMUCH_FORMAT_JSON,
> > +NOTMUCH_FORMAT_TEXT,
> > +NOTMUCH_FORMAT_MBOX,
> > +NOTMUCH_FORMAT_RAW
> > +};
> > +
> >  int
> >  notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
> >  {
> > @@ -1056,92 +1064,98 @@ notmuch_show_command (void *ctx, unused (int argc), 
> > unused (char *argv[]))
> >  notmuch_database_t *notmuch;
> >  notmuch_query_t *query;
> >  char *query_string;
> > -char *opt;
> > +int opt_index;
> >  const notmuch_show_format_t *format = _text;
> > -notmuch_show_params_t params;
> > -int mbox = 0;
> > -int format_specified = 0;
> > -int i;
> > +notmuch_show_params_t params = { .part = -1 };
> > +int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
> > +notmuch_bool_t decrypt = FALSE;
> > +notmuch_bool_t verify = FALSE;
> > +notmuch_bool_t entire_thread = FALSE;
> > +
> > +notmuch_opt_desc_t options[] = {
> > +   { NOTMUCH_OPT_KEYWORD, _sel, "format", 'f',
> > + (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
> > + { "text", NOTMUCH_FORMAT_TEXT },
> > + { "mbox", NOTMUCH_FORMAT_MBOX },
> > + { "raw", NOTMUCH_FORMAT_RAW },
> > + { 0, 0 } } },
> > +   { NOTMUCH_OPT_INT, , "part", 'p', 0 },
> > +   { NOTMUCH_OPT_BOOLEAN, _thread, "entire-thread", 't', 0 },
> > +   { NOTMUCH_OPT_BOOLEAN, , "decrypt", 'd', 0 },
> > +   { NOTMUCH_OPT_BOOLEAN, , "verify", 'v', 0 },
> > +   { 0, 0, 0, 0, 0 }
> > +};
> > +
> > +opt_index = parse_arguments (argc, argv, options, 1);
> > +if (opt_index < 0) {
> > +   /* diagnostics already printed */
> > +   return 1;
> > +}
> >  
> > -params.entire_thread = 0;
> > -params.raw = 0;
> > -params.part = -1;
> > -params.cryptoctx = NULL;
> > -params.decrypt = 0;
> > +params.entire_thread = entire_thread;
> 
> If you make params.entire_thread a notmuch_bool_t (instead of an int),
> you could pass _thread in the notmuch_opt_desc_t and get
> rid of the local variable.

You're right; I was a bit lazy and didn't consider changing
notmuch_show_params_t. I'll change both this and params.decrypt to
notmuch_bool_t.

> 
> >  
> > -argc--; argv++; /* skip subcommand argument */
> > +if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
> > +   /* if part was requested and format was not specified, use format=raw */
> > +   if (params.part >= 0)
> > +   format_sel = NOTMUCH_FORMAT_RAW;
> > +   else
> > +   format_sel = NOTMUCH_FORMAT_TEXT;
> > +}
> >  
> > -for (i = 0; i < argc && argv[i][0] == '-'; i++) {
> > -   if (strcmp (argv[i], "--") == 0) {
> > -   i++;
> > -   break;
> > +switch (format_sel) {
> > +case NOTMUCH_FORMAT_JSON:
> > +   format = _json;
> > +   params.entire_thread = 1;
> > +   break;
> > +case NOTMUCH_FORMAT_TEXT:
> > +   format = _text;
> > +   break;
> > +case NOTMUCH_FORMAT_MBOX:
> > +   if (params.part > 0) {
> > +   fprintf (stderr, "Error: specifying parts is incompatible with mbox 
> > output format.\n");
> > +   return 1;
> > }
> > -   if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
> > -   opt = argv[i] + sizeof ("--format=") - 1;
> > -   if (strcmp (opt, "text") == 0) {
> > -   format = _text;
> > -   } else if (strcmp (opt, "json") == 0) {
> > -   format 

[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread David Edmondson
On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins  wrote:
> Sorry to be so late on this, but I'm not a big fan of this new feature.
> I would prefer to always see the subject (or any other field for that
> matter) as is.

The Emacs UI always replaced blank subjects with '[No Subject]' in
buffer names. The printing code also needed something other than a blank
subject for buffer renaming.

> As a principle I would prefer there not be text replacements unless it's
> very clear that text has been replaced.  Buttons work because it's clear
> they're buttons.  This is not the case here, though, since this text
> replacement could actually be confused with real text.
> 
> It's also not clear to me why this feature would be needed.  I have
> never found blank subjects confusing.  The field is always clearly
> delineated, at least in search and show mode.  If it's not clear
> elsewhere, maybe we can make the delineation of the subject field
> clearer, but leave the actual subject text string alone.
> 
> If some feel this feature is really needed we should at least have a
> customization variable.  notmuch-unblank-subject?  I don't have any good
> name suggestions, though.

Updating `notmuch-prettify-subject' to use a user configurable string
(that can be set to the empty string) sounds like a good idea. Please
ensure that the various other bits of code that require something other
than a blank subject still work properly.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/9cf7dd14/attachment.pgp>


NEWS: add entries for the changes in the python bindings

2012-02-06 Thread Justus Winter
Quoting Tomi Ollila (2012-02-05 22:19:16)
>On Sun, 29 Jan 2012 18:08:50 +0100, Justus Winter <4winter at 
>informatik.uni-hamburg.de> wrote:
>> This patch series adds a section for the python binding changes to the
>> NEWS file.
>
>I marked patches 2/3 and 3/3 stale as git-am doesn't accept those anymore
>on top of 2c6710e3ba22f5af6e5813dad8bee732e6c5d02c.

come on... these are patches for the NEWS file, it's as much work for
me to merge these as for anyone else ;)

Justus


[PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Jameson Graef Rollins
On Mon, 06 Feb 2012 07:47:38 +, David Edmondson  wrote:
> On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins  finestructure.net> wrote:
> > Sorry to be so late on this, but I'm not a big fan of this new feature.
> > I would prefer to always see the subject (or any other field for that
> > matter) as is.
> 
> The Emacs UI always replaced blank subjects with '[No Subject]' in
> buffer names. The printing code also needed something other than a blank
> subject for buffer renaming.

I don't much care what the buffer name is.  That seems to be a
completely different issue to me.

> Updating `notmuch-prettify-subject' to use a user configurable string
> (that can be set to the empty string) sounds like a good idea. Please
> ensure that the various other bits of code that require something other
> than a blank subject still work properly.

I am actually perfectly happy to see this patch reverted.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120206/909a1bf2/attachment-0001.pgp>


Re: [PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Jameson Graef Rollins
On Mon, 06 Feb 2012 07:47:38 +, David Edmondson d...@dme.org wrote:
 On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins 
 jroll...@finestructure.net wrote:
  Sorry to be so late on this, but I'm not a big fan of this new feature.
  I would prefer to always see the subject (or any other field for that
  matter) as is.
 
 The Emacs UI always replaced blank subjects with '[No Subject]' in
 buffer names. The printing code also needed something other than a blank
 subject for buffer renaming.

I don't much care what the buffer name is.  That seems to be a
completely different issue to me.

 Updating `notmuch-prettify-subject' to use a user configurable string
 (that can be set to the empty string) sounds like a good idea. Please
 ensure that the various other bits of code that require something other
 than a blank subject still work properly.

I am actually perfectly happy to see this patch reverted.

jamie.


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


Re: [PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread David Edmondson
On Mon, 06 Feb 2012 00:06:54 -0800, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Mon, 06 Feb 2012 07:47:38 +, David Edmondson d...@dme.org wrote:
  On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins 
  jroll...@finestructure.net wrote:
   Sorry to be so late on this, but I'm not a big fan of this new feature.
   I would prefer to always see the subject (or any other field for that
   matter) as is.
  
  The Emacs UI always replaced blank subjects with '[No Subject]' in
  buffer names. The printing code also needed something other than a blank
  subject for buffer renaming.
 
 I don't much care what the buffer name is.  That seems to be a
 completely different issue to me.

I agree that they could be treated differently.

With blank subjects the printing code generated an error (because
`rename-buffer' doesn't like an empty string as the first argument), so
_some_ change is required.

  Updating `notmuch-prettify-subject' to use a user configurable string
  (that can be set to the empty string) sounds like a good idea. Please
  ensure that the various other bits of code that require something other
  than a blank subject still work properly.
 
 I am actually perfectly happy to see this patch reverted.

Whatever bremner decides.


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


[PATCH v7 2/8] emacs: Allow `notmuch-show-mode' to display only matching messages.

2012-02-06 Thread David Edmondson
The current behaviour (all messages shown, non-matching collapsed)
is retained as the default. Type '!' to switch to showing only
the matching messages - non-matching messages are not available.
'!' will switch back to showing everything.
---
 emacs/notmuch-show.el |   18 +-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 4b29dbd..39f19d3 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -141,6 +141,10 @@ indentation.
 (make-variable-buffer-local 'notmuch-show-process-crypto)
 (put 'notmuch-show-process-crypto 'permanent-local t)
 
+(defvar notmuch-show-elide-non-matching-messages nil)
+(make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
+(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message (rest body)
   Evaluate body with current buffer set to the text of current message
   `(save-excursion
@@ -938,11 +942,22 @@ current buffer, if possible.
 Not processing cryptographic MIME parts.))
   (notmuch-show-refresh-view))
 
+(defun notmuch-show-toggle-elide-non-matching ()
+  Toggle the display of non-matching messages.
+  (interactive)
+  (setq notmuch-show-elide-non-matching-messages (not 
notmuch-show-elide-non-matching-messages))
+  (message (if notmuch-show-elide-non-matching-messages
+  Showing matching messages only.
+Showing all messages.))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   Insert the message tree TREE at depth DEPTH in the current thread.
   (let ((msg (car tree))
(replies (cadr tree)))
-(notmuch-show-insert-msg msg depth)
+(if (or (not notmuch-show-elide-non-matching-messages)
+   (plist-get msg :match))
+   (notmuch-show-insert-msg msg depth))
 (notmuch-show-insert-thread replies (1+ depth
 
 (defun notmuch-show-insert-thread (thread depth)
@@ -1096,6 +,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences.
(define-key map (kbd M-RET) 'notmuch-show-open-or-close-all)
(define-key map (kbd RET) 'notmuch-show-toggle-message)
(define-key map # 'notmuch-show-print-message)
+   (define-key map ! 'notmuch-show-toggle-elide-non-matching)
(define-key map $ 'notmuch-show-toggle-process-crypto)
map)
   Keymap for \notmuch show\ buffers.)
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 4/8] emacs: Add a binding (t) to toggle the truncation of long lines.

2012-02-06 Thread David Edmondson
---
 emacs/notmuch-show.el |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 89663ee..db9292c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1131,6 +1131,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences.
(define-key map ! 'notmuch-show-toggle-elide-non-matching)
(define-key map $ 'notmuch-show-toggle-process-crypto)
(define-key map  'notmuch-show-toggle-thread-indentation)
+   (define-key map t 'toggle-truncate-lines)
map)
   Keymap for \notmuch show\ buffers.)
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 0/8] reworked crypto toggle, plus a few other toggles

2012-02-06 Thread David Edmondson
v7:
- Simple rebase.

David Edmondson (8):
  emacs: Rework crypto switch toggle.
  emacs: Allow `notmuch-show-mode' to display only matching messages.
  emacs: Allow the indentation of content to be toggled.
  emacs: Add a binding (t) to toggle the truncation of long lines.
  emacs: Optionally retain the state of the buffer during
`notmuch-show-refresh-view'.
  emacs: Check that the parent buffer is alive before using it.
  emacs: Add `notmuch-show-only-matching-messages'.
  emacs: A prefix argument to `notmuch-show' should invert the matching
message behaviour.

 emacs/notmuch-show.el |  224 ++---
 emacs/notmuch.el  |7 +-
 2 files changed, 158 insertions(+), 73 deletions(-)

-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 1/8] emacs: Rework crypto switch toggle.

2012-02-06 Thread David Edmondson
Re-work the existing crypto switch toggle to be based on a persistant
buffer-local variable.

To allow this, modify `notmuch-show-refresh-view' to erase and re-draw
in the current buffer rather than killing the current buffer and
creating a new one. (This will also allow more per-buffer behaviour in
future patches.)

Add a binding ('$') to toggle crypto processing of the current buffer
and remove the prefix argument approach that achieves a similar
result.
---
 emacs/notmuch-show.el |  126 
 emacs/notmuch.el  |7 +--
 2 files changed, 66 insertions(+), 67 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4b29dbd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -125,6 +125,22 @@ indentation.
 (const :tag View interactively
notmuch-show-interactively-view-part)))
 
+(defvar notmuch-show-thread-id nil)
+(make-variable-buffer-local 'notmuch-show-thread-id)
+(put 'notmuch-show-thread-id 'permanent-local t)
+
+(defvar notmuch-show-parent-buffer nil)
+(make-variable-buffer-local 'notmuch-show-parent-buffer)
+(put 'notmuch-show-parent-buffer 'permanent-local t)
+
+(defvar notmuch-show-query-context nil)
+(make-variable-buffer-local 'notmuch-show-query-context)
+(put 'notmuch-show-query-context 'permanent-local t)
+
+(defvar notmuch-show-process-crypto nil)
+(make-variable-buffer-local 'notmuch-show-process-crypto)
+(put 'notmuch-show-process-crypto 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message (rest body)
   Evaluate body with current buffer set to the text of current message
   `(save-excursion
@@ -421,14 +437,11 @@ message at DEPTH in the current thread.
 
 (defmacro notmuch-with-temp-part-buffer (message-id nth rest body)
   (declare (indent 2))
-  (let ((process-crypto (make-symbol process-crypto)))
-`(let ((,process-crypto notmuch-show-process-crypto))
-   (with-temp-buffer
-(setq notmuch-show-process-crypto ,process-crypto)
-;; Always acquires the part via `notmuch part', even if it is
-;; available in the JSON output.
-(insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
-,@body
+  `(with-temp-buffer
+ ;; Always acquires the part via `notmuch part', even if it is
+ ;; available in the JSON output.
+ (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
+ ,@body))
 
 (defun notmuch-show-save-part (message-id nth optional filename content-type)
   (notmuch-with-temp-part-buffer message-id nth
@@ -610,7 +623,7 @@ current buffer, if possible.
   (sigstatus (car (plist-get part :sigstatus
  (notmuch-crypto-insert-sigstatus-button sigstatus from))
   ;; if we're not adding sigstatus, tell the user how they can get it
-  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic mime parts.)))
+  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic MIME parts.)))
 
   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -636,7 +649,7 @@ current buffer, if possible.
 (sigstatus (car (plist-get part :sigstatus
(notmuch-crypto-insert-sigstatus-button sigstatus from
   ;; if we're not adding encstatus, tell the user how they can get it
-  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic mime parts.)))
+  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic MIME parts.)))
 
   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -763,8 +776,6 @@ current buffer, if possible.
 
 ;; Helper for parts which are generally not included in the default
 ;; JSON output.
-;; Uses the buffer-local variable notmuch-show-process-crypto to
-;; determine if parts should be decrypted first.
 (defun notmuch-show-get-bodypart-internal (message-id part-number)
   (let ((args '(show --format=raw))
(part-arg (format --part=%s part-number)))
@@ -918,6 +929,15 @@ current buffer, if possible.
 ;; criteria.
 (notmuch-show-message-visible msg (plist-get msg :match
 
+(defun notmuch-show-toggle-process-crypto ()
+  Toggle the processing of cryptographic MIME parts.
+  (interactive)
+  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))
+  (message (if notmuch-show-process-crypto
+  Processing cryptographic MIME parts.
+Not processing cryptographic MIME parts.))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   Insert the message tree TREE at depth DEPTH in the current thread.
   (let ((msg (car tree))
@@ -933,15 +953,6 @@ current buffer, if possible.
   Insert the forest of threads FOREST.
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
 
-(defvar notmuch-show-thread-id nil)
-(make-variable-buffer-local 

[PATCH v7 3/8] emacs: Allow the indentation of content to be toggled.

2012-02-06 Thread David Edmondson
Very deeply indented content is sometimes difficult to
read (particular for something like patches). Allow the indentation of
the content to be toggled with ''.

Indentation of the header lines is not affected, so it remains
possible to see the structure of the thread.
---
 emacs/notmuch-show.el |   26 ++
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 39f19d3..89663ee 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -145,6 +145,10 @@ indentation.
 (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
 (put 'notmuch-show-elide-non-matching-messages 'permanent-local t)
 
+(defvar notmuch-show-indent-content t)
+(make-variable-buffer-local 'notmuch-show-indent-content)
+(put 'notmuch-show-indent-content 'permanent-local t)
+
 (defmacro with-current-notmuch-show-message (rest body)
   Evaluate body with current buffer set to the text of current message
   `(save-excursion
@@ -255,10 +259,12 @@ operation on the contents of the current buffer.
 (all (buffer-substring (notmuch-show-message-top)
(notmuch-show-message-bottom)))
 
-(props (notmuch-show-get-message-properties)))
+(props (notmuch-show-get-message-properties))
+(indenting notmuch-show-indent-content))
 (with-temp-buffer
   (insert all)
-  (indent-rigidly (point-min) (point-max) (- depth))
+  (if indenting
+ (indent-rigidly (point-min) (point-max) (- depth)))
   ;; Remove the original header.
   (goto-char (point-min))
   (re-search-forward ^$ (point-max) nil)
@@ -896,7 +902,8 @@ current buffer, if possible.
 (setq body-start (point-marker))
 ;; A blank line between the headers and the body.
 (insert \n)
-(notmuch-show-insert-body msg (plist-get msg :body) depth)
+(notmuch-show-insert-body msg (plist-get msg :body)
+ (if notmuch-show-indent-content depth 0))
 ;; Ensure that the body ends with a newline.
 (unless (bolp)
   (insert \n))
@@ -904,7 +911,8 @@ current buffer, if possible.
 (setq content-end (point-marker))
 
 ;; Indent according to the depth in the thread.
-(indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth))
+(if notmuch-show-indent-content
+   (indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth)))
 
 (setq message-end (point-max-marker))
 
@@ -951,6 +959,15 @@ current buffer, if possible.
 Showing all messages.))
   (notmuch-show-refresh-view))
 
+(defun notmuch-show-toggle-thread-indentation ()
+  Toggle the indentation of threads.
+  (interactive)
+  (setq notmuch-show-indent-content (not notmuch-show-indent-content))
+  (message (if notmuch-show-indent-content
+  Content is indented.
+Content is not indented.))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-insert-tree (tree depth)
   Insert the message tree TREE at depth DEPTH in the current thread.
   (let ((msg (car tree))
@@ -1113,6 +1130,7 @@ Refreshes the current view, observing changes in 
cryptographic preferences.
(define-key map # 'notmuch-show-print-message)
(define-key map ! 'notmuch-show-toggle-elide-non-matching)
(define-key map $ 'notmuch-show-toggle-process-crypto)
+   (define-key map  'notmuch-show-toggle-thread-indentation)
map)
   Keymap for \notmuch show\ buffers.)
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 6/8] emacs: Check that the parent buffer is alive before using it.

2012-02-06 Thread David Edmondson
---
 emacs/notmuch-show.el |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f23aa8d..ec36767 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1683,7 +1683,7 @@ added.
   (interactive P)
   (let ((parent-buffer notmuch-show-parent-buffer))
 (notmuch-kill-this-buffer)
-(when parent-buffer
+(when (buffer-live-p parent-buffer)
   (switch-to-buffer parent-buffer)
   (notmuch-search-next-thread)
   (if show-next
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 5/8] emacs: Optionally retain the state of the buffer during `notmuch-show-refresh-view'.

2012-02-06 Thread David Edmondson
With an argument, record and reply the state of the buffer during
`notmuch-show-refresh-view'.

In this context, state is defined as:
 - the open/closed state of each message,
 - the current message.

Traditional use of refresh with the = key does not retain the
state. The recently introduced toggle commands ($, !,  and ) do
retain the state.
---
 emacs/notmuch-show.el |   56 ++---
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index db9292c..f23aa8d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -948,7 +948,7 @@ current buffer, if possible.
   (message (if notmuch-show-process-crypto
   Processing cryptographic MIME parts.
 Not processing cryptographic MIME parts.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-toggle-elide-non-matching ()
   Toggle the display of non-matching messages.
@@ -957,7 +957,7 @@ current buffer, if possible.
   (message (if notmuch-show-elide-non-matching-messages
   Showing matching messages only.
 Showing all messages.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-toggle-thread-indentation ()
   Toggle the indentation of threads.
@@ -966,7 +966,7 @@ current buffer, if possible.
   (message (if notmuch-show-indent-content
   Content is indented.
 Content is not indented.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-insert-tree (tree depth)
   Insert the message tree TREE at depth DEPTH in the current thread.
@@ -1070,14 +1070,54 @@ function is used.
 
 (notmuch-show-mark-read)))
 
-(defun notmuch-show-refresh-view ()
+(defun notmuch-show-capture-state ()
+  Capture the state of the current buffer.
+
+This includes:
+ - the list of open messages,
+ - the current message.
+  (list (notmuch-show-get-message-id) 
(notmuch-show-get-message-ids-for-open-messages)))
+
+(defun notmuch-show-apply-state (state)
+  Apply STATE to the current buffer.
+
+This includes:
+ - opening the messages previously opened,
+ - closing all other messages,
+ - moving to the correct current message.
+  (let ((current (car state))
+   (open (cadr state)))
+
+;; Open those that were open.
+(goto-char (point-min))
+(loop do (notmuch-show-message-visible 
(notmuch-show-get-message-properties)
+  (member 
(notmuch-show-get-message-id) open))
+ until (not (notmuch-show-goto-message-next)))
+
+;; Go to the previously open message.
+(goto-char (point-min))
+(unless (loop if (string= current (notmuch-show-get-message-id))
+ return t
+ until (not (notmuch-show-goto-message-next)))
+  (goto-char (point-min))
+  (message Previously current message not found.))
+(notmuch-show-message-adjust)))
+
+(defun notmuch-show-refresh-view (optional retain-state)
   Refresh the current view.
 
-Refreshes the current view, observing changes in cryptographic preferences.
+Refreshes the current view, observing changes in display
+preferences. If RETAIN-STATE is non-nil then the state of the
+buffer is stored and re-applied after the refresh.
   (interactive)
-  (let ((inhibit-read-only t))
-(erase-buffer))
-  (notmuch-show-worker))
+  (let ((inhibit-read-only t)
+   state)
+(if retain-state
+   (setq state (notmuch-show-capture-state)))
+(erase-buffer)
+(notmuch-show-worker)
+(if state
+   (notmuch-show-apply-state state
 
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 7/8] emacs: Add `notmuch-show-only-matching-messages'.

2012-02-06 Thread David Edmondson
Allow the user to choose that only matching messages are shown by
default.
---
 emacs/notmuch-show.el |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index ec36767..8c24f38 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -125,6 +125,11 @@ indentation.
 (const :tag View interactively
notmuch-show-interactively-view-part)))
 
+(defcustom notmuch-show-only-matching-messages nil
+  Only matching messages are shown by default.
+  :type 'boolean
+  :group 'notmuch-show)
+
 (defvar notmuch-show-thread-id nil)
 (make-variable-buffer-local 'notmuch-show-thread-id)
 (put 'notmuch-show-thread-id 'permanent-local t)
@@ -1028,6 +1033,9 @@ function is used.
 ;; Set the default value for `notmuch-show-process-crypto' in this
 ;; buffer.
 (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
+;; Set the default value for
+;; `notmuch-show-elide-non-matching-messages' in this buffer.
+(setq notmuch-show-elide-non-matching-messages 
notmuch-show-only-matching-messages)
 
 (setq notmuch-show-thread-id thread-id
  notmuch-show-parent-buffer parent-buffer
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v7 8/8] emacs: A prefix argument to `notmuch-show' should invert the matching message behaviour.

2012-02-06 Thread David Edmondson
Allow the user to open a thread with inverted
`notmuch-show-only-matching-messages' behaviour using a prefix
argument.
---
 emacs/notmuch-show.el |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 8c24f38..9c1d8fc 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1034,8 +1034,11 @@ function is used.
 ;; buffer.
 (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
 ;; Set the default value for
-;; `notmuch-show-elide-non-matching-messages' in this buffer.
+;; `notmuch-show-elide-non-matching-messages' in this buffer. If
+;; there is a prefix argument, invert the default.
 (setq notmuch-show-elide-non-matching-messages 
notmuch-show-only-matching-messages)
+(if current-prefix-arg
+   (setq notmuch-show-elide-non-matching-messages (not 
notmuch-show-elide-non-matching-messages)))
 
 (setq notmuch-show-thread-id thread-id
  notmuch-show-parent-buffer parent-buffer
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v6 3/3] NEWS: add news section for new.ignore

2012-02-06 Thread Tomi Ollila
Added NEWS section 'Mail store folder/file ignore'.
---
 NEWS |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 5c5b645..59da584 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,12 @@ Tag exclusion
 
 notmuch config set search.exclude_tags deleted spam
 
+Mail store folder/file ignore
+
+  New configuration option `new.ignore` is used to inform notmuch about
+  folders and files that are not mail files or contain material that is
+  not desired to be known by notmuch.
+
 Emacs Interface
 ---
 
-- 
1.7.6.5

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v6 2/3] add support for user-specified files directories to ignore

2012-02-06 Thread Tomi Ollila
A new configuration key 'new.ignore' is used to determine which
files and directories user wants not to be scanned as new mails.

Mark the corresponding test as no longer broken.

This work merges my previous attempts and Andreas Amann's work
in id:ylp7hi23mw8@tyndall.ie
---
 notmuch-client.h |9 +
 notmuch-config.c |   30 +-
 notmuch-new.c|   45 +
 test/new |1 -
 4 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..f1762ae 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 const char *new_tags[],
 size_t length);
 
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config,
+  size_t *length);
+
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *new_ignore[],
+  size_t length);
+
 notmuch_bool_t
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
 
diff --git a/notmuch-config.c b/notmuch-config.c
index a124e34..1f01128 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -44,7 +44,10 @@ static const char new_config_comment[] =
  The following options are supported here:\n
 \n
 \ttagsA list (separated by ';') of the tags that will be\n
-\tadded to all messages incorporated by \notmuch new\.\n;
+\tadded to all messages incorporated by \notmuch new\.\n
+\n
+\tignore  A list (separated by ';') of file and directory names\n
+\tthat will not be searched for messages by \notmuch new\.\n;
 
 static const char user_config_comment[] =
  User configuration\n
@@ -105,6 +108,8 @@ struct _notmuch_config {
 size_t user_other_email_length;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;
 notmuch_bool_t maildir_synchronize_flags;
 const char **search_exclude_tags;
 size_t search_exclude_tags_length;
@@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
 config-user_other_email_length = 0;
 config-new_tags = NULL;
 config-new_tags_length = 0;
+config-new_ignore = NULL;
+config-new_ignore_length = 0;
 config-maildir_synchronize_flags = TRUE;
 config-search_exclude_tags = NULL;
 config-search_exclude_tags_length = 0;
@@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
notmuch_config_set_new_tags (config, tags, 2);
 }
 
+if (notmuch_config_get_new_ignore (config, tmp) == NULL) {
+   notmuch_config_set_new_ignore (config, NULL, 0);
+}
+
 if (notmuch_config_get_search_exclude_tags (config, tmp) == NULL) {
if (is_new) {
const char *tags[] = { deleted, spam };
@@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   
size_t *length)
 (config-new_tags_length), length);
 }
 
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
+{
+return _config_get_list (config, new, ignore,
+(config-new_ignore),
+(config-new_ignore_length), length);
+}
+
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
 const char *list[],
@@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 (config-new_tags));
 }
 
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *list[],
+  size_t length)
+{
+_config_set_list (config, new, ignore, list, length,
+(config-new_ignore));
+}
+
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t 
*length)
 {
diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..8a615e6 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -39,6 +39,8 @@ typedef struct {
 int verbose;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;
 
 int total_files;
 int processed_files;
@@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int 
count)
 return 0;
 }
 
+/* Test if the file/directory is to be ignored.
+ */
+static notmuch_bool_t
+_entry_in_ignore_list (const char *entry, add_files_state_t *state)
+{
+size_t i;
+
+for (i = 0; i  state-new_ignore_length; i++)
+   if (strcmp (entry, state-new_ignore[i]) == 0)
+   return TRUE;
+
+return FALSE;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
}
 
/* Ignore special directories 

[PATCH v6 1/3] test: add tests wrt ignoring user-specified files and directories

2012-02-06 Thread Tomi Ollila
Files and directories which are specified in 'new.ignore' in the
config file shouldn't be indexed nor reported by `notmuch new'.

This is basically Pieter's work with Austin's comments addressed.
---
 test/new |   22 ++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/test/new b/test/new
index 49f390d..5ce8811 100755
--- a/test/new
+++ b/test/new
@@ -153,4 +153,26 @@ rm -rf ${MAIL_DIR}/two
 output=$(NOTMUCH_NEW)
 test_expect_equal $output No new mail. Removed 3 messages.
 
+# This test depends that notmuch new has been run at least once.
+test_begin_subtest Skip and report non-mail files
+generate_message
+mkdir -p ${MAIL_DIR}/.git  touch ${MAIL_DIR}/.git/config
+touch ${MAIL_DIR}/ignored_file
+touch ${MAIL_DIR}/.ignored_hidden_file
+output=$(NOTMUCH_NEW 21)
+test_expect_equal $output \
+Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
+Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
+Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
+Added 1 new message to the database.
+
+test_begin_subtest Ignore files and directories specified in new.ignore
+test_subtest_known_broken
+generate_message
+notmuch config set new.ignore .git ignored_file .ignored_hidden_file
+touch ${MAIL_DIR}/.git # change .git's mtime for notmuch new to rescan.
+output=$(NOTMUCH_NEW 21)
+test_expect_equal $output Added 1 new message to the database.
+
+
 test_done
-- 
1.7.6.5

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v6 2/3] add support for user-specified files directories to ignore

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 11:28:24 +0200, Tomi Ollila tomi.oll...@iki.fi wrote:
 A new configuration key 'new.ignore' is used to determine which
 files and directories user wants not to be scanned as new mails.
 
 Mark the corresponding test as no longer broken.
 
 This work merges my previous attempts and Andreas Amann's work
 in id:ylp7hi23mw8@tyndall.ie

I marked this patch with 'needs-review' for consistency with
the 2 other patches. No code changes to the previous version.

Tomi

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v7 0/8] reworked crypto toggle, plus a few other toggles

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 09:21:14 +, David Edmondson d...@dme.org wrote:
 v7:
 - Simple rebase.

The whole patch series applied cleanly (git am) on top of current origin/master
+ Dmitry's patchset 
id:1328426033-21480-2-git-send-email-dmitry.kuroch...@gmail.com

 David Edmondson (8):
   emacs: Rework crypto switch toggle.

I don't currently have any data (on this particular machine) to test 
crypto switch toggle. Rest of the patches (2-8) worked fine.

So, +1 for those. 

Tomi

   emacs: Allow `notmuch-show-mode' to display only matching messages.
   emacs: Allow the indentation of content to be toggled.
   emacs: Add a binding (t) to toggle the truncation of long lines.
   emacs: Optionally retain the state of the buffer during
 `notmuch-show-refresh-view'.
   emacs: Check that the parent buffer is alive before using it.
   emacs: Add `notmuch-show-only-matching-messages'.
   emacs: A prefix argument to `notmuch-show' should invert the matching
 message behaviour.
 
  emacs/notmuch-show.el |  224 
 ++---
  emacs/notmuch.el  |7 +-
  2 files changed, 158 insertions(+), 73 deletions(-)
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2] Wrap and indent headers in show mode

2012-02-06 Thread David Edmondson
v2:
- Simple rebase.

David Edmondson (1):
  emacs: Add more processing of displayed headers.

 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2] emacs: Add more processing of displayed headers.

2012-02-06 Thread David Edmondson
Wrap headers to the width of the window and indent continuations.
---
 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..a589d37 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -68,9 +68,16 @@ any given message.
   :type 'boolean
   :group 'notmuch-show)
 
-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
+(defcustom notmuch-show-markup-headers-hook '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
   A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.)
+`notmuch-message-headers'.
+  :type 'hook
+  :options '(notmuch-show-colour-headers
+notmuch-show-fill-headers
+notmuch-show-indent-continuations)
+  :group 'notmuch-show)
 
 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
   Functions called after populating a `notmuch-show' buffer.
@@ -269,13 +276,35 @@ operation on the contents of the current buffer.
 (overlay-put (make-overlay (point) (re-search-forward .*$))
 'face face)))
 
-(defun notmuch-show-colour-headers ()
+(defun notmuch-show-colour-headers (depth)
   Apply some colouring to the current headers.
   (goto-char (point-min))
   (while (looking-at ^[A-Za-z][-A-Za-z0-9]*:)
 (notmuch-show-fontify-header)
 (forward-line)))
 
+(defun notmuch-show-fill-headers (depth)
+  Wrap the text of the current headers.
+
+  ;; '-5' to allow for the indentation code.
+  (let ((fill-column (- (window-width) depth 5)))
+(goto-char (point-min))
+(while (not (eobp))
+  (let ((start (point)))
+   (end-of-line)
+   ;; We're left at the start of the next line, so there's no need
+   ;; to move forward after filling.
+   (fill-region-as-paragraph start (point))
+
+(defun notmuch-show-indent-continuations (depth)
+  Indent any continuation lines.
+  (goto-char (point-min))
+  (while (not (eobp))
+(if (not (looking-at ^[A-Za-z][-A-Za-z0-9]*:))
+   ;; Four spaces tends to work well with 'To' and 'Cc' headers.
+   (insert ))
+(forward-line)))
+
 (defun notmuch-show-spaces-n (n)
   Return a string comprised of `n' spaces.
   (make-string n ? ))
@@ -366,7 +395,7 @@ message at DEPTH in the current thread.
   Insert a single header.
   (insert header :  header-value \n))
 
-(defun notmuch-show-insert-headers (headers)
+(defun notmuch-show-insert-headers (headers depth)
   Insert the headers of the current message.
   (let ((start (point)))
 (mapc (lambda (header)
@@ -379,7 +408,7 @@ message at DEPTH in the current thread.
 (save-excursion
   (save-restriction
(narrow-to-region start (point-max))
-   (run-hooks 'notmuch-show-markup-headers-hook)
+   (run-hook-with-args 'notmuch-show-markup-headers-hook depth)
 
 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
@@ -671,7 +700,7 @@ current buffer, if possible.
 ;; Override `notmuch-message-headers' to force `From' to be
 ;; displayed.
 (let ((notmuch-message-headers '(From Subject To Cc Date)))
-  (notmuch-show-insert-headers (plist-get message :headers)))
+  (notmuch-show-insert-headers (plist-get message :headers) 0))
 
 ;; Blank line after headers to be compatible with the normal
 ;; message display.
@@ -864,7 +893,7 @@ current buffer, if possible.
 ;; Set `headers-start' to point after the 'Subject:' header to be
 ;; compatible with the existing implementation. This just sets it
 ;; to after the first header.
-(notmuch-show-insert-headers headers)
+(notmuch-show-insert-headers headers depth)
 (save-excursion
   (goto-char content-start)
   ;; If the subject of this message is the same as that of the
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/2] cli: convert notmuch show to use the new argument parser

2012-02-06 Thread Austin Clements
Quoth Jani Nikula on Feb 06 at  7:54 am:
 On Sun, 5 Feb 2012 23:12:05 -0500, Austin Clements amdra...@mit.edu wrote:
  Yikes.  I don't envy you this patch.  Two minor nits, otherwise this
  and the next patch LGTM.
 
 Thanks for the review. I'll roll another version, I think it will be
 better with your suggestions incorporated.
 
  Quoth Jani Nikula on Feb 04 at 12:41 am:
   Use the new notmuch argument parser to handle arguments in notmuch
   show. There are two corner case functional changes:
   
   1) Also set params.raw = 1 when defaulting to raw format when part is
  requested but format is not specified.
  
  Huh.  So notmuch show --part=0 query was broken before.
 
 Hmm, yes, it seems so. Do you think I should make this a separate fix?

I wouldn't bother.  Since this usage would throw --format=raw into
useless mode, clearly no one cared.  No sense throwing good code
after bad.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 0/3] part header code tidying and options

2012-02-06 Thread David Edmondson
v3:
- simple rebase.

The previous version of this had 'LGTM' for each of the three
parts. jrollins asked some questions, all of which were answered.

David Edmondson (3):
  emacs: Don't return the button from
`notmuch-show-insert-part-header'.
  emacs: Optionally hide some part headers.
  emacs: Don't insert a part header if it's the first part and text/*.

 emacs/notmuch-show.el |   84 +
 1 files changed, 50 insertions(+), 34 deletions(-)

-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2] emacs: Add more processing of displayed headers.

2012-02-06 Thread David Edmondson
Wrap headers to the width of the window and indent continuations.
---
 emacs/notmuch-show.el |   43 ---
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..a589d37 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -68,9 +68,16 @@ any given message.
   :type 'boolean
   :group 'notmuch-show)
 
-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
+(defcustom notmuch-show-markup-headers-hook '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
   A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.)
+`notmuch-message-headers'.
+  :type 'hook
+  :options '(notmuch-show-colour-headers
+notmuch-show-fill-headers
+notmuch-show-indent-continuations)
+  :group 'notmuch-show)
 
 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
   Functions called after populating a `notmuch-show' buffer.
@@ -269,13 +276,35 @@ operation on the contents of the current buffer.
 (overlay-put (make-overlay (point) (re-search-forward .*$))
 'face face)))
 
-(defun notmuch-show-colour-headers ()
+(defun notmuch-show-colour-headers (depth)
   Apply some colouring to the current headers.
   (goto-char (point-min))
   (while (looking-at ^[A-Za-z][-A-Za-z0-9]*:)
 (notmuch-show-fontify-header)
 (forward-line)))
 
+(defun notmuch-show-fill-headers (depth)
+  Wrap the text of the current headers.
+
+  ;; '-5' to allow for the indentation code.
+  (let ((fill-column (- (window-width) depth 5)))
+(goto-char (point-min))
+(while (not (eobp))
+  (let ((start (point)))
+   (end-of-line)
+   ;; We're left at the start of the next line, so there's no need
+   ;; to move forward after filling.
+   (fill-region-as-paragraph start (point))
+
+(defun notmuch-show-indent-continuations (depth)
+  Indent any continuation lines.
+  (goto-char (point-min))
+  (while (not (eobp))
+(if (not (looking-at ^[A-Za-z][-A-Za-z0-9]*:))
+   ;; Four spaces tends to work well with 'To' and 'Cc' headers.
+   (insert ))
+(forward-line)))
+
 (defun notmuch-show-spaces-n (n)
   Return a string comprised of `n' spaces.
   (make-string n ? ))
@@ -366,7 +395,7 @@ message at DEPTH in the current thread.
   Insert a single header.
   (insert header :  header-value \n))
 
-(defun notmuch-show-insert-headers (headers)
+(defun notmuch-show-insert-headers (headers depth)
   Insert the headers of the current message.
   (let ((start (point)))
 (mapc (lambda (header)
@@ -379,7 +408,7 @@ message at DEPTH in the current thread.
 (save-excursion
   (save-restriction
(narrow-to-region start (point-max))
-   (run-hooks 'notmuch-show-markup-headers-hook)
+   (run-hook-with-args 'notmuch-show-markup-headers-hook depth)
 
 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
@@ -671,7 +700,7 @@ current buffer, if possible.
 ;; Override `notmuch-message-headers' to force `From' to be
 ;; displayed.
 (let ((notmuch-message-headers '(From Subject To Cc Date)))
-  (notmuch-show-insert-headers (plist-get message :headers)))
+  (notmuch-show-insert-headers (plist-get message :headers) 0))
 
 ;; Blank line after headers to be compatible with the normal
 ;; message display.
@@ -864,7 +893,7 @@ current buffer, if possible.
 ;; Set `headers-start' to point after the 'Subject:' header to be
 ;; compatible with the existing implementation. This just sets it
 ;; to after the first header.
-(notmuch-show-insert-headers headers)
+(notmuch-show-insert-headers headers depth)
 (save-excursion
   (goto-char content-start)
   ;; If the subject of this message is the same as that of the
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 1/3] emacs: Don't return the button from `notmuch-show-insert-part-header'.

2012-02-06 Thread David Edmondson
Instead, allow the caller to specify some parameters for the
button. Rework `notmuch-show-insert-part-multipart/signed' and
`notmuch-show-insert-part-multipart/encrypted' accordingly.
---
 emacs/notmuch-show.el |   86 +---
 1 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..079d7cb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -397,25 +397,24 @@ message at DEPTH in the current thread.
   Submap for button commands)
 (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
 
-(defun notmuch-show-insert-part-header (nth content-type declared-type 
optional name comment)
-  (let ((button))
-(setq button
- (insert-button
-  (concat [ 
-  (if name (concat name : ) )
-  declared-type
-  (if (not (string-equal declared-type content-type))
-  (concat  (as  content-type ))
-)
-  (or comment )
-   ])
-  :type 'notmuch-show-part-button-type
-  :notmuch-part nth
-  :notmuch-filename name
-  :notmuch-content-type content-type))
-(insert \n)
-;; return button
-button))
+(defun notmuch-show-insert-part-header (nth content-type declared-type
+   optional name comment
+   rest button-parameters)
+  (apply #'insert-button
+(concat [ 
+(if name (concat name : ) )
+declared-type
+(if (not (string-equal declared-type content-type))
+(concat  (as  content-type ))
+  )
+(or comment )
+ ])
+:type 'notmuch-show-part-button-type
+:notmuch-part nth
+:notmuch-filename name
+:notmuch-content-type content-type
+button-parameters)
+  (insert \n))
 
 ;; Functions handling particular MIME parts.
 
@@ -602,15 +601,18 @@ current buffer, if possible.
   t)
 
 (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth 
depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type 
content-type nil)))
-(button-put button 'face 'notmuch-crypto-part-header)
-;; add signature status button if sigstatus provided
-(if (plist-member part :sigstatus)
-   (let* ((from (notmuch-show-get-header :From msg))
-  (sigstatus (car (plist-get part :sigstatus
- (notmuch-crypto-insert-sigstatus-button sigstatus from))
-  ;; if we're not adding sigstatus, tell the user how they can get it
-  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic mime parts.)))
+  ;; Add signature status button if sigstatus provided.
+  (if (plist-member part :sigstatus)
+  (let ((from (notmuch-show-get-header :From msg))
+   (sigstatus (car (plist-get part :sigstatus
+   (notmuch-show-insert-part-header nth declared-type content-type nil nil 
+'face 'notmuch-crypto-part-header)
+   (notmuch-crypto-insert-sigstatus-button sigstatus from))
+
+;; If we're not adding sigstatus, tell the user how to enable it.
+(notmuch-show-insert-part-header nth declared-type content-type nil nil 
+'face 'notmuch-crypto-part-header
+'help-echo Set 
notmuch-crypto-process-mime to process cryptographic mime parts.))
 
   (let ((inner-parts (plist-get part :content))
(start (point)))
@@ -624,19 +626,21 @@ current buffer, if possible.
   t)
 
 (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth 
depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type 
content-type nil)))
-(button-put button 'face 'notmuch-crypto-part-header)
-;; add encryption status button if encstatus specified
-(if (plist-member part :encstatus)
-   (let ((encstatus (car (plist-get part :encstatus
- (notmuch-crypto-insert-encstatus-button encstatus)
- ;; add signature status button if sigstatus specified
- (if (plist-member part :sigstatus)
- (let* ((from (notmuch-show-get-header :From msg))
-(sigstatus (car (plist-get part :sigstatus
-   (notmuch-crypto-insert-sigstatus-button sigstatus from
-  ;; if we're not adding encstatus, tell the user how they can get it
-  (button-put button 'help-echo Set notmuch-crypto-process-mime to 
process cryptographic mime parts.)))
+  ;; Add encryption status button if encstatus provided.
+  (if (plist-member part :encstatus)
+  (let ((encstatus (car (plist-get part :encstatus
+   (notmuch-show-insert-part-header nth declared-type content-type nil nil 
+ 

[PATCH v2 1/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
Except for where invisibility is involved, replace the use of overlays
in `notmuch-show-mode' with text properties, which are more efficient
and can be merged together more effectively.
---
 emacs/notmuch-show.el |   66 +++-
 emacs/notmuch-wash.el |8 -
 2 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..13d2e81 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -264,10 +264,10 @@ operation on the contents of the current buffer.
   (t
'message-header-other
 
-(overlay-put (make-overlay (point) (re-search-forward :))
-'face 'message-header-name)
-(overlay-put (make-overlay (point) (re-search-forward .*$))
-'face face)))
+(put-text-property (point) (re-search-forward :)
+  'face 'message-header-name)
+(put-text-property (point) (re-search-forward .*$)
+  'face face)))
 
 (defun notmuch-show-colour-headers ()
   Apply some colouring to the current headers.
@@ -284,12 +284,11 @@ operation on the contents of the current buffer.
   Update the displayed tags of the current message.
   (save-excursion
 (goto-char (notmuch-show-message-top))
-(if (re-search-forward (\\([^()]*\\))$ (line-end-position) t)
-   (let ((inhibit-read-only t))
- (replace-match (concat (
-(propertize (mapconcat 'identity tags  )
-'face 'notmuch-tag-face)
-)))
+(when (re-search-forward (\\([^()]*\\))$ (line-end-position) t)
+  (let ((inhibit-read-only t))
+   (replace-match (propertize (mapconcat 'identity tags  )
+  'face '(notmuch-tag-face 
notmuch-message-summary-face))
+  nil nil nil 1)
 
 (defun notmuch-show-clean-address (address)
   Try to clean a single email ADDRESS for display.  Return
@@ -352,15 +351,26 @@ unchanged ADDRESS if parsing fails.
   Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread.
   (let ((start (point)))
-(insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width 
depth))
-   (notmuch-show-clean-address (plist-get headers :From))
-(
-   date
-   ) (
-   (propertize (mapconcat 'identity tags  )
-   'face 'notmuch-tag-face)
-   )\n)
-(overlay-put (make-overlay start (point)) 'face 
'notmuch-message-summary-face)))
+(insert
+ (propertize (concat (notmuch-show-clean-address (plist-get headers :From))
+ (
+date
+) ()
+'face 'notmuch-message-summary-face)
+ (propertize (mapconcat 'identity tags  )
+'face '(notmuch-tag-face notmuch-message-summary-face))
+ (propertize )\n
+'face 'notmuch-message-summary-face))
+
+;; Ensure that any insertions at the start of this line (usually
+;; just spaces for indentation purposes) inherit the face of the
+;; rest of the line...
+(put-text-property start (1+ start)
+  'front-sticky '(face))
+;; ...and that insertions at the end of this region do _not_
+;; inherit the face of the rest of this line.
+(put-text-property (1- (point)) (point)
+  'rear-nonsticky '(face
 
 (defun notmuch-show-insert-header (header header-value)
   Insert a single header.
@@ -796,8 +806,15 @@ current buffer, if possible.
 (defun notmuch-show-insert-bodypart (msg part depth)
   Insert the body part PART at depth DEPTH in the current thread.
   (let ((content-type (downcase (plist-get part :content-type)))
-   (nth (plist-get part :id)))
-(notmuch-show-insert-bodypart-internal msg part content-type nth depth 
content-type))
+   (nth (plist-get part :id))
+   (start (point)))
+(notmuch-show-insert-bodypart-internal msg part content-type nth depth 
content-type)
+
+;; Ensure that face properties applied to text in the buffer by
+;; the part handler don't leak into the following text.
+(put-text-property start (point-max)
+  'rear-nonsticky '(face)))
+
   ;; Some of the body part handlers leave point somewhere up in the
   ;; part, so we make sure that we're down at the end.
   (goto-char (point-max))
@@ -888,11 +905,12 @@ current buffer, if possible.
 (setq body-end (point-marker))
 (setq content-end (point-marker))
 
-;; Indent according to the depth in the thread.
-(indent-rigidly content-start content-end (* 
notmuch-show-indent-messages-width depth))
-
 (setq message-end (point-max-marker))
 
+;; Indent according to the depth in the thread.
+(indent-rigidly message-start message-end
+   (* notmuch-show-indent-messages-width 

[PATCH v2 0/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
v2:
- simple rebase.

David Edmondson (2):
  emacs: Use text properties rather than overlays in
`notmuch-show-mode'.
  test: Update test to match previous patch.

 emacs/notmuch-show.el  |   66 ---
 emacs/notmuch-wash.el  |8 ++-
 ...hread-maildir-storage-with-fourfold-indentation |8 +-
 3 files changed, 52 insertions(+), 30 deletions(-)

-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 2/2] test: Update test to match previous patch.

2012-02-06 Thread David Edmondson
Indentation now uses tabs where possible.
---
 ...hread-maildir-storage-with-fourfold-indentation |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
 
b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
index b0bf93e..1f7801e 100644
--- 
a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
+++ 
b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation
@@ -69,7 +69,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
-Lars Kellogg-Stedman l...@seas.harvard.edu (2009-11-17) (inbox 
signed unread)
+   Lars Kellogg-Stedman l...@seas.harvard.edu (2009-11-17) (inbox signed 
unread)
Subject: Re: [notmuch] Working with Maildir storage?
To: Mikhail Gusarov dotted...@dottedmag.net
Cc: notmuch@notmuchmail.org
@@ -101,7 +101,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch
-Mikhail Gusarov dotted...@dottedmag.net (2009-11-17) (inbox 
unread)
+   Mikhail Gusarov dotted...@dottedmag.net (2009-11-17) (inbox 
unread)
Subject: [notmuch] Working with Maildir storage?
To: notmuch@notmuchmail.org
Date: Wed, 18 Nov 2009 02:50:48 +0600
@@ -129,7 +129,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
Desc: not available
URL:

http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp
-Keith Packard kei...@keithp.com (2009-11-17) (inbox unread)
+   Keith Packard kei...@keithp.com (2009-11-17) (inbox unread)
Subject: [notmuch] Working with Maildir storage?
To: notmuch@notmuchmail.org
Date: Tue, 17 Nov 2009 13:24:13 -0800
@@ -151,7 +151,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch
Thanks to everyone for trying out notmuch!
 
-keith
-Lars Kellogg-Stedman l...@seas.harvard.edu (2009-11-18) 
(inbox signed unread)
+   Lars Kellogg-Stedman l...@seas.harvard.edu (2009-11-18) 
(inbox signed unread)
Subject: Re: [notmuch] Working with Maildir storage?
To: Keith Packard kei...@keithp.com
Cc: notmuch@notmuchmail.org
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2 1/2] emacs: Use text properties rather than overlays in `notmuch-show-mode'.

2012-02-06 Thread David Edmondson
On Mon,  6 Feb 2012 16:08:21 +, David Edmondson d...@dme.org wrote:
 Except for where invisibility is involved, replace the use of overlays
 in `notmuch-show-mode' with text properties, which are more efficient
 and can be merged together more effectively.

Austin reviewed this (id:20120124161511.gc16...@mit.edu), but
suggested that someone else should look it over. Any volunteers?


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


Re: newbie questions

2012-02-06 Thread Jesse Rosenthal
On Mon, 06 Feb 2012 08:51:15 +0200, Tomi Ollila tomi.oll...@iki.fi wrote:
 On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp tkp...@gmail.com wrote:
  
  1. How can I restrict searches (eg of my inbox) to the last few
  messages (eg 50-100) or some date (eg last 2 weeks)?  I am using the
  Emacs interface.
 
 Currently, if you have GNU date you can run from command line:
 
 date +%s.. --date '2 weeks ago'
 
 Then paste the string 1327300096.. to the search field.

FWIW, I actually have a hacky date parser baked into my
remote-usage-and-other-stuff script (a more idiosyncratc python
version of the bash script on the wiki). I found that I needed
date-searching pretty frequently, since language and senders seem to be
repeated pretty often in my world. It just parses a date: term, passes
it to GNU date, and proceeds with a term in notmuch language. It also
does some day-rounding, since by date:'2 days ago'..yesterday, I mean
beginning of day before yesterday to end of yesterday, not 48 hours
ago until 24 hours ago.

I'm not swearing by its efficiency, or even its correctness, but it has
made my life easier. The basics are as follows:

DATE_PATTERN = re.compile(r'^date:([^.]+)(\.\.)?([^.]+)?')

def replace_date_args(st):
out = subprocess.check_output([GNU_DATE, +%s, -d, st])
return out.strip()

def round_day_down(timestamp):
tup = datetime.fromtimestamp(int(timestamp)).date().timetuple()
return time.mktime(tup)

def round_day_up(timestamp):
date = datetime.fromtimestamp(int(timestamp)).date()
date += timedelta(days=1)
tup = date.timetuple()
return time.mktime(tup)

def parse_date_args(st):
re_match = DATE_PATTERN.match(st)
if re_match:
grps = re_match.groups()
start_term = grps[0]
if not (grps[1] or grps[2]):
stop_term = start_term
elif not grps[2]:
stop_term = now
else:
stop_term = grps[2]

try:
start = round_day_down(replace_date_args(start_term))
stop = round_day_up(replace_date_args(stop_term))
return %d..%d % (start, stop)
except OSError:
return st
else:
return st

And then in the main routine, I have a parse-and-replace step:

args = sys.argv[1:]
try:
if args[-1] == )':
args = args[:-2] + shlex.split(sys.argv[-2]) + [)']
else:
args = args[:-1] + shlex.split(sys.argv[-1])
except IndexError, ValueError:
pass

args = [parse_date_args(a) for a in args] 

I'm only giving the relevant parts here, of course.

Best,
Jesse


___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Jameson Graef Rollins
On Mon, 06 Feb 2012 08:56:34 +, David Edmondson d...@dme.org wrote:
 With blank subjects the printing code generated an error (because
 `rename-buffer' doesn't like an empty string as the first argument), so
 _some_ change is required.

This sounds like something that could easily be fixed in the printing
code, without changing the show and search behavior.

jamie.


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


Installation on Mac OS X Lion

2012-02-06 Thread Saurabh Nanda

Hi,

I'm trying to install notmuchmail on my Mac box, but have (obviously) 
run into dependancy issues (Xapian, GMime, Glib, talloc). Has anyone 
managed to install notmuchmail on Mac OS X? How painful is it? Is it 
possible to have a binary package for this?


Thanks,
Saurabh.
--
http://www.saurabhnanda.com
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: newbie questions

2012-02-06 Thread albin stjerna
On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp tkp...@gmail.com wrote:
 Hi,

Hi Tamas, and (I suppose) welcome to the Notmuch mailing list!

 I just started using notmuch. It is fascinating, but I still need to
 figure out a few things:
 
 1. How can I restrict searches (eg of my inbox) to the last few
 messages (eg 50-100) or some date (eg last 2 weeks)? I am using the
 Emacs interface.

Well, the query syntax is start unix timestamp..end unix timestamp. I
know there's been talk on the list about some way to use it more easily
in the queries, and it wouldn't be hard to write a function that
generated a query using a more human-friendly notation of time. So far I
don't know about anyone actually having written such a function though,
but I wouldn't be surprised if someone has.

 2. Could someone point me to some guides on workflow with notmuch in
 Emacs? So far I have been using mutt, and I guess I need to rethink a
 few things.

Possibly. I've only used mutt briefly and a very long time ago, so I
don't really remember, but as you've probably already seen notmuch
relies very heavily on tags, as opposed to just about any other email
client out there (except Gmail, which I've found to be very similar). So
»inbox«, »archived«, »read« and so on isn't really »boxes« the way one
is used to, rather than separate labels you can set (and unset) on each
thread.

My workflow is something like this: first I fetch mail from IMAP using
offlineimap, then I run a script that tags incoming mail as personal,
list, notmuch, rss and so on (notmuch is also my RSS reader). I've set
the saved searches in Emacs to show fairly standard »tag:tag title AND
tag:inbox« searches for most of my tags. Then each morning, I begin by
processing »personal« from the top to the bottom, because the »personal«
tag is the one most likely to contain important and/or time-critical
mail (in effect it is the catch-all tag for all mail that isn't directed
to a mailing list or otherwise filtered out as probably uninteresting).

If you're interested, I can send you my mail tagging script.

When I'm done with each mail I archive it (using the standard keybinding
»a«). Most mails are handled more or less immediately, but some (in
particular posts from RSS) take longer time to read. Those I tag with
»read/review« using a custom keybinding »T«. I can then process those
when I have the time.

 3. If I have multiple accounts, how can I change my e-mail address
 (From:) when I am writing messages (within emacs, using the m key).

I'm mostly changing this by just typing my other email address (and
tab-completing it of course). I actually haven't thought about there
being any other way, but now that you mention it there probably is. :)

Hope this helps! Albin
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread David Edmondson
On Mon, 06 Feb 2012 11:19:46 -0800, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Mon, 06 Feb 2012 08:56:34 +, David Edmondson d...@dme.org wrote:
  With blank subjects the printing code generated an error (because
  `rename-buffer' doesn't like an empty string as the first argument), so
  _some_ change is required.
 
 This sounds like something that could easily be fixed in the printing
 code, without changing the show and search behavior.

Yes.


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


Re: Installation on Mac OS X Lion

2012-02-06 Thread Blake Sweeney

Quoting Saurabh Nanda (2012-02-05 03:27:38)
Hi,

I'm trying to install notmuchmail on my Mac box, but have (obviously) 
run into dependancy issues (Xapian, GMime, Glib, talloc). Has anyone 
managed to install notmuchmail on Mac OS X? How painful is it? Is it 
possible to have a binary package for this?

I have notmuch installed on os x though I'm on 10.5. I used homebrew
(http://mxcl.github.com/homebrew/) to install it orginally. It took care of all
the dependencies. There may be macports of fink packages, but I haven't checked.
I later upgraded to 10.2 by installing notmuch manually. I had some troubles
with the python bindings, but I think that was just because my glib was too old.
Installing a glib a newer 2.4.x glib fixed it.


Blake

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2 v2] emacs: Prefer '[No Subject]' to blank subjects.

2012-02-06 Thread Antoine Beaupré
On Sun, 05 Feb 2012 23:07:02 -0800, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 Sorry to be so late on this, but I'm not a big fan of this new feature.
 I would prefer to always see the subject (or any other field for that
 matter) as is.

I agree. as a native french speaker, for example, it's annoying having
to change those settings everywhere I got...

a.
-- 
To be naive and easily deceived is impermissible, today more than
ever, when the prevailing untruths may lead to a catastrophe because
they blind people to real dangers and real possibilities.
- Erich Fromm


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


[PATCH 0/3] notmuch show argument parsing

2012-02-06 Thread Jani Nikula
Hi all, 

v2 addressing Austin's comments in id:20120206041205.gp10...@mit.edu.
Separate the bool cleanup into a new patch, cleaning up notmuch reply
while at it. No functional changes since v1.

For reviewing convenience, the diff between v1 and v2 is at the end of
this cover letter.

BR,
Jani.

Jani Nikula (3):
  cli: use notmuch_bool_t for boolean fields in notmuch_show_params_t
  cli: convert notmuch show to use the new argument parser
  cli: reach previously unreachable cleanup code in notmuch show

 notmuch-client.h |6 +-
 notmuch-reply.c  |7 +--
 notmuch-show.c   |  155 +++---
 3 files changed, 84 insertions(+), 84 deletions(-)

-- 
1.7.5.4

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..60828aa 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -98,15 +98,15 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;
 
 typedef struct notmuch_show_params {
-int entire_thread;
-int raw;
+notmuch_bool_t entire_thread;
+notmuch_bool_t raw;
 int part;
 #ifdef GMIME_ATLEAST_26
 GMimeCryptoContext* cryptoctx;
 #else
 GMimeCipherContext* cryptoctx;
 #endif
-int decrypt;
+notmuch_bool_t decrypt;
 } notmuch_show_params_t;
 
 /* There's no point in continuing when we've detected that we've done
diff --git a/notmuch-reply.c b/notmuch-reply.c
index f55b1d2..6b244e6 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -661,7 +661,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_show_params_t params = { .part = -1 };
 int format = FORMAT_DEFAULT;
 int reply_all = TRUE;
-notmuch_bool_t decrypt = FALSE;
 
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, format, format, 'f',
@@ -672,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
  (notmuch_keyword_t []){ { all, TRUE },
  { sender, FALSE },
  { 0, 0 } } },
-   { NOTMUCH_OPT_BOOLEAN, decrypt, decrypt, 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.decrypt, decrypt, 'd', 0 },
{ 0, 0, 0, 0, 0 }
 };
 
@@ -687,7 +686,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 else
reply_format_func = notmuch_reply_format_default;
 
-if (decrypt) {
+if (params.decrypt) {
 #ifdef GMIME_ATLEAST_26
/* TODO: GMimePasswordRequestFunc */
params.cryptoctx = g_mime_gpg_context_new (NULL, gpg);
@@ -697,8 +696,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 #endif
if (params.cryptoctx) {
g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) 
params.cryptoctx, FALSE);
-   params.decrypt = TRUE;
} else {
+   params.decrypt = FALSE;
fprintf (stderr, Failed to construct gpg context.\n);
}
 #ifndef GMIME_ATLEAST_26
diff --git a/notmuch-show.c b/notmuch-show.c
index b18e279..c8fbd79 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1068,9 +1068,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 const notmuch_show_format_t *format = format_text;
 notmuch_show_params_t params = { .part = -1 };
 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
-notmuch_bool_t decrypt = FALSE;
 notmuch_bool_t verify = FALSE;
-notmuch_bool_t entire_thread = FALSE;
 
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, format_sel, format, 'f',
@@ -1080,8 +1078,8 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
  { raw, NOTMUCH_FORMAT_RAW },
  { 0, 0 } } },
{ NOTMUCH_OPT_INT, params.part, part, 'p', 0 },
-   { NOTMUCH_OPT_BOOLEAN, entire_thread, entire-thread, 't', 0 },
-   { NOTMUCH_OPT_BOOLEAN, decrypt, decrypt, 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.entire_thread, entire-thread, 't', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.decrypt, decrypt, 'd', 0 },
{ NOTMUCH_OPT_BOOLEAN, verify, verify, 'v', 0 },
{ 0, 0, 0, 0, 0 }
 };
@@ -1092,8 +1090,6 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
return 1;
 }
 
-params.entire_thread = entire_thread;
-
 if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
/* if part was requested and format was not specified, use format=raw */
if (params.part = 0)
@@ -1105,7 +1101,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 switch (format_sel) {
 case NOTMUCH_FORMAT_JSON:
format = format_json;
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
break;
 case NOTMUCH_FORMAT_TEXT:
format = format_text;
@@ -1123,11 +1119,11 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 * output single message, so set part=0 */
if (params.part  0)
params.part = 0;
-   

[PATCH v2 1/3] cli: use notmuch_bool_t for boolean fields in notmuch_show_params_t

2012-02-06 Thread Jani Nikula
Use notmuch_bool_t instead of int for entire_thread, raw, and decrypt
boolean fields in notmuch_show_params_t. No functional changes.

Signed-off-by: Jani Nikula j...@nikula.org
---
 notmuch-client.h |6 +++---
 notmuch-reply.c  |7 +++
 notmuch-show.c   |   14 +++---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..60828aa 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -98,15 +98,15 @@ typedef struct notmuch_show_format {
 } notmuch_show_format_t;
 
 typedef struct notmuch_show_params {
-int entire_thread;
-int raw;
+notmuch_bool_t entire_thread;
+notmuch_bool_t raw;
 int part;
 #ifdef GMIME_ATLEAST_26
 GMimeCryptoContext* cryptoctx;
 #else
 GMimeCipherContext* cryptoctx;
 #endif
-int decrypt;
+notmuch_bool_t decrypt;
 } notmuch_show_params_t;
 
 /* There's no point in continuing when we've detected that we've done
diff --git a/notmuch-reply.c b/notmuch-reply.c
index f55b1d2..6b244e6 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -661,7 +661,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_show_params_t params = { .part = -1 };
 int format = FORMAT_DEFAULT;
 int reply_all = TRUE;
-notmuch_bool_t decrypt = FALSE;
 
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, format, format, 'f',
@@ -672,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
  (notmuch_keyword_t []){ { all, TRUE },
  { sender, FALSE },
  { 0, 0 } } },
-   { NOTMUCH_OPT_BOOLEAN, decrypt, decrypt, 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.decrypt, decrypt, 'd', 0 },
{ 0, 0, 0, 0, 0 }
 };
 
@@ -687,7 +686,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 else
reply_format_func = notmuch_reply_format_default;
 
-if (decrypt) {
+if (params.decrypt) {
 #ifdef GMIME_ATLEAST_26
/* TODO: GMimePasswordRequestFunc */
params.cryptoctx = g_mime_gpg_context_new (NULL, gpg);
@@ -697,8 +696,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 #endif
if (params.cryptoctx) {
g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) 
params.cryptoctx, FALSE);
-   params.decrypt = TRUE;
} else {
+   params.decrypt = FALSE;
fprintf (stderr, Failed to construct gpg context.\n);
}
 #ifndef GMIME_ATLEAST_26
diff --git a/notmuch-show.c b/notmuch-show.c
index dec799c..e04b3cc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1063,11 +1063,11 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 int format_specified = 0;
 int i;
 
-params.entire_thread = 0;
-params.raw = 0;
+params.entire_thread = FALSE;
+params.raw = FALSE;
 params.part = -1;
 params.cryptoctx = NULL;
-params.decrypt = 0;
+params.decrypt = FALSE;
 
 argc--; argv++; /* skip subcommand argument */
 
@@ -1082,13 +1082,13 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
format = format_text;
} else if (strcmp (opt, json) == 0) {
format = format_json;
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
} else if (strcmp (opt, mbox) == 0) {
format = format_mbox;
mbox = 1;
} else if (strcmp (opt, raw) == 0) {
format = format_raw;
-   params.raw = 1;
+   params.raw = TRUE;
} else {
fprintf (stderr, Invalid value for --format: %s\n, opt);
return 1;
@@ -1097,7 +1097,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
} else if (STRNCMP_LITERAL (argv[i], --part=) == 0) {
params.part = atoi(argv[i] + sizeof (--part=) - 1);
} else if (STRNCMP_LITERAL (argv[i], --entire-thread) == 0) {
-   params.entire_thread = 1;
+   params.entire_thread = TRUE;
} else if ((STRNCMP_LITERAL (argv[i], --verify) == 0) ||
   (STRNCMP_LITERAL (argv[i], --decrypt) == 0)) {
if (params.cryptoctx == NULL) {
@@ -1117,7 +1117,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 #endif
}
if (STRNCMP_LITERAL (argv[i], --decrypt) == 0)
-   params.decrypt = 1;
+   params.decrypt = TRUE;
} else {
fprintf (stderr, Unrecognized option: %s\n, argv[i]);
return 1;
-- 
1.7.5.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 2/3] cli: convert notmuch show to use the new argument parser

2012-02-06 Thread Jani Nikula
Use the new notmuch argument parser to handle arguments in notmuch
show. There are three minor functional changes:

1) Also set params.raw = TRUE when defaulting to raw format when part
   is requested but format is not specified. This was a bug, and
   --part=0 without --format=raw did not work previously.

2) Set params.decrypt = FALSE if crypto context creation fails.

3) Only use the parameters for the last --format if specified multiple
   times. Previously this could have resulted in a non-working mixture
   of parameters.

Signed-off-by: Jani Nikula j...@nikula.org
---
 notmuch-show.c |  149 
 1 files changed, 75 insertions(+), 74 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index e04b3cc..b358278 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1049,6 +1049,14 @@ do_show (void *ctx,
 return 0;
 }
 
+enum {
+NOTMUCH_FORMAT_NOT_SPECIFIED,
+NOTMUCH_FORMAT_JSON,
+NOTMUCH_FORMAT_TEXT,
+NOTMUCH_FORMAT_MBOX,
+NOTMUCH_FORMAT_RAW
+};
+
 int
 notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
 {
@@ -1056,92 +1064,94 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 notmuch_database_t *notmuch;
 notmuch_query_t *query;
 char *query_string;
-char *opt;
+int opt_index;
 const notmuch_show_format_t *format = format_text;
-notmuch_show_params_t params;
-int mbox = 0;
-int format_specified = 0;
-int i;
+notmuch_show_params_t params = { .part = -1 };
+int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
+notmuch_bool_t verify = FALSE;
+
+notmuch_opt_desc_t options[] = {
+   { NOTMUCH_OPT_KEYWORD, format_sel, format, 'f',
+ (notmuch_keyword_t []){ { json, NOTMUCH_FORMAT_JSON },
+ { text, NOTMUCH_FORMAT_TEXT },
+ { mbox, NOTMUCH_FORMAT_MBOX },
+ { raw, NOTMUCH_FORMAT_RAW },
+ { 0, 0 } } },
+   { NOTMUCH_OPT_INT, params.part, part, 'p', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.entire_thread, entire-thread, 't', 0 },
+   { NOTMUCH_OPT_BOOLEAN, params.decrypt, decrypt, 'd', 0 },
+   { NOTMUCH_OPT_BOOLEAN, verify, verify, 'v', 0 },
+   { 0, 0, 0, 0, 0 }
+};
 
-params.entire_thread = FALSE;
-params.raw = FALSE;
-params.part = -1;
-params.cryptoctx = NULL;
-params.decrypt = FALSE;
+opt_index = parse_arguments (argc, argv, options, 1);
+if (opt_index  0) {
+   /* diagnostics already printed */
+   return 1;
+}
 
-argc--; argv++; /* skip subcommand argument */
+if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
+   /* if part was requested and format was not specified, use format=raw */
+   if (params.part = 0)
+   format_sel = NOTMUCH_FORMAT_RAW;
+   else
+   format_sel = NOTMUCH_FORMAT_TEXT;
+}
 
-for (i = 0; i  argc  argv[i][0] == '-'; i++) {
-   if (strcmp (argv[i], --) == 0) {
-   i++;
-   break;
+switch (format_sel) {
+case NOTMUCH_FORMAT_JSON:
+   format = format_json;
+   params.entire_thread = TRUE;
+   break;
+case NOTMUCH_FORMAT_TEXT:
+   format = format_text;
+   break;
+case NOTMUCH_FORMAT_MBOX:
+   if (params.part  0) {
+   fprintf (stderr, Error: specifying parts is incompatible with mbox 
output format.\n);
+   return 1;
}
-   if (STRNCMP_LITERAL (argv[i], --format=) == 0) {
-   opt = argv[i] + sizeof (--format=) - 1;
-   if (strcmp (opt, text) == 0) {
-   format = format_text;
-   } else if (strcmp (opt, json) == 0) {
-   format = format_json;
-   params.entire_thread = TRUE;
-   } else if (strcmp (opt, mbox) == 0) {
-   format = format_mbox;
-   mbox = 1;
-   } else if (strcmp (opt, raw) == 0) {
-   format = format_raw;
-   params.raw = TRUE;
-   } else {
-   fprintf (stderr, Invalid value for --format: %s\n, opt);
-   return 1;
-   }
-   format_specified = 1;
-   } else if (STRNCMP_LITERAL (argv[i], --part=) == 0) {
-   params.part = atoi(argv[i] + sizeof (--part=) - 1);
-   } else if (STRNCMP_LITERAL (argv[i], --entire-thread) == 0) {
-   params.entire_thread = TRUE;
-   } else if ((STRNCMP_LITERAL (argv[i], --verify) == 0) ||
-  (STRNCMP_LITERAL (argv[i], --decrypt) == 0)) {
-   if (params.cryptoctx == NULL) {
+   format = format_mbox;
+   break;
+case NOTMUCH_FORMAT_RAW:
+   format = format_raw;
+   /* If --format=raw specified without specifying part, we can only
+* output single message, so set part=0 */
+   if (params.part  0)
+   params.part = 0;
+   params.raw = TRUE;
+   break;
+}
+
+if 

[PATCH v2 3/3] cli: reach previously unreachable cleanup code in notmuch show

2012-02-06 Thread Jani Nikula
The last lines of notmuch_show_command() function were
unreachable. Fix it by using a variable for return value.

Signed-off-by: Jani Nikula j...@nikula.org
---
 notmuch-show.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index b358278..c8fbd79 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1064,7 +1064,7 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 notmuch_database_t *notmuch;
 notmuch_query_t *query;
 char *query_string;
-int opt_index;
+int opt_index, ret;
 const notmuch_show_format_t *format = format_text;
 notmuch_show_params_t params = { .part = -1 };
 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
@@ -1169,9 +1169,9 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 }
 
 if (params.part = 0)
-   return do_show_single (ctx, query, format, params);
+   ret = do_show_single (ctx, query, format, params);
 else
-   return do_show (ctx, query, format, params);
+   ret = do_show (ctx, query, format, params);
 
 notmuch_query_destroy (query);
 notmuch_database_close (notmuch);
@@ -1179,5 +1179,5 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 if (params.cryptoctx)
g_object_unref(params.cryptoctx);
 
-return 0;
+return ret;
 }
-- 
1.7.5.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 0/3] notmuch show argument parsing

2012-02-06 Thread Austin Clements
Quoth Jani Nikula on Feb 06 at  9:57 pm:
 Hi all, 
 
 v2 addressing Austin's comments in id:20120206041205.gp10...@mit.edu.
 Separate the bool cleanup into a new patch, cleaning up notmuch reply
 while at it. No functional changes since v1.

LGTM.

(Heads up: I never received patch 1/3, though I found it in the online
archive, so it may have been a local problem.)
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Leave blank subjects alone by default.

2012-02-06 Thread David Edmondson
Add `notmuch-blank-subject' to control how empty or whitespace only
subjects are treated. The default behaviour is to leave them
alone. The user can choose a string to use as a replacement.

Modify code that cannot handle blank subjects to use a fixed string.
---
 emacs/notmuch-lib.el   |   20 +---
 emacs/notmuch-print.el |4 ++--
 emacs/notmuch-show.el  |2 +-
 emacs/notmuch.el   |4 ++--
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index d315f76..2edc868 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -67,6 +67,13 @@
   :type 'boolean
   :group 'notmuch-search)
 
+(defcustom notmuch-blank-subject nil
+  How should subjects that are empty or whitespace only be
+treated?
+  :type '(choice (const :tag Leave them alone nil)
+(string :tag Replacement string [No Subject]))
+  :group 'notmuch)
+
 ;;
 
 (defvar notmuch-search-history nil
@@ -133,13 +140,20 @@ the user hasn't set this variable with the old or new 
value.
   (interactive)
   (kill-buffer (current-buffer)))
 
-(defun notmuch-prettify-subject (subject)
+(defun notmuch-pretty-non-empty-subject (subject)
+  (let ((subject (notmuch-pretty-subject subject)))
+(if (string-match ^[ \t]*$ subject)
+   no subject
+  subject)))
+
+(defun notmuch-pretty-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
   (save-match-data
-(if (and subject
+(if (and (stringp notmuch-blank-subject)
+subject
 (string-match ^[ \t]*$ subject))
-   [No Subject]
+   notmuch-blank-subject
   subject)))
 
 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6653d97..dda082a 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -60,7 +60,7 @@ Optional OUTPUT allows passing a list of flags to muttprint.
 
 (defun notmuch-print-ps-print (msg)
   Print a message buffer using the ps-print package.
-  (let ((subject (notmuch-prettify-subject
+  (let ((subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer)))
@@ -68,7 +68,7 @@ Optional OUTPUT allows passing a list of flags to muttprint.
 (defun notmuch-print-ps-print/evince (msg)
   Preview a message buffer using ps-print and evince.
   (let ((ps-file (make-temp-file notmuch))
-   (subject (notmuch-prettify-subject
+   (subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer ps-file)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4a23cc2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1261,7 +1261,7 @@ Some useful entries are:
   (notmuch-show-get-prop :depth))
 
 (defun notmuch-show-get-pretty-subject ()
-  (notmuch-prettify-subject (notmuch-show-get-subject)))
+  (notmuch-pretty-subject (notmuch-show-get-subject)))
 
 (defun notmuch-show-set-tags (tags)
   Set the tags of the current message.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index cd04ffd..aab6946 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -467,7 +467,7 @@ Complete list of currently available key bindings:
   Display the currently selected thread.
   (interactive P)
   (let ((thread-id (notmuch-search-find-thread-id))
-   (subject (notmuch-prettify-subject (notmuch-search-find-subject
+   (subject (notmuch-pretty-non-empty-subject 
(notmuch-search-find-subject
 (if ( (length thread-id) 0)
(notmuch-show thread-id
  (current-buffer)
@@ -850,7 +850,7 @@ non-authors is found, assume that all of the authors match.
  (insert (concat Error: Unexpected output from 
notmuch search:\n (substring string line (match-beginning 1)) \n)))
  (let ((beg (point)))
(notmuch-search-show-result date count authors
-   (notmuch-prettify-subject 
subject) tags)
+   (notmuch-pretty-subject 
subject) tags)
(notmuch-search-color-line beg (point) tag-list)
(put-text-property beg (point) 
'notmuch-search-thread-id thread-id)
(put-text-property beg (point) 'notmuch-search-authors 
authors)
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] Free the results of scandir()

2012-02-06 Thread Ethan Glasser-Camp
From: Ethan Glasser-Camp et...@betacantrips.com

scandir() returns strings allocated via malloc(3) which are then
collected in array namelist which is allocated via
malloc(3). Currently we just free the array namelist. Instead, free
all the entries of namelist, and then free namelist.

entry only points to elements of namelist, so we don't free it
separately.
---

This should fix a minor memory leak in notmuch-new. Please confirm I'm
reading the manpage correctly ;)

 notmuch-new.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..c536873 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch,
   DONE:
 if (next)
talloc_free (next);
-if (entry)
-   free (entry);
 if (dir)
closedir (dir);
-if (fs_entries)
+if (fs_entries){
+   for (i = 0; i  num_fs_entries; i++){
+   free (fs_entries[i]);
+   }
free (fs_entries);
+}
 if (db_subdirs)
notmuch_filenames_destroy (db_subdirs);
 if (db_files)
-- 
1.7.5.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] Free the results of scandir()

2012-02-06 Thread Jani Nikula
On Mon,  6 Feb 2012 17:02:49 -0500, Ethan Glasser-Camp gla...@cs.rpi.edu 
wrote:
 From: Ethan Glasser-Camp et...@betacantrips.com
 
 scandir() returns strings allocated via malloc(3) which are then
 collected in array namelist which is allocated via
 malloc(3). Currently we just free the array namelist. Instead, free
 all the entries of namelist, and then free namelist.
 
 entry only points to elements of namelist, so we don't free it
 separately.
 ---
 
 This should fix a minor memory leak in notmuch-new. Please confirm I'm
 reading the manpage correctly ;)

It looks right, good catch! Please do also fix the other scandir() usage
in count_files().

BR,
Jani.


 
  notmuch-new.c |8 +---
  1 files changed, 5 insertions(+), 3 deletions(-)
 
 diff --git a/notmuch-new.c b/notmuch-new.c
 index a569a54..c536873 100644
 --- a/notmuch-new.c
 +++ b/notmuch-new.c
 @@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch,
DONE:
  if (next)
   talloc_free (next);
 -if (entry)
 - free (entry);
  if (dir)
   closedir (dir);
 -if (fs_entries)
 +if (fs_entries){
 + for (i = 0; i  num_fs_entries; i++){
 + free (fs_entries[i]);
 + }
   free (fs_entries);
 +}
  if (db_subdirs)
   notmuch_filenames_destroy (db_subdirs);
  if (db_files)
 -- 
 1.7.5.4
 
 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2] emacs: Leave blank subjects alone by default.

2012-02-06 Thread David Edmondson
Add `notmuch-blank-subject' to control how empty or whitespace only
subjects are treated. The default behaviour is to leave them
alone. The user can choose a string to use as a replacement.

Modify code that cannot handle blank subjects to use a fixed string.
---

Fix the non-string subject case (again, sigh).

 emacs/notmuch-lib.el   |   21 ++---
 emacs/notmuch-print.el |4 ++--
 emacs/notmuch-show.el  |2 +-
 emacs/notmuch.el   |4 ++--
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index d315f76..95e3c29 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -67,6 +67,13 @@
   :type 'boolean
   :group 'notmuch-search)
 
+(defcustom notmuch-blank-subject nil
+  How should subjects that are empty or whitespace only be
+treated?
+  :type '(choice (const :tag Leave them alone nil)
+(string :tag Replacement string [No Subject]))
+  :group 'notmuch)
+
 ;;
 
 (defvar notmuch-search-history nil
@@ -133,13 +140,21 @@ the user hasn't set this variable with the old or new 
value.
   (interactive)
   (kill-buffer (current-buffer)))
 
-(defun notmuch-prettify-subject (subject)
+(defun notmuch-pretty-non-empty-subject (subject)
+  (let ((subject (notmuch-pretty-subject subject)))
+(if (and subject
+(string-match ^[ \t]*$ subject))
+   no subject
+  subject)))
+
+(defun notmuch-pretty-subject (subject)
   ;; This function is used by `notmuch-search-process-filter' which
   ;; requires that we not disrupt its' matching state.
   (save-match-data
-(if (and subject
+(if (and (stringp notmuch-blank-subject)
+subject
 (string-match ^[ \t]*$ subject))
-   [No Subject]
+   notmuch-blank-subject
   subject)))
 
 ;;
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
index 6653d97..dda082a 100644
--- a/emacs/notmuch-print.el
+++ b/emacs/notmuch-print.el
@@ -60,7 +60,7 @@ Optional OUTPUT allows passing a list of flags to muttprint.
 
 (defun notmuch-print-ps-print (msg)
   Print a message buffer using the ps-print package.
-  (let ((subject (notmuch-prettify-subject
+  (let ((subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer)))
@@ -68,7 +68,7 @@ Optional OUTPUT allows passing a list of flags to muttprint.
 (defun notmuch-print-ps-print/evince (msg)
   Preview a message buffer using ps-print and evince.
   (let ((ps-file (make-temp-file notmuch))
-   (subject (notmuch-prettify-subject
+   (subject (notmuch-pretty-non-empty-subject
  (plist-get (notmuch-show-get-prop :headers msg) :Subject
 (rename-buffer subject t)
 (ps-print-buffer ps-file)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..4a23cc2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1261,7 +1261,7 @@ Some useful entries are:
   (notmuch-show-get-prop :depth))
 
 (defun notmuch-show-get-pretty-subject ()
-  (notmuch-prettify-subject (notmuch-show-get-subject)))
+  (notmuch-pretty-subject (notmuch-show-get-subject)))
 
 (defun notmuch-show-set-tags (tags)
   Set the tags of the current message.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index cd04ffd..aab6946 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -467,7 +467,7 @@ Complete list of currently available key bindings:
   Display the currently selected thread.
   (interactive P)
   (let ((thread-id (notmuch-search-find-thread-id))
-   (subject (notmuch-prettify-subject (notmuch-search-find-subject
+   (subject (notmuch-pretty-non-empty-subject 
(notmuch-search-find-subject
 (if ( (length thread-id) 0)
(notmuch-show thread-id
  (current-buffer)
@@ -850,7 +850,7 @@ non-authors is found, assume that all of the authors match.
  (insert (concat Error: Unexpected output from 
notmuch search:\n (substring string line (match-beginning 1)) \n)))
  (let ((beg (point)))
(notmuch-search-show-result date count authors
-   (notmuch-prettify-subject 
subject) tags)
+   (notmuch-pretty-subject 
subject) tags)
(notmuch-search-color-line beg (point) tag-list)
(put-text-property beg (point) 
'notmuch-search-thread-id thread-id)
(put-text-property beg (point) 'notmuch-search-authors 
authors)
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch