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 A659C431FBC for ; Thu, 19 Nov 2009 03:52:52 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 5Lxw47OPei1z for ; Thu, 19 Nov 2009 03:52:51 -0800 (PST) Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com [209.85.218.224]) by olra.theworths.org (Postfix) with ESMTP id 1BCB0431FAE for ; Thu, 19 Nov 2009 03:52:50 -0800 (PST) Received: by bwz24 with SMTP id 24so1174476bwz.30 for ; Thu, 19 Nov 2009 03:52:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.160.73 with SMTP id m9mr6106300bkx.214.1258631569649; Thu, 19 Nov 2009 03:52:49 -0800 (PST) In-Reply-To: <1258630481-5133-2-git-send-email-jan@ryngle.com> References: <1258630481-5133-1-git-send-email-jan@ryngle.com> <1258630481-5133-2-git-send-email-jan@ryngle.com> Date: Thu, 19 Nov 2009 12:52:49 +0100 Message-ID: From: Jan Janak To: notmuch@notmuchmail.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [notmuch] [PATCH 2/2] notmuch list: A new command to produce various lists. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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 Nov 2009 11:52:52 -0000 Carl and others, I implemented a new notmuch command that can be used to list all tags present in the database: $ notmuch list tags If you run this, you'll get an alphabetically sorted list of all tags--one tag per line. The main reason why I implemented this is because I am also working on adding the tag completion feature to the Emacs mode. This is very useful if you have a large collection of tags--it can save you some typing and, perhaps more importantly, it minimizes the risk of having typos in tag names. I'll send a patch for that later too. Let me know what do you think. -- Jan On Thu, Nov 19, 2009 at 12:34 PM, Jan Janak wrote: > Here we create a new notmuch command called list. The purpose of the > command is to produce various lists from the notmuch database. > > At the moment we support only one command, notmuch list tags. This > command creates a list of all tags found in the database. > > Signed-off-by: Jan Janak > --- > =C2=A0Makefile.local =C2=A0 | =C2=A0 =C2=A01 + > =C2=A0notmuch-client.h | =C2=A0 =C2=A03 ++ > =C2=A0notmuch-list.c =C2=A0 | =C2=A0 98 +++++++++++++++++++++++++++++++++= +++++++++++++++++++++ > =C2=A0notmuch.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 10 +++++ > =C2=A04 files changed, 112 insertions(+), 0 deletions(-) > =C2=A0create mode 100644 notmuch-list.c > > diff --git a/Makefile.local b/Makefile.local > index 27e42ba..fb6d5c3 100644 > --- a/Makefile.local > +++ b/Makefile.local > @@ -12,6 +12,7 @@ notmuch_client_srcs =3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 \ > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-show.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-tag.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 \ > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-time.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0\ > + =C2=A0 =C2=A0notmuch-list.c =C2=A0 =C2=A0 =C2=A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0gmime-filter-reply.c =C2=A0 =C2=A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0query-string.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0show-message.c > diff --git a/notmuch-client.h b/notmuch-client.h > index b65aa77..ae876b5 100644 > --- a/notmuch-client.h > +++ b/notmuch-client.h > @@ -114,6 +114,9 @@ notmuch_show_command (void *ctx, int argc, char *argv= []); > =C2=A0int > =C2=A0notmuch_tag_command (void *ctx, int argc, char *argv[]); > > +int > +notmuch_list_command (void *ctx, int argc, char *argv[]); > + > =C2=A0const char * > =C2=A0notmuch_time_relative_date (const void *ctx, time_t then); > > diff --git a/notmuch-list.c b/notmuch-list.c > new file mode 100644 > index 0000000..fe71108 > --- /dev/null > +++ b/notmuch-list.c > @@ -0,0 +1,98 @@ > +/* notmuch - Not much of an email program, (just index and search) > + * > + * Copyright =C2=A9 2009 Carl Worth > + * Copyright =C2=A9 2009 Jan Janak > + * > + * This program is free software: you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation, either version 3 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =C2=A0See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program. =C2=A0If not, see http://www.gnu.org/license= s/ . > + * > + * Authors: Carl Worth > + * =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Jan Janak > + */ > + > +#include "notmuch-client.h" > + > +enum list_cmd { > + =C2=A0 =C2=A0 =C2=A0 LIST_TAGS > +}; > + > + > +static int > +list_all_tags(notmuch_database_t* db) > +{ > + =C2=A0 =C2=A0 =C2=A0 notmuch_tags_t* tags; > + =C2=A0 =C2=A0 =C2=A0 const char* t; > + > + =C2=A0 =C2=A0 =C2=A0 if ((tags =3D notmuch_database_get_tags(db)) =3D= =3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Error= while obtaining tags from the database.\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 1; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 while((t =3D notmuch_tags_get(tags))) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("%s\n", t); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_tags_advance(t= ags); > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 notmuch_tags_destroy(tags); > + =C2=A0 =C2=A0 =C2=A0 return 0; > +} > + > +int > +notmuch_list_command (void *ctx, int argc, char *argv[]) > +{ > + =C2=A0 =C2=A0notmuch_config_t *config; > + =C2=A0 =C2=A0notmuch_database_t *db; > + =C2=A0 =C2=A0 =C2=A0 enum list_cmd cmd; > + > + =C2=A0 =C2=A0 =C2=A0 config =3D NULL; > + =C2=A0 =C2=A0 =C2=A0 db =3D NULL; > + > + =C2=A0 =C2=A0 =C2=A0 if (argc < 1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Error= : notmuch list requires at least one parameter.\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "(See = notmuch help list)\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 if (!strcmp(argv[0], "tags")) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cmd =3D LIST_TAGS; > + =C2=A0 =C2=A0 =C2=A0 } else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Sub-c= ommand '%s' not supported.\n", argv[0]); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0if ((config =3D notmuch_config_open (ctx, NULL, NULL)) =3D= =3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0db =3D notmuch_database_open (notmuch_config_get_database_= path (config)); > + =C2=A0 =C2=A0if (db =3D=3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 switch(cmd) { > + =C2=A0 =C2=A0 =C2=A0 case LIST_TAGS: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (list_all_tags(db) = !=3D 0) goto error; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > + > + =C2=A0 =C2=A0 =C2=A0 default: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Unsup= ported command: bug in notmuch_list_command.\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto error; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0notmuch_database_close (db); > + =C2=A0 =C2=A0return 0; > + > +error: > + =C2=A0 =C2=A0 =C2=A0 if (db) notmuch_database_close(db); > + =C2=A0 =C2=A0 =C2=A0 return 1; > +} > diff --git a/notmuch.c b/notmuch.c > index 5cc8e4c..1baa22d 100644 > --- a/notmuch.c > +++ b/notmuch.c > @@ -230,6 +230,16 @@ command_t commands[] =3D { > =C2=A0 =C2=A0 =C2=A0 "\t\tSo if you've previously been using sup for mail= , then the\n" > =C2=A0 =C2=A0 =C2=A0 "\t\t\"notmuch restore\" command provides you a way = to import\n" > =C2=A0 =C2=A0 =C2=A0 "\t\tall of your tags (or labels as sup calls them).= " }, > + =C2=A0 =C2=A0 =C2=A0 { "list", notmuch_list_command, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\tShow additional information about the = database.", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\tThe following sub-commands are support= ed:" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\n\n" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\ttags\n" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\n" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\t\tGenerate a list of all tags availabl= e in the database.\n" > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\t\t\tThe list will be sorted alphabetical= ly." > + =C2=A0 =C2=A0 =C2=A0 }, > =C2=A0 =C2=A0 { "help", notmuch_help_command, > =C2=A0 =C2=A0 =C2=A0 "[]", > =C2=A0 =C2=A0 =C2=A0 "\t\tThis message, or more detailed help for the nam= ed command.", > -- > 1.6.3.3 > > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch > >