Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 026FC431FAF for ; Thu, 19 Jan 2012 13:18:35 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K9hbEG9BMSqX for ; Thu, 19 Jan 2012 13:18:34 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 54143431FAE for ; Thu, 19 Jan 2012 13:18:27 -0800 (PST) Received: by werp13 with SMTP id p13so382561wer.26 for ; Thu, 19 Jan 2012 13:18:26 -0800 (PST) Received: by 10.216.136.156 with SMTP id w28mr1339406wei.11.1327007897834; Thu, 19 Jan 2012 13:18:17 -0800 (PST) Received: from localhost ([109.131.97.13]) by mx.google.com with ESMTPS id d9sm30192463wiy.2.2012.01.19.13.18.17 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Jan 2012 13:18:17 -0800 (PST) From: Pieter Praet To: Austin Clements Subject: Re: [PATCH 4/4] setup: prompt user for search.exclude_tags value In-Reply-To: <20120119194437.GP16740@mit.edu> References: <1326586654-16840-3-git-send-email-amdragon@mit.edu> <1327000744-25463-1-git-send-email-pieter@praet.org> <1327000744-25463-5-git-send-email-pieter@praet.org> <20120119194437.GP16740@mit.edu> User-Agent: Notmuch/0.11+99~gab86e73 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-unknown-linux-gnu) Date: Thu, 19 Jan 2012 22:16:27 +0100 Message-ID: <8762g7o0k4.fsf@praet.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Notmuch Mail X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jan 2012 21:18:35 -0000 On Thu, 19 Jan 2012 14:44:37 -0500, Austin Clements wrote: > 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? > Depends on who "we" is... :) I would gladly do it if I could, but I think this uber1337 copy-paste coding job serves as *very* convincing proof that I'm pretty much in the dark (with a single wet match) when it comes to C :) > > if (! notmuch_config_save (config)) { > > if (is_new) > > welcome_message_post_setup (); Peace -- Pieter