unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] notmuch: New function to retrieve all tags from the database.
@ 2009-11-23  0:10 Jan Janak
  2009-11-23  0:10 ` [PATCH 2/3] notmuch: New command 'search-tags' Jan Janak
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Janak @ 2009-11-23  0:10 UTC (permalink / raw)
  To: notmuch

This patch adds a new function called notmuch_database_get_all_tags
which can be used to obtain a list of all tags from the database
(in other words, the list contains all tags from all messages). The
function produces an alphabetically sorted list.

To add support for the new function, we rip the guts off of
notmuch_message_get_tags and put them in a new generic function
called _notmuch_convert_tags. The generic function takes a
Xapian::TermIterator as argument and uses the iterator to find tags.
This makes the function usable with different Xapian objects.

Function notmuch_message_get_tags is then reimplemented to call the
generic function with message->doc.termlist_begin() as argument.

Similarly, we implement notmuch_message_database_get_all_tags, the
function calls the generic function with db->xapian_db->allterms_begin()
as argument.

Finally, notmuch_database_get_all_tags is exported through
lib/notmuch.h

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 lib/database-private.h |   13 +++++++++++++
 lib/database.cc        |   43 +++++++++++++++++++++++++++++++++++++++++++
 lib/message.cc         |   34 +++-------------------------------
 lib/notmuch.h          |   10 ++++++++++
 4 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index 5f178f3..37f9bf8 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -34,4 +34,17 @@ struct _notmuch_database {
     Xapian::TermGenerator *term_gen;
 };
 
+/* Convert tags from Xapian internal format to notmuch format.
+ *
+ * The function gets a TermIterator as argument and uses that iterator to find
+ * all tag terms in the object. The tags are then converted to a
+ * notmuch_tags_t list and returned. The function needs to allocate memory for
+ * the resulting list and it uses the argument ctx as talloc context.
+ *
+ * The function returns NULL on failure.
+ */
+notmuch_tags_t *
+_notmuch_convert_tags (void *ctx, Xapian::TermIterator &i,
+		       Xapian::TermIterator &end);
+
 #endif
diff --git a/lib/database.cc b/lib/database.cc
index 2c90019..5d2add7 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1026,3 +1026,46 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
     return ret;
 }
+
+notmuch_tags_t *
+_notmuch_convert_tags (void *ctx, Xapian::TermIterator &i,
+		       Xapian::TermIterator &end)
+{
+    const char *prefix = _find_prefix ("tag");
+    notmuch_tags_t *tags;
+    std::string tag;
+
+    /* Currently this iteration is written with the assumption that
+     * "tag" has a single-character prefix. */
+    assert (strlen (prefix) == 1);
+
+    tags = _notmuch_tags_create (ctx);
+    if (unlikely (tags == NULL))
+	return NULL;
+
+    i.skip_to (prefix);
+
+    while (i != end) {
+	tag = *i;
+
+	if (tag.empty () || tag[0] != *prefix)
+	    break;
+
+	_notmuch_tags_add_tag (tags, tag.c_str () + 1);
+
+	i++;
+    }
+
+    _notmuch_tags_prepare_iterator (tags);
+
+    return tags;
+}
+
+notmuch_tags_t *
+notmuch_database_get_all_tags (notmuch_database_t *db)
+{
+    Xapian::TermIterator i, end;
+    i = db->xapian_db->allterms_begin();
+    end = db->xapian_db->allterms_end();
+    return _notmuch_convert_tags(db, i, end);
+}
diff --git a/lib/message.cc b/lib/message.cc
index 017c47b..d27ea92 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -459,38 +459,10 @@ notmuch_message_get_date (notmuch_message_t *message)
 notmuch_tags_t *
 notmuch_message_get_tags (notmuch_message_t *message)
 {
-    const char *prefix = _find_prefix ("tag");
     Xapian::TermIterator i, end;
-    notmuch_tags_t *tags;
-    std::string tag;
-
-    /* Currently this iteration is written with the assumption that
-     * "tag" has a single-character prefix. */
-    assert (strlen (prefix) == 1);
-
-    tags = _notmuch_tags_create (message);
-    if (unlikely (tags == NULL))
-	return NULL;
-
-    i = message->doc.termlist_begin ();
-    end = message->doc.termlist_end ();
-
-    i.skip_to (prefix);
-
-    while (i != end) {
-	tag = *i;
-
-	if (tag.empty () || tag[0] != *prefix)
-	    break;
-
-	_notmuch_tags_add_tag (tags, tag.c_str () + 1);
-
-	i++;
-    }
-
-    _notmuch_tags_prepare_iterator (tags);
-
-    return tags;
+    i = message->doc.termlist_begin();
+    end = message->doc.termlist_end();
+    return _notmuch_convert_tags(message, i, end);
 }
 
 void
diff --git a/lib/notmuch.h b/lib/notmuch.h
index a61cd02..e2f1398 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -280,6 +280,16 @@ notmuch_message_t *
 notmuch_database_find_message (notmuch_database_t *database,
 			       const char *message_id);
 
+/* Return a list of all tags found in the database.
+ *
+ * This function creates a list of all tags found in the database. The
+ * resulting list contains all tags from all messages found in the database.
+ *
+ * On error this function returns NULL.
+ */
+notmuch_tags_t *
+notmuch_database_get_all_tags (notmuch_database_t *db);
+
 /* Create a new query for 'database'.
  *
  * Here, 'database' should be an open database, (see
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] notmuch: New command 'search-tags'.
  2009-11-23  0:10 [PATCH 1/3] notmuch: New function to retrieve all tags from the database Jan Janak
@ 2009-11-23  0:10 ` Jan Janak
  2009-11-23  0:10   ` [PATCH 3/3] notmuch.el: Select tag names with completion Jan Janak
  2009-11-25  3:30   ` [PATCH 1/2] lib: New function to collect tags from a list of messages Jan Janak
  0 siblings, 2 replies; 9+ messages in thread
