Re: [PATCH 4/4] setup: prompt user for search.exclude_tags value
authorPieter Praet <pieter@praet.org>
Thu, 19 Jan 2012 21:16:27 +0000 (22:16 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:44 +0000 (09:42 -0800)
27/44b2b1baf651a5c7140a4eed70231d74f52a0f [new file with mode: 0644]

diff --git a/27/44b2b1baf651a5c7140a4eed70231d74f52a0f b/27/44b2b1baf651a5c7140a4eed70231d74f52a0f
new file mode 100644 (file)
index 0000000..5b2980d
--- /dev/null
@@ -0,0 +1,138 @@
+Return-Path: <pieter@praet.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 026FC431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:18:35 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id K9hbEG9BMSqX for <notmuch@notmuchmail.org>;\r
+       Thu, 19 Jan 2012 13:18:34 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 54143431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:18:27 -0800 (PST)\r
+Received: by werp13 with SMTP id p13so382561wer.26\r
+       for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:18:26 -0800 (PST)\r
+Received: by 10.216.136.156 with SMTP id w28mr1339406wei.11.1327007897834;\r
+       Thu, 19 Jan 2012 13:18:17 -0800 (PST)\r
+Received: from localhost ([109.131.97.13])\r
+       by mx.google.com with ESMTPS id d9sm30192463wiy.2.2012.01.19.13.18.17\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 19 Jan 2012 13:18:17 -0800 (PST)\r
+From: Pieter Praet <pieter@praet.org>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 4/4] setup: prompt user for search.exclude_tags value\r
+In-Reply-To: <20120119194437.GP16740@mit.edu>\r
+References: <1326586654-16840-3-git-send-email-amdragon@mit.edu>\r
+       <1327000744-25463-1-git-send-email-pieter@praet.org>\r
+       <1327000744-25463-5-git-send-email-pieter@praet.org>\r
+       <20120119194437.GP16740@mit.edu>\r
+User-Agent: Notmuch/0.11+99~gab86e73 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-unknown-linux-gnu)\r
+Date: Thu, 19 Jan 2012 22:16:27 +0100\r
+Message-ID: <8762g7o0k4.fsf@praet.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 19 Jan 2012 21:18:35 -0000\r
+\r
+On Thu, 19 Jan 2012 14:44:37 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Quoth Pieter Praet on Jan 19 at  8:19 pm:\r
+> > Allow users to customize the search.exclude_tags option during setup.\r
+> > \r
+> > ---\r
+> >  notmuch-setup.c |   36 ++++++++++++++++++++++++++++++++++++\r
+> >  1 files changed, 36 insertions(+), 0 deletions(-)\r
+> > \r
+> > diff --git a/notmuch-setup.c b/notmuch-setup.c\r
+> > index c3ea937..44d4aaa 100644\r
+> > --- a/notmuch-setup.c\r
+> > +++ b/notmuch-setup.c\r
+> > @@ -101,6 +101,8 @@ notmuch_setup_command (unused (void *ctx),\r
+> >      int is_new;\r
+> >      const char **new_tags;\r
+> >      size_t new_tags_len;\r
+> > +    const char **search_exclude_tags;\r
+> > +    size_t search_exclude_tags_len;\r
+> >  \r
+> >  #define prompt(format, ...)                                       \\r
+> >      do {                                                  \\r
+> > @@ -195,6 +197,40 @@ notmuch_setup_command (unused (void *ctx),\r
+> >    g_ptr_array_free (tags, TRUE);\r
+> >      }\r
+> >  \r
+> > +    search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len);\r
+> > +\r
+> > +    printf ("Tags to exclude when searching messages (separated by spaces) [");\r
+> > +\r
+> > +    for (i = 0; i < search_exclude_tags_len; i++) {\r
+> > +  if (i != 0)\r
+> > +      printf (" ");\r
+> > +  printf ("%s", search_exclude_tags[i]);\r
+> > +    }\r
+> > +\r
+> > +    prompt ("]: ");\r
+> > +\r
+> > +    if (strlen (response)) {\r
+> > +  GPtrArray *tags = g_ptr_array_new ();\r
+> > +  char *tag = response;\r
+> > +  char *space;\r
+> > +\r
+> > +  while (tag && *tag) {\r
+> > +      space = strchr (tag, ' ');\r
+> > +      if (space)\r
+> > +          g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
+> > +      else\r
+> > +          g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
+> > +      tag = space;\r
+> > +      while (tag && *tag == ' ')\r
+> > +          tag++;\r
+> > +  }\r
+> > +\r
+> > +  notmuch_config_set_search_exclude_tags (config, (const char **) tags->pdata,\r
+> > +                               tags->len);\r
+> > +\r
+> > +  g_ptr_array_free (tags, TRUE);\r
+> > +    }\r
+> > +\r
+> \r
+> Holy code duplication.  Can we move most of this (at least the\r
+> response parsing part and maybe the prompt printing) into a function\r
+> and use it for both new tags and exclude tags?\r
+> \r
+\r
+Depends on who "we" is... :)  I would gladly do it if I could, but I\r
+think this uber1337 copy-paste coding job serves as *very* convincing\r
+proof that I'm pretty much in the dark (with a single wet match) when it\r
+comes to C :)\r
+\r
+\r
+> >      if (! notmuch_config_save (config)) {\r
+> >    if (is_new)\r
+> >      welcome_message_post_setup ();\r
+\r
+\r
+Peace\r
+\r
+-- \r
+Pieter\r