unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated.
Date: Fri,  2 May 2014 09:15:52 +0100	[thread overview]
Message-ID: <1399018555-1994-3-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1399018555-1994-1-git-send-email-dme@dme.org>

Add support for specifying a set of tags to be added/removed from
messages added to the database by 'notmuch new'. These tags are
addition to those specified in .notmuch-config. They can be used to
override the pre-configured tags (e.g. -inbox).
---
 notmuch-new.c |  5 +++++
 tag-util.c    | 20 +++++++++++++++-----
 tag-util.h    | 15 +++++++++++++++
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index b53401a..855e1e2 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -951,6 +951,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     add_files_state.tag_ops = tag_op_list_create (config);
     db_path = notmuch_config_get_database_path (config);
 
+    /* Add the configured tags to the list applied. */
     for (i = 0; i < new_tags_length; i++) {
 	const char *error_msg;
 
@@ -963,6 +964,10 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 	    return EXIT_FAILURE;
     }
 
+    /* Add any command line tags to the list applied. */
+    if (process_tag_command_line (argc - opt_index, &argv[opt_index], add_files_state.tag_ops) < 0)
+	return EXIT_FAILURE;
+
     if (!no_hooks) {
 	ret = notmuch_run_hook (db_path, "pre-new");
 	if (ret)
diff --git a/tag-util.c b/tag-util.c
index 343c161..5ad78aa 100644
--- a/tag-util.c
+++ b/tag-util.c
@@ -151,11 +151,9 @@ parse_tag_line (void *ctx, char *line,
     return ret;
 }
 
-tag_parse_status_t
-parse_tag_command_line (void *ctx, int argc, char **argv,
-			char **query_str, tag_op_list_t *tag_ops)
+int
+process_tag_command_line (int argc, char **argv, tag_op_list_t *tag_ops)
 {
-
     int i;
 
     for (i = 0; i < argc; i++) {
@@ -173,12 +171,24 @@ parse_tag_command_line (void *ctx, int argc, char **argv,
 	msg = illegal_tag (argv[i] + 1, is_remove);
 	if (msg) {
 	    fprintf (stderr, "Error: %s\n", msg);
-	    return TAG_PARSE_INVALID;
+	    return -1;
 	}
 
 	tag_op_list_append (tag_ops, argv[i] + 1, is_remove);
     }
 
+    return i;
+}
+
+tag_parse_status_t
+parse_tag_command_line (void *ctx, int argc, char **argv,
+			char **query_str, tag_op_list_t *tag_ops)
+{
+    int i = process_tag_command_line (argc, argv, tag_ops);
+
+    if (i < 0)
+	return TAG_PARSE_INVALID;
+
     *query_str = query_string_from_args (ctx, argc - i, &argv[i]);
 
     if (*query_str == NULL) {
diff --git a/tag-util.h b/tag-util.h
index 8a4074c..9f2c18c 100644
--- a/tag-util.h
+++ b/tag-util.h
@@ -74,6 +74,21 @@ parse_tag_line (void *ctx, char *line,
 
 
 
+/* Process a command line of the following format:
+ *
+ * +<tag>|-<tag> [...] [--]
+ *
+ * Return the number of tags operations, or -1 for failure to parse.
+ *
+ * Output Parameters:
+ *	ops	contains a list of tag operations
+ *
+ * The ops argument is not cleared.
+ */
+
+int
+process_tag_command_line (int argc, char **argv, tag_op_list_t *ops);
+
 /* Parse a command line of the following format:
  *
  * +<tag>|-<tag> [...] [--] <search-terms>
-- 
1.9.2

  parent reply	other threads:[~2014-05-02  8:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-02  8:15 Add support for specifying tags during "notmuch new" David Edmondson
2014-05-02  8:15 ` [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same David Edmondson
2014-05-02  8:15 ` David Edmondson [this message]
2014-05-02  8:15 ` [PATCH 3/5] notmuch-new: Manual: Add command line tags David Edmondson
2014-05-02  8:15 ` [PATCH 4/5] NEWS: Add information about "notmuch new" " David Edmondson
2014-05-02  8:15 ` [PATCH 5/5] Test: Add tests for " David Edmondson
2014-05-02 12:11 ` [PATCH v2 0/5] Add support for specifying tags during "notmuch new" David Edmondson
2014-05-02 12:14   ` [PATCH 1/5] notmuch-new: Use tag_op_list_apply() rather than hand-coding the same David Edmondson
2014-05-02 12:14   ` [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated David Edmondson
2014-05-02 12:14   ` [PATCH 3/5] notmuch-new: Manual: Add command line tags David Edmondson
2014-05-02 12:14   ` [PATCH 4/5] NEWS: Add information about "notmuch new" " David Edmondson
2014-05-02 12:14   ` [PATCH 5/5] Test: Add tests for " David Edmondson
2014-05-02 14:07   ` [PATCH v2 0/5] Add support for specifying tags during "notmuch new" Mark Walters
2014-05-02 15:18 ` Austin Clements
2014-05-02 15:32   ` David Edmondson
2014-07-12 19:08   ` David Bremner
2014-07-13  3:40     ` Austin Clements
2014-07-13 11:58       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399018555-1994-3-git-send-email-dme@dme.org \
    --to=dme@dme.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).