From: Jan Janak @ 2009-11-23  0:10 UTC (permalink / raw)
  To: notmuch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4191 bytes --]

This is a new notmuch command that can be used to search for all tags
found in the database. The resulting list is alphabetically sorted.

The primary use-case for this new command is to provide the tag
completion feature in Emacs (and other interfaces).

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 Makefile.local        |    1 +
 notmuch-client.h      |    3 ++
 notmuch-search-tags.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++
 notmuch.c             |    6 ++++
 4 files changed, 81 insertions(+), 0 deletions(-)
 create mode 100644 notmuch-search-tags.c

diff --git a/Makefile.local b/Makefile.local
index 2828659..d8f7906 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -12,6 +12,7 @@ notmuch_client_srcs =		\
 	notmuch-reply.c		\
 	notmuch-restore.c	\
 	notmuch-search.c	\
+	notmuch-search-tags.c   \
 	notmuch-setup.c		\
 	notmuch-show.c		\
 	notmuch-tag.c		\
diff --git a/notmuch-client.h b/notmuch-client.h
index ea77686..c6142b5 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -114,6 +114,9 @@ notmuch_show_command (void *ctx, int argc, char *argv[]);
 int
 notmuch_tag_command (void *ctx, int argc, char *argv[]);
 
+int
+notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
+
 const char *
 notmuch_time_relative_date (const void *ctx, time_t then);
 
diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c
new file mode 100644
index 0000000..1201165
--- /dev/null
+++ b/notmuch-search-tags.c
@@ -0,0 +1,71 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2009 Carl Worth
+ * Copyright © 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.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: Jan Janak <jan@ryngle.com>
+ */
+
+#include "notmuch-client.h"
+
+static int
+list_all_tags (notmuch_database_t* db)
+{
+    notmuch_tags_t* tags;
+    const char* t;
+
+    if ((tags = notmuch_database_get_all_tags (db)) == NULL) {
+	fprintf (stderr, "Error while obtaining tags from the database.\n");
+	return 1;
+    }
+
+    while((t = notmuch_tags_get (tags))) {
+	printf ("%s\n", t);
+	notmuch_tags_advance (tags);
+    }
+
+    notmuch_tags_destroy (tags);
+    return 0;
+}
+
+int
+notmuch_search_tags_command (void *ctx, int argc, char *argv[])
+{
+    notmuch_config_t *config;
+    notmuch_database_t *db;
+
+    config = NULL;
+    db = NULL;
+
+    if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {
+	goto error;
+    }
+
+    db = notmuch_database_open (notmuch_config_get_database_path (config),
+				NOTMUCH_DATABASE_MODE_READ_ONLY);
+    if (db == NULL) {
+	goto error;
+    }
+
+    if (list_all_tags (db) != 0) goto error;
+
+    notmuch_database_close (db);
+    return 0;
+
+error:
+    if (db) notmuch_database_close (db);
+    return 1;
+}
diff --git a/notmuch.c b/notmuch.c
index 5cc8e4c..b1d7cf9 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -230,6 +230,12 @@ command_t commands[] = {
       "\t\tSo if you've previously been using sup for mail, then the\n"
       "\t\t\"notmuch restore\" command provides you a way to import\n"
       "\t\tall of your tags (or labels as sup calls them)." },
+    { "search-tags", notmuch_search_tags_command,
+      NULL,
+      "List all tags found in the database.",
+      "\t\tThis command returns an alphabetically sorted list of all tags\n"
+      "\t\tthat are present in the database. In other words, the resulting\n"
+      "\t\tlist is a collection of all tags from all messages." },
     { "help", notmuch_help_command,
       "[<command>]",
       "\t\tThis message, or more detailed help for the named command.",
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] notmuch.el: Select tag names with completion.
  2009-11-23  0:10 ` [PATCH 2/3] notmuch: New command 'search-tags' Jan Janak
@ 2009-11-23  0:10   ` Jan Janak
  2009-11-25  4:05     ` [PATCH] notmuch.el: When removing tags, offer only those a msg/thread has set Jan Janak
  2009-11-26 15:15     ` [PATCH 3/3] notmuch.el: Select tag names with completion Carl Worth
  2009-11-25  3:30   ` [PATCH 1/2] lib: New function to collect tags from a list of messages Jan Janak
  1 sibling, 2 replies; 9+ messages in thread
From: Jan Janak @ 2009-11-23  0:10 UTC (permalink / raw)
  To: notmuch

Several commands ask the user for a tag name. With this feature the
user can just press tab and Emacs automatically retrieves the list of
all existing tags from notmuch database with 'notmuch search-tags' and
presents a completion buffer to the user.

This feature is very useful for users who have a large number of tags
because it saves typing and minimizes the risk of typos.

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 notmuch.el |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 5927737..b6be395 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -139,6 +139,13 @@ within the current window."
       (or (memq prop buffer-invisibility-spec)
 	  (assq prop buffer-invisibility-spec)))))
 
+(defun notmuch-select-tag-with-completion (prompt)
+  (let ((tag-list
+	 (with-output-to-string
+	   (with-current-buffer standard-output
+	     (call-process notmuch-command nil t nil "search-tags")))))
+    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
+
 (defun notmuch-show-next-line ()
   "Like builtin `next-line' but ensuring we end on a visible character.
 
