* [PATCH v5 1/5] cli: command line parsing: allow default for keyword options
2012-05-26 15:54 [PATCH v5 0/5] Allow JSON to use non-entire thread, and use for elide Mark Walters
@ 2012-05-26 15:54 ` Mark Walters
2012-05-27 2:32 ` Peter Wang
2012-05-26 15:54 ` [PATCH v5 2/5] cli: Let json output "null" messages for non --entire-thread Mark Walters
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Mark Walters @ 2012-05-26 15:54 UTC (permalink / raw)
To: notmuch
This changes the parsing for "keyword" options so that if the option
is specified with no argument the first possible argument is
chosen. This make it easier to add options to existing boolean
arguments (the existing --option can default to TRUE).
---
command-line-arguments.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/command-line-arguments.c b/command-line-arguments.c
index 76b185f..d40c7e6 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -11,10 +11,16 @@
*/
static notmuch_bool_t
-_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {
+_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
const notmuch_keyword_t *keywords = arg_desc->keywords;
+ if (next == 0) {
+/* No keyword given so return first option as default */
+ *((int *)arg_desc->output_var) = keywords->value;
+ return TRUE;
+ }
+
while (keywords->name) {
if (strcmp (arg_str, keywords->name) == 0) {
if (arg_desc->output_var) {
@@ -99,7 +105,8 @@ parse_option (const char *arg,
*/
if (next != '=' && next != ':' && next != 0) return FALSE;
if (next == 0) {
- if (try->opt_type != NOTMUCH_OPT_BOOLEAN)
+ if (try->opt_type != NOTMUCH_OPT_BOOLEAN &&
+ try->opt_type != NOTMUCH_OPT_KEYWORD)
return FALSE;
} else {
if (value[0] == 0) return FALSE;
@@ -110,7 +117,7 @@ parse_option (const char *arg,
switch (try->opt_type) {
case NOTMUCH_OPT_KEYWORD:
- return _process_keyword_arg (try, value);
+ return _process_keyword_arg (try, next, value);
break;
case NOTMUCH_OPT_BOOLEAN:
return _process_boolean_arg (try, next, value);
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v5 1/5] cli: command line parsing: allow default for keyword options
2012-05-26 15:54 ` [PATCH v5 1/5] cli: command line parsing: allow default for keyword options Mark Walters
@ 2012-05-27 2:32 ` Peter Wang
0 siblings, 0 replies; 7+ messages in thread
From: Peter Wang @ 2012-05-27 2:32 UTC (permalink / raw)
To: notmuch
On Sat, 26 May 2012 16:54:50 +0100, Mark Walters <markwalters1009@gmail.com> wrote:
> This changes the parsing for "keyword" options so that if the option
> is specified with no argument the first possible argument is
> chosen. This make it easier to add options to existing boolean
> arguments (the existing --option can default to TRUE).
This has the side-effect of allowing defaults for all keyword options,
right? I'm not sure that's desirable when the default is non-obvious.
Maybe keyword options which allow an optional argument should have an
explicit entry in the notmuch_keyword_t[] array, e.g. under "" or "default".
> diff --git a/command-line-arguments.c b/command-line-arguments.c
> index 76b185f..d40c7e6 100644
> --- a/command-line-arguments.c
> +++ b/command-line-arguments.c
> @@ -11,10 +11,16 @@
> */
>
> static notmuch_bool_t
> -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {
> +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
>
> const notmuch_keyword_t *keywords = arg_desc->keywords;
>
> + if (next == 0) {
> +/* No keyword given so return first option as default */
> + *((int *)arg_desc->output_var) = keywords->value;
> + return TRUE;
> + }
Indentation.
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v5 2/5] cli: Let json output "null" messages for non --entire-thread
2012-05-26 15:54 [PATCH v5 0/5] Allow JSON to use non-entire thread, and use for elide Mark Walters
2012-05-26 15:54 ` [PATCH v5 1/5] cli: command line parsing: allow default for keyword options Mark Walters
@ 2012-05-26 15:54 ` Mark Walters
2012-05-26 15:54 ` [PATCH v5 3/5] cli: make --entire-thread=false work for format=json Mark Walters
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Mark Walters @ 2012-05-26 15:54 UTC (permalink / raw)
To: notmuch
All formats except Json can output empty messages for non
entire-thread, but in Json format we output "null" to keep the other
elements (e.g. the replies to the omitted message) in the correct
place.
---
notmuch-client.h | 1 +
notmuch-show.c | 20 ++++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/notmuch-client.h b/notmuch-client.h
index 19b7f01..08540a7 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -72,6 +72,7 @@ typedef struct notmuch_show_format {
const struct notmuch_show_params *params);
const char *message_set_sep;
const char *message_set_end;
+ const char *null_message;
} notmuch_show_format_t;
typedef struct notmuch_show_params {
diff --git a/notmuch-show.c b/notmuch-show.c
index 95427d4..97da5cc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -37,7 +37,8 @@ static const notmuch_show_format_t format_json = {
.message_set_start = "[",
.part = format_part_json_entry,
.message_set_sep = ", ",
- .message_set_end = "]"
+ .message_set_end = "]",
+ .null_message = "null"
};
static notmuch_status_t
@@ -800,6 +801,15 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
}
static notmuch_status_t
+show_null_message (const notmuch_show_format_t *format)
+{
+ /* Output a null message. Currently empty for all formats except Json */
+ if (format->null_message)
+ printf ("%s", format->null_message);
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+static notmuch_status_t
show_message (void *ctx,
const notmuch_show_format_t *format,
notmuch_message_t *message,
@@ -862,11 +872,13 @@ show_messages (void *ctx,
if (status && !res)
res = status;
next_indent = indent + 1;
-
- if (!status && format->message_set_sep)
- fputs (format->message_set_sep, stdout);
+ } else {
+ status = show_null_message (format);
}
+ if (!status && format->message_set_sep)
+ fputs (format->message_set_sep, stdout);
+
status = show_messages (ctx,
format,
notmuch_message_get_replies (message),
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 3/5] cli: make --entire-thread=false work for format=json.
2012-05-26 15:54 [PATCH v5 0/5] Allow JSON to use non-entire thread, and use for elide Mark Walters
2012-05-26 15:54 ` [PATCH v5 1/5] cli: command line parsing: allow default for keyword options Mark Walters
2012-05-26 15:54 ` [PATCH v5 2/5] cli: Let json output "null" messages for non --entire-thread Mark Walters
@ 2012-05-26 15:54 ` Mark Walters
2012-05-26 15:54 ` [PATCH v5 4/5] Update devel/schemata for --entire-thread=false Mark Walters
2012-05-26 15:54 ` [PATCH v5 5/5] emacs: make elide messages use notmuch-show for omitting messages Mark Walters
4 siblings, 0 replies; 7+ messages in thread
From: Mark Walters @ 2012-05-26 15:54 UTC (permalink / raw)
To: notmuch
The --entire-thread option in notmuch-show.c defaults to true when
format=json. Previously there was no way to turn this off. This patch
makes it respect --entire-thread=false.
To do this the patch moves the --entire-thread option to be a keyword
option using the new command line parsing to allow the existing
--entire-thread syntax to keep working.
---
notmuch-show.c | 25 +++++++++++++++++++++++--
1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/notmuch-show.c b/notmuch-show.c
index 97da5cc..207093a 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -981,6 +981,12 @@ enum {
NOTMUCH_FORMAT_RAW
};
+enum {
+ ENTIRE_THREAD_DEFAULT,
+ ENTIRE_THREAD_TRUE,
+ ENTIRE_THREAD_FALSE,
+};
+
/* The following is to allow future options to be added more easily */
enum {
EXCLUDE_TRUE,
@@ -1000,6 +1006,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
notmuch_bool_t verify = FALSE;
int exclude = EXCLUDE_TRUE;
+ int entire_thread = ENTIRE_THREAD_DEFAULT;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
@@ -1012,8 +1019,11 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
(notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
{ "false", EXCLUDE_FALSE },
{ 0, 0 } } },
+ { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't',
+ (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE },
+ { "false", ENTIRE_THREAD_FALSE },
+ { 0, 0 } } },
{ NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 },
- { NOTMUCH_OPT_BOOLEAN, ¶ms.entire_thread, "entire-thread", 't', 0 },
{ NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 },
{ NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },
{ 0, 0, 0, 0, 0 }
@@ -1036,7 +1046,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
switch (format_sel) {
case NOTMUCH_FORMAT_JSON:
format = &format_json;
- params.entire_thread = TRUE;
+ /* JSON defaults to entire-thread TRUE */
+ if (entire_thread == ENTIRE_THREAD_DEFAULT)
+ entire_thread = ENTIRE_THREAD_TRUE;
break;
case NOTMUCH_FORMAT_TEXT:
format = &format_text;
@@ -1058,6 +1070,15 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
params.raw = TRUE;
break;
}
+ /* Default is entire-thread = FALSE except for format=json which
+ * is dealt with above. */
+ if (entire_thread == ENTIRE_THREAD_DEFAULT)
+ entire_thread = ENTIRE_THREAD_FALSE;
+
+ if (entire_thread == ENTIRE_THREAD_TRUE)
+ params.entire_thread = TRUE;
+ else
+ params.entire_thread = FALSE;
if (params.decrypt || verify) {
#ifdef GMIME_ATLEAST_26
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 4/5] Update devel/schemata for --entire-thread=false
2012-05-26 15:54 [PATCH v5 0/5] Allow JSON to use non-entire thread, and use for elide Mark Walters
` (2 preceding siblings ...)
2012-05-26 15:54 ` [PATCH v5 3/5] cli: make --entire-thread=false work for format=json Mark Walters
@ 2012-05-26 15:54 ` Mark Walters
2012-05-26 15:54 ` [PATCH v5 5/5] emacs: make elide messages use notmuch-show for omitting messages Mark Walters
4 siblings, 0 replies; 7+ messages in thread
From: Mark Walters @ 2012-05-26 15:54 UTC (permalink / raw)
To: notmuch
Also remove the Json --entire-thread item from devel/TODO.
---
devel/TODO | 2 --
devel/schemata | 2 +-
2 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/devel/TODO b/devel/TODO
index 7b750af..eb757af 100644
--- a/devel/TODO
+++ b/devel/TODO
@@ -92,8 +92,6 @@ and email address in the From: line. We could also then easily support
"notmuch compose --from <something>" to support getting at alternate
email addresses.
-Fix the --format=json option to not imply --entire-thread.
-
Implement "notmuch search --exclude-threads=<search-terms>" to allow
for excluding muted threads, (and any other negative, thread-based
filtering that the user wants to do).
diff --git a/devel/schemata b/devel/schemata
index 977cea7..8fcab8e 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -32,7 +32,7 @@ thread = [thread_node*]
# A message and its replies (show_messages)
thread_node = [
- message?, # present if --entire-thread or matched
+ message?, # null if not matched and not --entire-thread
[thread_node*] # children of message
]
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 5/5] emacs: make elide messages use notmuch-show for omitting messages.
2012-05-26 15:54 [PATCH v5 0/5] Allow JSON to use non-entire thread, and use for elide Mark Walters
` (3 preceding siblings ...)
2012-05-26 15:54 ` [PATCH v5 4/5] Update devel/schemata for --entire-thread=false Mark Walters
@ 2012-05-26 15:54 ` Mark Walters
4 siblings, 0 replies; 7+ messages in thread
From: Mark Walters @ 2012-05-26 15:54 UTC (permalink / raw)
To: notmuch
Previously the elide messages code got the entire-thread from
notmuch-show.c and then threw away all non-matching messages. This
version calls notmuch-show.c without the --entire-thread flag so
it never receives the non-matching messages in the first place.
This makes it substantially faster.
---
emacs/notmuch-show.el | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index d318430..9cc68be 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -958,9 +958,9 @@ message at DEPTH in the current thread."
"Insert the message tree TREE at depth DEPTH in the current thread."
(let ((msg (car tree))
(replies (cadr tree)))
- (if (or (not notmuch-show-elide-non-matching-messages)
- (plist-get msg :match))
- (notmuch-show-insert-msg msg depth))
+ ;; We test whether there is a message or just some replies.
+ (when msg
+ (notmuch-show-insert-msg msg depth))
(notmuch-show-insert-thread replies (1+ depth))))
(defun notmuch-show-insert-thread (thread depth)
@@ -1041,16 +1041,18 @@ function is used."
(args (if notmuch-show-query-context
(append (list "\'") basic-args
(list "and (" notmuch-show-query-context ")\'"))
- (append (list "\'") basic-args (list "\'")))))
- (notmuch-show-insert-forest (notmuch-query-get-threads
- (cons "--exclude=false" args)))
+ (append (list "\'") basic-args (list "\'"))))
+ (cli-args (cons "--exclude=false"
+ (when notmuch-show-elide-non-matching-messages
+ (list "--entire-thread=false")))))
+
+ (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))
;; If the query context reduced the results to nothing, run
;; the basic query.
(when (and (eq (buffer-size) 0)
notmuch-show-query-context)
(notmuch-show-insert-forest
- (notmuch-query-get-threads
- (cons "--exclude=false" basic-args)))))
+ (notmuch-query-get-threads (append cli-args basic-args)))))
(jit-lock-register #'notmuch-show-buttonise-links)
--
1.7.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread