[PATCH 4/4] setup: prompt user for search.exclude_tags value

Austin Clements amdragon at MIT.EDU
Thu Jan 19 11:44:37 PST 2012


Quoth Pieter Praet on Jan 19 at  8:19 pm:
> Allow users to customize the search.exclude_tags option during setup.
> 
> ---
>  notmuch-setup.c |   36 ++++++++++++++++++++++++++++++++++++
>  1 files changed, 36 insertions(+), 0 deletions(-)
> 
> diff --git a/notmuch-setup.c b/notmuch-setup.c
> index c3ea937..44d4aaa 100644
> --- a/notmuch-setup.c
> +++ b/notmuch-setup.c
> @@ -101,6 +101,8 @@ notmuch_setup_command (unused (void *ctx),
>      int is_new;
>      const char **new_tags;
>      size_t new_tags_len;
> +    const char **search_exclude_tags;
> +    size_t search_exclude_tags_len;
>  
>  #define prompt(format, ...)					\
>      do {							\
> @@ -195,6 +197,40 @@ notmuch_setup_command (unused (void *ctx),
>  	g_ptr_array_free (tags, TRUE);
>      }
>  
> +    search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len);
> +
> +    printf ("Tags to exclude when searching messages (separated by spaces) [");
> +
> +    for (i = 0; i < search_exclude_tags_len; i++) {
> +	if (i != 0)
> +	    printf (" ");
> +	printf ("%s", search_exclude_tags[i]);
> +    }
> +
> +    prompt ("]: ");
> +
> +    if (strlen (response)) {
> +	GPtrArray *tags = g_ptr_array_new ();
> +	char *tag = response;
> +	char *space;
> +
> +	while (tag && *tag) {
> +	    space = strchr (tag, ' ');
> +	    if (space)
> +		g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));
> +	    else
> +		g_ptr_array_add (tags, talloc_strdup (ctx, tag));
> +	    tag = space;
> +	    while (tag && *tag == ' ')
> +		tag++;
> +	}
> +
> +	notmuch_config_set_search_exclude_tags (config, (const char **) tags->pdata,
> +				     tags->len);
> +
> +	g_ptr_array_free (tags, TRUE);
> +    }
> +

Holy code duplication.  Can we move most of this (at least the
response parsing part and maybe the prompt printing) into a function
and use it for both new tags and exclude tags?

>      if (! notmuch_config_save (config)) {
>  	if (is_new)
>  	  welcome_message_post_setup ();


More information about the notmuch mailing list