From 8af113cf940ffe9ed91025f3b47e5ba848cb90bf Mon Sep 17 00:00:00 2001 From: Bryan Bennett Date: Tue, 24 Jan 2017 10:49:14 -0500 Subject: [PATCH] notmuch: Allow to toggle labels can, now: tag add a tag +tag add a tag -tag remove a tag !tag toggle a tag Closes #326 Closes #328 --- README.notmuch | 2 +- doc/manual.xml.head | 3 +++ mutt_notmuch.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.notmuch b/README.notmuch index 471d22adf..663428d4c 100644 --- a/README.notmuch +++ b/README.notmuch @@ -97,7 +97,7 @@ notmuch support for mutt - note: TAB completion of 'tag:' names is available modify-labels: - - add or remove notmuch tags; [+] to add, - to remove + - add, remove, or toggle notmuch tags; [+] to add, - to remove, ! to toggle - default key: ` - note: TAB completion of tag names is available - example: "+AAA +BBB -CCC" diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 70f85f211..c959b11ad 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -12644,6 +12644,9 @@ bind index,pager + entire-thread # modify (notmuch) tags bind index,pager \` modify-labels +# modify (notmuch) tag non-interactively. +bind index,pager tt "<modify-labels>!todo\n" "Toggle the 'todo' tag" + # generate virtual folder from query bind index,pager \eX vfolder-from-query diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 7646a25f2..e66d380ea 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1321,6 +1321,23 @@ static notmuch_message_t *get_nm_message(notmuch_database_t *db, HEADER *hdr) return msg; } +static bool nm_message_has_tag(notmuch_message_t *msg, char *tag) +{ + const char *possible_match_tag; + notmuch_tags_t *tags; + + for (tags = notmuch_message_get_tags(msg); notmuch_tags_valid(tags); + notmuch_tags_move_to_next(tags)) + { + possible_match_tag = notmuch_tags_get(tags); + if (mutt_strncmp(possible_match_tag, tag, mutt_strlen(tag)) == 0) + { + return true; + } + } + return false; +} + static int update_tags(notmuch_message_t *msg, const char *tags) { char *tag = NULL, *end = NULL, *p; @@ -1353,6 +1370,18 @@ static int update_tags(notmuch_message_t *msg, const char *tags) dprint(1, (debugfile, "nm: remove tag: '%s'\n", tag + 1)); notmuch_message_remove_tag(msg, tag + 1); } + else if (*tag == '!') + { + dprint(1, (debugfile, "nm: toggle tag: '%s'\n", tag + 1)); + if (nm_message_has_tag (msg, tag + 1)) + { + notmuch_message_remove_tag (msg, tag + 1); + } + else + { + notmuch_message_add_tag (msg, tag + 1); + } + } else { dprint(1, (debugfile, "nm: add tag: '%s'\n", (*tag == '+') ? tag + 1 : tag)); -- 2.40.0