--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id ACAAC6DE035F\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Jun 2016 01:40:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.005\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5\r
+ tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id s1Qjs-vxuQAP for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Jun 2016 01:40:46 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 5CE066DE014D\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Jun 2016 01:40:43 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1bIXWK-0007eJ-3H; Thu, 30 Jun 2016 04:40:24 -0400\r
+Received: (nullmailer pid 30884 invoked by uid 1000);\r
+ Thu, 30 Jun 2016 08:40:30 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] WIP: treat notmuch tag without operations as query\r
+Date: Thu, 30 Jun 2016 10:40:27 +0200\r
+Message-Id: <1467276027-30633-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1467276027-30633-1-git-send-email-david@tethera.net>\r
+References: <87fustdsx9.fsf@zancas.localnet>\r
+ <1467276027-30633-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 30 Jun 2016 08:40:53 -0000\r
+\r
+e.g.\r
+\r
+% notmuch tag # dump all tags\r
+% notmuch tag subject:foo # all tags of messages with foo in the subject\r
+---\r
+ notmuch-tag.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------\r
+ 1 file changed, 52 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 18d78dd..941c653 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -186,6 +186,50 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,\r
+ return ret || warn;\r
+ }\r
+ \r
++static int\r
++_dump_tags (notmuch_config_t *config, const char *query_string)\r
++{\r
++ notmuch_database_t *notmuch;\r
++ notmuch_tags_t *tags;\r
++ const char *tag;\r
++ char *status_string;\r
++\r
++ notmuch_query_t *query;\r
++\r
++ if (notmuch_database_open_verbose (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY,\r
++ ¬much, &status_string)) {\r
++ if (status_string) {\r
++ fputs (status_string, stderr);\r
++ free (status_string);\r
++ }\r
++ return EXIT_FAILURE;\r
++ }\r
++\r
++ query = notmuch_query_create (notmuch, query_string);\r
++ if (query == NULL) {\r
++ fprintf (stderr, "Out of memory\n");\r
++ return EXIT_FAILURE;\r
++ }\r
++\r
++ if (print_status_query ("notmuch tag",\r
++ query,\r
++ notmuch_query_search_tags (query, &tags)))\r
++ return 1;\r
++\r
++ for (;\r
++ notmuch_tags_valid (tags);\r
++ notmuch_tags_move_to_next (tags))\r
++ {\r
++ tag = notmuch_tags_get (tags);\r
++\r
++ printf ("%s\n", tag);\r
++ }\r
++\r
++ notmuch_tags_destroy (tags);\r
++ return EXIT_SUCCESS;\r
++}\r
++\r
+ int\r
+ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+@@ -196,6 +240,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
+ tag_op_flag_t tag_flags = TAG_FLAG_NONE;\r
+ notmuch_bool_t batch = FALSE;\r
+ notmuch_bool_t remove_all = FALSE;\r
++ notmuch_bool_t with_ops = FALSE;\r
+ FILE *input = stdin;\r
+ char *input_file_name = NULL;\r
+ int opt_index;\r
+@@ -248,17 +293,18 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
+ &query_string, tag_ops))\r
+ return EXIT_FAILURE;\r
+ \r
+- if (tag_op_list_size (tag_ops) == 0 && ! remove_all) {\r
+- fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
+- return EXIT_FAILURE;\r
+- }\r
++ if (tag_op_list_size (tag_ops) == 0 && ! remove_all)\r
++ with_ops = FALSE;\r
+ \r
+- if (*query_string == '\0') {\r
+- fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");\r
++ if (with_ops && *query_string == '\0') {\r
++ fprintf (stderr, "Error: notmuch tag with operations requires at least one search term.\n");\r
+ return EXIT_FAILURE;\r
+ }\r
+ }\r
+ \r
++ if (! with_ops)\r
++ return _dump_tags (config, query_string);\r
++\r
+ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
+ return EXIT_FAILURE;\r
+-- \r
+2.8.1\r
+\r