@@ -202,7 +209,8 @@ Unlike builtin `next-line' this version accepts no arguments."
 
 (defun notmuch-show-add-tag (&rest toadd)
   "Add a tag to the current message."
-  (interactive "sTag to add: ")
+  (interactive
+   (list (notmuch-select-tag-with-completion "Tag to add: ")))
   (apply 'notmuch-call-notmuch-process
 	 (append (cons "tag"
 		       (mapcar (lambda (s) (concat "+" s)) toadd))
@@ -211,7 +219,8 @@ Unlike builtin `next-line' this version accepts no arguments."
 
 (defun notmuch-show-remove-tag (&rest toremove)
   "Remove a tag from the current message."
-  (interactive "sTag to remove: ")
+  (interactive
+   (list (notmuch-select-tag-with-completion "Tag to remove: ")))
   (let ((tags (notmuch-show-get-tags)))
     (if (intersection tags toremove :test 'string=)
 	(progn
@@ -970,12 +979,14 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
 	(split-string (buffer-substring beg end))))))
 
 (defun notmuch-search-add-tag (tag)
-  (interactive "sTag to add: ")
+  (interactive
+   (list (notmuch-select-tag-with-completion "Tag to add: ")))
   (notmuch-call-notmuch-process "tag" (concat "+" tag) (notmuch-search-find-thread-id))
   (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))))
 
 (defun notmuch-search-remove-tag (tag)
-  (interactive "sTag to remove: ")
+  (interactive
+   (list (notmuch-select-tag-with-completion "Tag to remove: ")))
   (notmuch-call-notmuch-process "tag" (concat "-" tag) (notmuch-search-find-thread-id))
   (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
 
@@ -1061,7 +1072,8 @@ current search results AND the additional query string provided."
 
 Runs a new search matching only messages that match both the
 current search results AND that are tagged with the given tag."
-  (interactive "sFilter by tag: ")
+  (interactive
+   (list (notmuch-select-tag-with-completion "Filter by tag: ")))
   (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
 
 (defun notmuch ()
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 1/2] lib: New function to collect tags from a list of messages.
  2009-11-23  0:10 ` [PATCH 2/3] notmuch: New command 'search-tags' Jan Janak
  2009-11-23  0:10   ` [PATCH 3/3] notmuch.el: Select tag names with completion Jan Janak
@ 2009-11-25  3:30   ` Jan Janak
  2009-11-25  3:30     ` [PATCH 2/2] search-tags: Add support for search-terms Jan Janak
  1 sibling, 1 reply; 9+ messages in thread
From: Jan Janak @ 2009-11-25  3:30 UTC (permalink / raw)
  To: notmuch

This patch adds a new function that can be used to collect a list of
unique tags from a list of messages. 'notmuch search-tags' uses the
function to get a list of tags from messages matching a search-term,
but it has the potential to be used elsewhere so we put it in the lib.

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 lib/messages.c |   40 ++++++++++++++++++++++++++++++++++++++++
 lib/notmuch.h  |   15 +++++++++++++++
 2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/lib/messages.c b/lib/messages.c
index 54c0ab0..aa92535 100644
--- a/lib/messages.c
+++ b/lib/messages.c
@@ -20,6 +20,8 @@
 
 #include "notmuch-private.h"
 
+#include <glib.h>
+
 /* Create a new notmuch_message_list_t object, with 'ctx' as its
  * talloc owner.
  *
@@ -140,3 +142,41 @@ notmuch_messages_destroy (notmuch_messages_t *messages)
 {
     talloc_free (messages);
 }
+
+
+notmuch_tags_t *
+notmuch_messages_collect_tags (notmuch_messages_t *messages)
+{
+    notmuch_tags_t *tags, *msg_tags;
+    notmuch_message_t *msg;
+    GHashTable *htable;
+    GList *keys, *l;
+    const char *tag;
+
+    tags = _notmuch_tags_create (messages);
+    if (tags == NULL) return NULL;
+
+    htable = g_hash_table_new_full (g_str_hash, g_str_equal, free, NULL);
+
+    while ((msg = notmuch_messages_get (messages))) {
+	msg_tags = notmuch_message_get_tags (msg);
+	while ((tag = notmuch_tags_get (msg_tags))) {
+	    g_hash_table_insert (htable, xstrdup (tag), NULL);
+	    notmuch_tags_advance (msg_tags);
+	}
+	notmuch_tags_destroy (msg_tags);
+	notmuch_message_destroy (msg);
+	notmuch_messages_advance (messages);
+    }
+
+    keys = g_hash_table_get_keys (htable);
+    for (l = keys; l; l = l->next) {
+	_notmuch_tags_add_tag (tags, (char *)l->data);
+    }
+
+    g_list_free (keys);
+    g_hash_table_destroy (htable);
+
+    _notmuch_tags_prepare_iterator (tags);
+    return tags;
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c05e802..9fa2770 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -635,6 +635,21 @@ notmuch_messages_advance (notmuch_messages_t *messages);
 void
 notmuch_messages_destroy (notmuch_messages_t *messages);
 
+/* Return a list of tags from all messages.
+ *
+ * The resulting list is guaranteed not to contain duplicated tags.
+ *
+ * WARNING: You can no longer iterate over messages after calling this
+ * function, because the iterator will point at the end of the list.
+ * We do not have a function to reset the iterator yet and the only
+ * way how you can iterate over the list again is to recreate the
+ * message list.
+ *
+ * The function returns NULL on error.
+ */
+notmuch_tags_t *
+notmuch_messages_collect_tags (notmuch_messages_t *messages);
+
 /* Get the message ID of 'message'.
  *
  * The returned string belongs to 'message' and as such, should not be
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] search-tags: Add support for search-terms.
  2009-11-25  3:30   ` [PATCH 1/2] lib: New function to collect tags from a list of messages Jan Janak
@ 2009-11-25  3:30     ` Jan Janak
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Janak @ 2009-11-25  3:30 UTC (permalink / raw)
  To: notmuch

This patch adds support for search-terms to 'notmuch search-tags'. If
no search-term is provided then the command returns a list of all tags
from the database.

If the user provides one or more search-terms as arguments then the
command collects tags from matching messages only.

This could be used by functions in the Emacs mode to further limit the
list of tags offered for completion. For example, functions that remove
tags from message(s) could offer only tags present in the message(s).

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 notmuch-search-tags.c |   55 ++++++++++++++++++++++++++++++++++++------------
 notmuch.c             |   13 +++++++----
 2 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c
index 1201165..7a1305e 100644
--- a/notmuch-search-tags.c
+++ b/notmuch-search-tags.c
@@ -21,34 +21,31 @@
 
 #include "notmuch-client.h"
 
-static int
-list_all_tags (notmuch_database_t* db)
+static void
+print_tags (notmuch_tags_t *tags)
 {
-    notmuch_tags_t* tags;
-    const char* t;
+    const char *t;
 
-    if ((tags = notmuch_database_get_all_tags (db)) == NULL) {
-	fprintf (stderr, "Error while obtaining tags from the database.\n");
-	return 1;
-    }
-
-    while((t = notmuch_tags_get (tags))) {
+    while ((t = notmuch_tags_get (tags))) {
 	printf ("%s\n", t);
 	notmuch_tags_advance (tags);
     }
-
-    notmuch_tags_destroy (tags);
-    return 0;
 }
 
 int
 notmuch_search_tags_command (void *ctx, int argc, char *argv[])
 {
+    notmuch_messages_t *msgs;
+    notmuch_tags_t *tags;
     notmuch_config_t *config;
     notmuch_database_t *db;
+    notmuch_query_t *query;
+    char *query_str;
 
+    tags = NULL;
     config = NULL;
     db = NULL;
+    query = NULL;
 
     if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {
 	goto error;
@@ -60,12 +57,42 @@ notmuch_search_tags_command (void *ctx, int argc, char *argv[])
 	goto error;
     }
 
-    if (list_all_tags (db) != 0) goto error;
+    if (argc > 0) {
+	if ((query_str = query_string_from_args (ctx, argc, argv)) == NULL) {
+	    fprintf (stderr, "Out of memory.\n");
+	    goto error;
+	}
+
+	if (*query_str == '\0') {
+	    fprintf (stderr, "Error: Invalid search string.\n");
+	    goto error;
+	}
+
+	if ((query = notmuch_query_create (db, query_str)) == NULL) {
+	    fprintf (stderr, "Out of memory\n");
+	    goto error;
+	}
+
+
+	msgs = notmuch_query_search_messages (query);
+	if ((tags = notmuch_messages_collect_tags (msgs)) == NULL) goto error;
+    } else {
+	if ((tags = notmuch_database_get_all_tags (db)) == NULL) {
+	    fprintf (stderr, "Error while getting tags from the database.\n");
+	    goto error;
+	}
+    }
+
+    print_tags (tags);
 
+    notmuch_tags_destroy (tags);
+    if (query) notmuch_query_destroy (query);
     notmuch_database_close (db);
     return 0;
 
 error:
+    if (tags) notmuch_tags_destroy (tags);
+    if (query) notmuch_query_destroy (query);
     if (db) notmuch_database_close (db);
     return 1;
 }
diff --git a/notmuch.c b/notmuch.c
index c57bb5c..5b0284c 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -255,11 +255,14 @@ command_t commands[] = {
       "\t\t\"notmuch restore\" command provides you a way to import\n"
       "\t\tall of your tags (or labels as sup calls them)." },
     { "search-tags", notmuch_search_tags_command,
-      NULL,
-      "List all tags found in the database.",
-      "\t\tThis command returns an alphabetically sorted list of all tags\n"
-      "\t\tthat are present in the database. In other words, the resulting\n"
-      "\t\tlist is a collection of all tags from all messages." },
+      "[<search-terms> [...] ]",
+      "\t\tList all tags found in the database or matching messages.",
+      "\t\tRun this command without any search-term(s) to obtain a list\n"
+      "\t\tof all tags found in the database. If you provide one or more\n"
+      "\t\tsearch-terms as argument(s) then the resulting list will\n"
+      "\t\tcontain tags only from messages that match the search-term(s).\n"
+      "\n"
+      "\t\tIn both cases the list will be alphabetically sorted." },
     { "help", notmuch_help_command,
       "[<command>]",
       "\t\tThis message, or more detailed help for the named command.",
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] notmuch.el: When removing tags, offer only those a msg/thread has set.
  2009-11-23  0:10   ` [PATCH 3/3] notmuch.el: Select tag names with completion Jan Janak
@ 2009-11-25  4:05     ` Jan Janak
  2009-11-26 15:15     ` [PATCH 3/3] notmuch.el: Select tag names with completion Carl Worth
  1 sibling, 0 replies; 9+ messages in thread
From: Jan Janak @ 2009-11-25  4:05 UTC (permalink / raw)
  To: notmuch

When removing a tag from a message or thread, build a completion buffer
which contains only tags that the message or thread has really set.

Signed-off-by: Jan Janak <jan@ryngle.com>
---
 notmuch.el |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index a9f534b..9594f63 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -137,11 +137,11 @@ within the current window."
       (or (memq prop buffer-invisibility-spec)
 	  (assq prop buffer-invisibility-spec)))))
 
-(defun notmuch-select-tag-with-completion (prompt)
+(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
   (let ((tag-list
 	 (with-output-to-string
 	   (with-current-buffer standard-output
-	     (call-process notmuch-command nil t nil "search-tags")))))
+	     (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
     (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
 
 (defun notmuch-show-next-line ()
@@ -218,7 +218,7 @@ Unlike builtin `next-line' this version accepts no arguments."
 (defun notmuch-show-remove-tag (&rest toremove)
   "Remove a tag from the current message."
   (interactive
-   (list (notmuch-select-tag-with-completion "Tag to remove: ")))
+   (list (notmuch-select-tag-with-completion "Tag to remove: " (notmuch-show-get-message-id))))
   (let ((tags (notmuch-show-get-tags)))
     (if (intersection tags toremove :test 'string=)
 	(progn
@@ -968,7 +968,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
 
 (defun notmuch-search-remove-tag (tag)
   (interactive
-   (list (notmuch-select-tag-with-completion "Tag to remove: ")))
+   (list (notmuch-select-tag-with-completion "Tag to remove: " (notmuch-search-find-thread-id))))
   (notmuch-call-notmuch-process "tag" (concat "-" tag) (notmuch-search-find-thread-id))
   (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
 
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] notmuch.el: Select tag names with completion.
  2009-11-23  0:10   ` [PATCH 3/3] notmuch.el: Select tag names with completion Jan Janak
  2009-11-25  4:05     ` [PATCH] notmuch.el: When removing tags, offer only those a msg/thread has set Jan Janak
@ 2009-11-26 15:15     ` Carl Worth
  2009-11-27 11:30       ` Jan Janak
  1 sibling, 1 reply; 9+ messages in thread
From: Carl Worth @ 2009-11-26 15:15 UTC (permalink / raw)
  To: Jan Janak, notmuch

On Mon, 23 Nov 2009 01:10:56 +0100, Jan Janak <jan@ryngle.com> wrote:
> Several commands ask the user for a tag name. With this feature the
> user can just press tab and Emacs automatically retrieves the list of
> all existing tags from notmuch database with 'notmuch search-tags' and
> presents a completion buffer to the user.
> 
> This feature is very useful for users who have a large number of tags
> because it saves typing and minimizes the risk of typos.

Jan,

This feature is incredibly useful. Thanks so much for coding it!

I've had a bunch of messages that were effectively "lost" to me since
switching from sup. I had been experimenting with different tag
schemes, renaming tags, etc. within sup. But in sup there was no
global-search-based tag manipulation command, so no easy way to update
the tag names for messages tagged under the old scheme.

I'd been aware of the problem and knew I could just code something up to
search for those old tags. But now I get to see the full list every time
I hit TAB in emacs. So thanks!

I do still want to unify search, search-messages, search-tags, count,
etc. But I've gone ahead and merged this whole series as-is to get the
functionality out there for now.

I assume that everyone is aware that I'm reserving the right to change
the library and command-line interface as much as I want right now.

If you've got code or scripts that depend on these interfaces, I highly
recommend that you get them contributed to the notmuch repository so
that we can fix them up as we rework the library and command line.

(So, Bart, I'll merge the vim stuff which is using "notmuch count"
before I change that, so I can fixup the vim stuff at the same time.)

Thanks again, Jan! Well done.

-Carl

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] notmuch.el: Select tag names with completion.
  2009-11-26 15:15     ` [PATCH 3/3] notmuch.el: Select tag names with completion Carl Worth
@ 2009-11-27 11:30       ` Jan Janak
  2009-11-28  4:10         ` Carl Worth
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Janak @ 2009-11-27 11:30 UTC (permalink / raw)
  To: Carl Worth; +Cc: notmuch

Hi Carl,

On 26-11 07:15, Carl Worth wrote:
> On Mon, 23 Nov 2009 01:10:56 +0100, Jan Janak <jan@ryngle.com> wrote:
> > Several commands ask the user for a tag name. With this feature the
> > user can just press tab and Emacs automatically retrieves the list of
> > all existing tags from notmuch database with 'notmuch search-tags' and
> > presents a completion buffer to the user.
> > 
> > This feature is very useful for users who have a large number of tags
> > because it saves typing and minimizes the risk of typos.
> 
> Jan,
> 
> This feature is incredibly useful. Thanks so much for coding it!

You are welcome!

> I've had a bunch of messages that were effectively "lost" to me since
> switching from sup. I had been experimenting with different tag
> schemes, renaming tags, etc. within sup. But in sup there was no
> global-search-based tag manipulation command, so no easy way to update
> the tag names for messages tagged under the old scheme.
> 
> I'd been aware of the problem and knew I could just code something up to
> search for those old tags. But now I get to see the full list every time
> I hit TAB in emacs. So thanks!
> 
> I do still want to unify search, search-messages, search-tags, count,
> etc. But I've gone ahead and merged this whole series as-is to get the
> functionality out there for now.

Oh, that's great, my first bigger contribution to nutmuch is in the
repository, thanks so much! 

I was just thinking about giving you some time to catch up and review all the
patches, but now I have a reason to send more again ;-).

> I assume that everyone is aware that I'm reserving the right to change
> the library and command-line interface as much as I want right now.

Yeah, I personally have no problem with that. In fact I like it.

I think that not having the user interface fixed is a good thing at this early
stage. This is what makes notmuch so hackable :-), contributors like me don't
have to worry about breaking things (at least not too much).

From my point of view, notmuch is still missing some important features. Also,
there is a bunch of people writing front-ends and they'll probably ask for
more, too. Personally, I think it would make sense to add what is missing and,
once you feel that notuch is reasonably feature-complete, you can design nice
and intuitive user interface for it.

I'd be happy to help you update the code that I contributed once you decide to
change the command-line interface.

> If you've got code or scripts that depend on these interfaces, I highly
> recommend that you get them contributed to the notmuch repository so
> that we can fix them up as we rework the library and command line.

Yeah, I will.

> (So, Bart, I'll merge the vim stuff which is using "notmuch count"
> before I change that, so I can fixup the vim stuff at the same time.)
> 
> Thanks again, Jan! Well done.

Thanks for starting notmuch! I've been working on converting my 4GB mailbox
with about a hundred tags from gmail to notmuch and while I am not there yet,
I've made some good progress recently. That makes me really optimistic; I
tried various other mail indexing tools before and never got that far.

-Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] notmuch.el: Select tag names with completion.
  2009-11-27 11:30       ` Jan Janak
@ 2009-11-28  4:10         ` Carl Worth
  0 siblings, 0 replies; 9+ messages in thread
From: Carl Worth @ 2009-11-28  4:10 UTC (permalink / raw)
  To: Jan Janak; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

On Fri, 27 Nov 2009 12:30:38 +0100, Jan Janak <jan@ryngle.com> wrote:
> Oh, that's great, my first bigger contribution to nutmuch is in the
> repository, thanks so much! 

You're quite welcome.

> I was just thinking about giving you some time to catch up and review all the
> patches, but now I have a reason to send more again ;-).

Yes, please don't slow down. Like Keith recently mentioned to me---one
drawback with notmuch is that it makes it so easy and fun to get
through mail that you quickly end up without any mail and don't get to
play with notmuch anymore.

> Thanks for starting notmuch! I've been working on converting my 4GB mailbox
> with about a hundred tags from gmail to notmuch and while I am not there yet,
> I've made some good progress recently. That makes me really optimistic; I
> tried various other mail indexing tools before and never got that far.

Good luck with that! I know that the period of transitioning from one
mail system to another can be extremely painful. I hope you get through
it alright and end up better for it.

Happy hacking,

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-11-28  4:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-23  0:10 [PATCH 1/3] notmuch: New function to retrieve all tags from the database Jan Janak
2009-11-23  0:10 ` [PATCH 2/3] notmuch: New command 'search-tags' Jan Janak
2009-11-23  0:10   ` [PATCH 3/3] notmuch.el: Select tag names with completion Jan Janak
2009-11-25  4:05     ` [PATCH] notmuch.el: When removing tags, offer only those a msg/thread has set Jan Janak
2009-11-26 15:15     ` [PATCH 3/3] notmuch.el: Select tag names with completion Carl Worth
2009-11-27 11:30       ` Jan Janak
2009-11-28  4:10         ` Carl Worth
2009-11-25  3:30   ` [PATCH 1/2] lib: New function to collect tags from a list of messages Jan Janak
2009-11-25  3:30     ` [PATCH 2/2] search-tags: Add support for search-terms Jan Janak

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).