* [PATCH v1 0/3] Improve the display of matching/non-matching authors.
@ 2014-10-24 8:48 David Edmondson
2014-10-24 8:48 ` [PATCH v1 1/3] search: Seperately report matching and non-matching authors David Edmondson
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: David Edmondson @ 2014-10-24 8:48 UTC (permalink / raw)
To: notmuch
Improve the display of matching/non-matching authors.
Distinguishing between matching and non-matching authors in the emacs
interface is currently done by parsing the :authors attribute of a
search result. If one of the authors uses the pipe symbol (|) in their
'From' address this parsing incorrectly determines the matching and
non-matching authors.
Address this by adding explicit matching and non-matching authors
attributes to the structured output formats.
David Edmondson (3):
search: Seperately report matching and non-matching authors.
emacs: Improved display of matching/non-matching authors.
test: Update tests for :authors_matched and :authors_non_matched.
emacs/notmuch.el | 64 ++++++++++++++++++++++++--------------------
lib/notmuch.h | 34 +++++++++++++++++++++++
lib/thread.cc | 60 ++++++++++++++++++++++++++++-------------
notmuch-search.c | 6 +++++
test/T160-json.sh | 4 +++
test/T170-sexp.sh | 4 +--
test/T470-missing-headers.sh | 4 +++
7 files changed, 127 insertions(+), 49 deletions(-)
--
2.1.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/3] search: Seperately report matching and non-matching authors.
2014-10-24 8:48 [PATCH v1 0/3] Improve the display of matching/non-matching authors David Edmondson
@ 2014-10-24 8:48 ` David Edmondson
2014-10-24 9:23 ` Mark Walters
2014-10-24 8:48 ` [PATCH v1 2/3] emacs: Improved display of matching/non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 3/3] test: Update tests for :authors_matched and :authors_non_matched David Edmondson
2 siblings, 1 reply; 7+ messages in thread
From: David Edmondson @ 2014-10-24 8:48 UTC (permalink / raw)
To: notmuch
In addition to the :authors attribute of each search result, include
:authors_matched and :authors_non_matched attributes. Both attributes
are always included. If there are no non-matching authors, the
:authors_non_matched attribute is set to the empty string.
---
lib/notmuch.h | 34 ++++++++++++++++++++++++++++++++
lib/thread.cc | 60 +++++++++++++++++++++++++++++++++++++++-----------------
notmuch-search.c | 6 ++++++
3 files changed, 82 insertions(+), 18 deletions(-)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index dae0416..30ce6c3 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -993,6 +993,40 @@ const char *
notmuch_thread_get_authors (notmuch_thread_t *thread);
/**
+ * Get the matched authors of 'thread' as a UTF-8 string.
+ *
+ * The returned string is a comma-separated list of the names of the
+ * authors of mail messages in the query results that belong to this
+ * thread.
+ *
+ * Authors are ordered by date.
+ *
+ * The returned string belongs to 'thread' and as such, should not be
+ * modified by the caller and will only be valid for as long as the
+ * thread is valid, (which is until notmuch_thread_destroy or until
+ * the query from which it derived is destroyed).
+ */
+const char *
+notmuch_thread_get_authors_matched (notmuch_thread_t *thread);
+
+/**
+ * Get the non-matched authors of 'thread' as a UTF-8 string.
+ *
+ * The returned string is a comma-separated list of the names of the
+ * authors of mail messages in the query results that belong to this
+ * thread.
+ *
+ * Authors are ordered by date.
+ *
+ * The returned string belongs to 'thread' and as such, should not be
+ * modified by the caller and will only be valid for as long as the
+ * thread is valid, (which is until notmuch_thread_destroy or until
+ * the query from which it derived is destroyed).
+ */
+const char *
+notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread);
+
+/**
* Get the subject of 'thread' as a UTF-8 string.
*
* The subject is taken from the first message (according to the query
diff --git a/lib/thread.cc b/lib/thread.cc
index 8922403..b344875 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -33,6 +33,8 @@ struct visible _notmuch_thread {
GHashTable *matched_authors_hash;
GPtrArray *matched_authors_array;
char *authors;
+ char *authors_matched;
+ char *authors_non_matched;
GHashTable *tags;
/* All messages, oldest first. */
@@ -112,10 +114,11 @@ _thread_add_matched_author (notmuch_thread_t *thread,
g_ptr_array_add (thread->matched_authors_array, author_copy);
}
-/* Construct an authors string from matched_authors_array and
- * authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+/* Construct the authors_matched, authors_non_matched and authors
+ * strings from matched_authors_array and authors_array. The authors
+ * string contains matched authors first, then non-matched authors
+ * (with the two groups separated by '|'). Within each group, authors
+ * are listed in date order. */
static void
_resolve_thread_authors_string (notmuch_thread_t *thread)
{
@@ -123,36 +126,43 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
char *author;
int first_non_matched_author = 1;
- /* First, list all matched authors in date order. */
+ /* List all matched authors in date order. */
for (i = 0; i < thread->matched_authors_array->len; i++) {
author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
- if (thread->authors)
- thread->authors = talloc_asprintf (thread, "%s, %s",
- thread->authors,
- author);
- else
- thread->authors = author;
+ if (thread->authors_matched) {
+ thread->authors_matched = talloc_asprintf (thread, "%s, %s",
+ thread->authors_matched,
+ author);
+ } else {
+ thread->authors_matched = author;
+ }
}
- /* Next, append any non-matched authors that haven't already appeared. */
+ /* List any non-matched authors that haven't already appeared. */
for (i = 0; i < thread->authors_array->len; i++) {
author = (char *) g_ptr_array_index (thread->authors_array, i);
if (g_hash_table_lookup_extended (thread->matched_authors_hash,
author, NULL, NULL))
continue;
if (first_non_matched_author) {
- thread->authors = talloc_asprintf (thread, "%s| %s",
- thread->authors,
- author);
+ thread->authors_non_matched = author;
} else {
- thread->authors = talloc_asprintf (thread, "%s, %s",
- thread->authors,
- author);
+ thread->authors_non_matched = talloc_asprintf (thread, "%s, %s",
+ thread->authors_non_matched,
+ author);
}
first_non_matched_author = 0;
}
+ /* List both matched and any non-matched authors. */
+ if (thread->authors_non_matched)
+ thread->authors = talloc_asprintf (thread, "%s| %s",
+ thread->authors_matched,
+ thread->authors_non_matched);
+ else
+ thread->authors = thread->authors_matched;
+
g_ptr_array_free (thread->authors_array, TRUE);
thread->authors_array = NULL;
g_ptr_array_free (thread->matched_authors_array, TRUE);
@@ -473,6 +483,8 @@ _notmuch_thread_create (void *ctx,
NULL, NULL);
thread->matched_authors_array = g_ptr_array_new ();
thread->authors = NULL;
+ thread->authors_matched = NULL;
+ thread->authors_non_matched = NULL;
thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
free, NULL);
@@ -568,6 +580,18 @@ notmuch_thread_get_authors (notmuch_thread_t *thread)
}
const char *
+notmuch_thread_get_authors_matched (notmuch_thread_t *thread)
+{
+ return thread->authors_matched;
+}
+
+const char *
+notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread)
+{
+ return thread->authors_non_matched;
+}
+
+const char *
notmuch_thread_get_subject (notmuch_thread_t *thread)
{
return thread->subject;
diff --git a/notmuch-search.c b/notmuch-search.c
index bc9be45..f1b096d 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -114,6 +114,8 @@ do_search_threads (sprinter_t *format,
} else { /* output == OUTPUT_SUMMARY */
void *ctx_quote = talloc_new (thread);
const char *authors = notmuch_thread_get_authors (thread);
+ const char *authors_matched = notmuch_thread_get_authors_matched (thread);
+ const char *authors_non_matched = notmuch_thread_get_authors_non_matched (thread);
const char *subject = notmuch_thread_get_subject (thread);
const char *thread_id = notmuch_thread_get_thread_id (thread);
int matched = notmuch_thread_get_matched_messages (thread);
@@ -152,6 +154,10 @@ do_search_threads (sprinter_t *format,
format->integer (format, total);
format->map_key (format, "authors");
format->string (format, authors);
+ format->map_key (format, "authors_matched");
+ format->string (format, authors_matched);
+ format->map_key (format, "authors_non_matched");
+ format->string (format, authors_non_matched);
format->map_key (format, "subject");
format->string (format, subject);
if (notmuch_format_version >= 2) {
--
2.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/3] emacs: Improved display of matching/non-matching authors.
2014-10-24 8:48 [PATCH v1 0/3] Improve the display of matching/non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 1/3] search: Seperately report matching and non-matching authors David Edmondson
@ 2014-10-24 8:48 ` David Edmondson
2014-10-24 8:48 ` [PATCH v1 3/3] test: Update tests for :authors_matched and :authors_non_matched David Edmondson
2 siblings, 0 replies; 7+ messages in thread
From: David Edmondson @ 2014-10-24 8:48 UTC (permalink / raw)
To: notmuch
Rather than splitting the :authors attribute, which is error prone,
use the separate :authors_matched and :authors_non_matched attributes.
This improves the display of authors should one of them include a pipe
symbol (|) in their 'from' address.
---
emacs/notmuch.el | 64 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 35 insertions(+), 29 deletions(-)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index b44a907..29b6cdc 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -672,22 +672,24 @@ foreground and blue background."
;; Reverse the list so earlier entries take precedence
(reverse notmuch-search-line-faces)))
-(defun notmuch-search-author-propertize (authors)
+(defun notmuch-search-author-propertize (authors matching-length)
"Split `authors' into matching and non-matching authors and
propertize appropriately. If no boundary between authors and
non-authors is found, assume that all of the authors match."
- (if (string-match "\\(.*\\)|\\(.*\\)" authors)
- (concat (propertize (concat (match-string 1 authors) ",")
- 'face 'notmuch-search-matching-authors)
- (propertize (match-string 2 authors)
- 'face 'notmuch-search-non-matching-authors))
- (propertize authors 'face 'notmuch-search-matching-authors)))
-
-(defun notmuch-search-insert-authors (format-string authors)
+ (let ((match-part (substring authors 0 matching-length))
+ (non-match-part (substring authors matching-length)))
+
+ (concat (propertize match-part 'face 'notmuch-search-matching-authors)
+ (propertize non-match-part 'face 'notmuch-search-non-matching-authors))))
+
+(defun notmuch-search-insert-authors (format-string matching-authors non-matching-authors)
;; Save the match data to avoid interfering with
;; `notmuch-search-process-filter'.
(save-match-data
- (let* ((formatted-authors (format format-string authors))
+ (let* ((authors (if (string= "" non-matching-authors)
+ matching-authors
+ (concat matching-authors ", " non-matching-authors)))
+ (formatted-authors (format format-string authors))
(formatted-sample (format format-string ""))
(visible-string formatted-authors)
(invisible-string "")
@@ -703,9 +705,9 @@ non-authors is found, assume that all of the authors match."
(setq visible-string (substring formatted-authors 0 visible-length)
invisible-string (substring formatted-authors visible-length))
;; If possible, truncate the visible string at a natural
- ;; break (comma or pipe), as incremental search doesn't
- ;; match across the visible/invisible border.
- (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)
+ ;; break (comma), as incremental search doesn't match
+ ;; across the visible/invisible border.
+ (when (string-match "\\(.*\\)\\(, \\)\\([^,]*\\)" visible-string)
;; Second clause is destructive on `visible-string', so
;; order is important.
(setq invisible-string (concat (match-string 3 visible-string)
@@ -721,20 +723,23 @@ non-authors is found, assume that all of the authors match."
? ))))
;; Use different faces to show matching and non-matching authors.
- (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)
- ;; The visible string contains both matching and
- ;; non-matching authors.
- (setq visible-string (notmuch-search-author-propertize visible-string)
- ;; The invisible string must contain only non-matching
- ;; authors, as the visible-string contains both.
- invisible-string (propertize invisible-string
- 'face 'notmuch-search-non-matching-authors))
- ;; The visible string contains only matching authors.
- (setq visible-string (propertize visible-string
- 'face 'notmuch-search-matching-authors)
- ;; The invisible string may contain both matching and
- ;; non-matching authors.
- invisible-string (notmuch-search-author-propertize invisible-string)))
+ (let ((visible-length (length visible-string))
+ (matching-length (length matching-authors)))
+
+ (if (> visible-length matching-length)
+ ;; The visible string contains both matching and
+ ;; non-matching authors.
+ (setq visible-string (notmuch-search-author-propertize visible-string matching-length)
+ ;; The invisible string must contain only non-matching
+ ;; authors, as the visible-string contains both.
+ invisible-string (propertize invisible-string
+ 'face 'notmuch-search-non-matching-authors))
+ ;; The visible string contains only matching authors.
+ (setq visible-string (propertize visible-string
+ 'face 'notmuch-search-matching-authors)
+ ;; The invisible string may contain both matching and
+ ;; non-matching authors.
+ invisible-string (notmuch-search-author-propertize invisible-string (- visible-length matching-length)))))
;; If there is any invisible text, add it as a tooltip to the
;; visible text.
@@ -768,8 +773,9 @@ non-authors is found, assume that all of the authors match."
'face 'notmuch-search-subject)))
((string-equal field "authors")
- (notmuch-search-insert-authors
- format-string (notmuch-sanitize (plist-get result :authors))))
+ (notmuch-search-insert-authors format-string
+ (notmuch-sanitize (plist-get result :authors_matched))
+ (notmuch-sanitize (plist-get result :authors_non_matched))))
((string-equal field "tags")
(let ((tags (plist-get result :tags))
--
2.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 3/3] test: Update tests for :authors_matched and :authors_non_matched.
2014-10-24 8:48 [PATCH v1 0/3] Improve the display of matching/non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 1/3] search: Seperately report matching and non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 2/3] emacs: Improved display of matching/non-matching authors David Edmondson
@ 2014-10-24 8:48 ` David Edmondson
2 siblings, 0 replies; 7+ messages in thread
From: David Edmondson @ 2014-10-24 8:48 UTC (permalink / raw)
To: notmuch
---
test/T160-json.sh | 4 ++++
test/T170-sexp.sh | 4 ++--
| 4 ++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/test/T160-json.sh b/test/T160-json.sh
index c1cf649..d3cf2e7 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -25,6 +25,8 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\"matched\": 1,
\"total\": 1,
\"authors\": \"Notmuch Test Suite\",
+ \"authors_matched\": \"Notmuch Test Suite\",
+ \"authors_non_matched\": \"\",
\"subject\": \"json-search-subject\",
\"query\": [\"id:$gen_msg_id\", null],
\"tags\": [\"inbox\",
@@ -59,6 +61,8 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
\"matched\": 1,
\"total\": 1,
\"authors\": \"Notmuch Test Suite\",
+ \"authors_matched\": \"Notmuch Test Suite\",
+ \"authors_non_matched\": \"\",
\"subject\": \"json-search-utf8-body-sübjéct\",
\"query\": [\"id:$gen_msg_id\", null],
\"tags\": [\"inbox\",
diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
index 667e319..8a57b74 100755
--- a/test/T170-sexp.sh
+++ b/test/T170-sexp.sh
@@ -19,7 +19,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" :match t :excluded nil :f
test_begin_subtest "Search message: sexp"
add_message "[subject]=\"sexp-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"sexp-search-message\""
output=$(notmuch search --format=sexp "sexp-search-message" | notmuch_search_sanitize)
-test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
+test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :authors_matched \"Notmuch Test Suite\" :authors_non_matched \"\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
test_begin_subtest "Show message: sexp, utf-8"
add_message "[subject]=\"sexp-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
@@ -44,7 +44,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"
test_begin_subtest "Search message: sexp, utf-8"
add_message "[subject]=\"sexp-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
output=$(notmuch search --format=sexp "jsön-search-méssage" | notmuch_search_sanitize)
-test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-utf8-body-sübjéct\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
+test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :authors_matched \"Notmuch Test Suite\" :authors_non_matched \"\" :subject \"sexp-search-utf8-body-sübjéct\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"
test_done
--git a/test/T470-missing-headers.sh b/test/T470-missing-headers.sh
index cb38301..5d66e7e 100755
--- a/test/T470-missing-headers.sh
+++ b/test/T470-missing-headers.sh
@@ -34,6 +34,8 @@ test_expect_equal_json "$output" '
[
{
"authors": "",
+ "authors_matched": "",
+ "authors_non_matched": "",
"date_relative": "2001-01-05",
"matched": 1,
"subject": "",
@@ -48,6 +50,8 @@ test_expect_equal_json "$output" '
},
{
"authors": "Notmuch Test Suite",
+ "authors_matched": "Notmuch Test Suite",
+ "authors_non_matched": "",
"date_relative": "1970-01-01",
"matched": 1,
"subject": "",
--
2.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/3] search: Seperately report matching and non-matching authors.
2014-10-24 8:48 ` [PATCH v1 1/3] search: Seperately report matching and non-matching authors David Edmondson
@ 2014-10-24 9:23 ` Mark Walters
2014-10-24 10:21 ` David Edmondson
2014-10-24 12:40 ` Austin Clements
0 siblings, 2 replies; 7+ messages in thread
From: Mark Walters @ 2014-10-24 9:23 UTC (permalink / raw)
To: David Edmondson, notmuch
Hi
I definitely like the idea: some comments below.
On Fri, 24 Oct 2014, David Edmondson <dme@dme.org> wrote:
> In addition to the :authors attribute of each search result, include
> :authors_matched and :authors_non_matched attributes. Both attributes
> are always included. If there are no non-matching authors, the
> :authors_non_matched attribute is set to the empty string.
What about having both authors_matched and authors_not_matched as lists
of authors (ie one string for each author)? Then emacs, for example,
wouldn't try and parse the string back into authors before
splitting. And authors_non_matched could be an empty list when
appropriate which seems more natural than the empty string.
All the above is based on what a client might want in the output rather
than what is easy or sensible to implement in the C code.
> ---
> lib/notmuch.h | 34 ++++++++++++++++++++++++++++++++
> lib/thread.cc | 60 +++++++++++++++++++++++++++++++++++++++-----------------
> notmuch-search.c | 6 ++++++
> 3 files changed, 82 insertions(+), 18 deletions(-)
>
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index dae0416..30ce6c3 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -993,6 +993,40 @@ const char *
> notmuch_thread_get_authors (notmuch_thread_t *thread);
>
> /**
> + * Get the matched authors of 'thread' as a UTF-8 string.
> + *
> + * The returned string is a comma-separated list of the names of the
> + * authors of mail messages in the query results that belong to this
> + * thread.
> + *
> + * Authors are ordered by date.
> + *
> + * The returned string belongs to 'thread' and as such, should not be
> + * modified by the caller and will only be valid for as long as the
> + * thread is valid, (which is until notmuch_thread_destroy or until
> + * the query from which it derived is destroyed).
> + */
> +const char *
> +notmuch_thread_get_authors_matched (notmuch_thread_t *thread);
> +
> +/**
> + * Get the non-matched authors of 'thread' as a UTF-8 string.
> + *
> + * The returned string is a comma-separated list of the names of the
> + * authors of mail messages in the query results that belong to this
> + * thread.
> + *
> + * Authors are ordered by date.
> + *
> + * The returned string belongs to 'thread' and as such, should not be
> + * modified by the caller and will only be valid for as long as the
> + * thread is valid, (which is until notmuch_thread_destroy or until
> + * the query from which it derived is destroyed).
> + */
> +const char *
> +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread);
> +
> +/**
> * Get the subject of 'thread' as a UTF-8 string.
> *
> * The subject is taken from the first message (according to the query
> diff --git a/lib/thread.cc b/lib/thread.cc
> index 8922403..b344875 100644
> --- a/lib/thread.cc
> +++ b/lib/thread.cc
> @@ -33,6 +33,8 @@ struct visible _notmuch_thread {
> GHashTable *matched_authors_hash;
> GPtrArray *matched_authors_array;
> char *authors;
> + char *authors_matched;
> + char *authors_non_matched;
> GHashTable *tags;
>
> /* All messages, oldest first. */
> @@ -112,10 +114,11 @@ _thread_add_matched_author (notmuch_thread_t *thread,
> g_ptr_array_add (thread->matched_authors_array, author_copy);
> }
>
> -/* Construct an authors string from matched_authors_array and
> - * authors_array. The string contains matched authors first, then
> - * non-matched authors (with the two groups separated by '|'). Within
> - * each group, authors are listed in date order. */
> +/* Construct the authors_matched, authors_non_matched and authors
> + * strings from matched_authors_array and authors_array. The authors
> + * string contains matched authors first, then non-matched authors
> + * (with the two groups separated by '|'). Within each group, authors
> + * are listed in date order. */
> static void
> _resolve_thread_authors_string (notmuch_thread_t *thread)
> {
> @@ -123,36 +126,43 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
> char *author;
> int first_non_matched_author = 1;
>
> - /* First, list all matched authors in date order. */
> + /* List all matched authors in date order. */
> for (i = 0; i < thread->matched_authors_array->len; i++) {
> author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
> - if (thread->authors)
> - thread->authors = talloc_asprintf (thread, "%s, %s",
> - thread->authors,
> - author);
> - else
> - thread->authors = author;
> + if (thread->authors_matched) {
> + thread->authors_matched = talloc_asprintf (thread, "%s, %s",
> + thread->authors_matched,
> + author);
> + } else {
> + thread->authors_matched = author;
> + }
> }
>
> - /* Next, append any non-matched authors that haven't already appeared. */
> + /* List any non-matched authors that haven't already appeared. */
> for (i = 0; i < thread->authors_array->len; i++) {
> author = (char *) g_ptr_array_index (thread->authors_array, i);
> if (g_hash_table_lookup_extended (thread->matched_authors_hash,
> author, NULL, NULL))
> continue;
> if (first_non_matched_author) {
> - thread->authors = talloc_asprintf (thread, "%s| %s",
> - thread->authors,
> - author);
> + thread->authors_non_matched = author;
> } else {
> - thread->authors = talloc_asprintf (thread, "%s, %s",
> - thread->authors,
> - author);
> + thread->authors_non_matched = talloc_asprintf (thread, "%s, %s",
> + thread->authors_non_matched,
> + author);
> }
>
> first_non_matched_author = 0;
I think I would prefer to make this look like the matched case and drop
the first_non_matched_author stuff.
Best wishes
Mark
> }
>
> + /* List both matched and any non-matched authors. */
> + if (thread->authors_non_matched)
> + thread->authors = talloc_asprintf (thread, "%s| %s",
> + thread->authors_matched,
> + thread->authors_non_matched);
> + else
> + thread->authors = thread->authors_matched;
> +
> g_ptr_array_free (thread->authors_array, TRUE);
> thread->authors_array = NULL;
> g_ptr_array_free (thread->matched_authors_array, TRUE);
> @@ -473,6 +483,8 @@ _notmuch_thread_create (void *ctx,
> NULL, NULL);
> thread->matched_authors_array = g_ptr_array_new ();
> thread->authors = NULL;
> + thread->authors_matched = NULL;
> + thread->authors_non_matched = NULL;
> thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
> free, NULL);
>
> @@ -568,6 +580,18 @@ notmuch_thread_get_authors (notmuch_thread_t *thread)
> }
>
> const char *
> +notmuch_thread_get_authors_matched (notmuch_thread_t *thread)
> +{
> + return thread->authors_matched;
> +}
> +
> +const char *
> +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread)
> +{
> + return thread->authors_non_matched;
> +}
> +
> +const char *
> notmuch_thread_get_subject (notmuch_thread_t *thread)
> {
> return thread->subject;
> diff --git a/notmuch-search.c b/notmuch-search.c
> index bc9be45..f1b096d 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -114,6 +114,8 @@ do_search_threads (sprinter_t *format,
> } else { /* output == OUTPUT_SUMMARY */
> void *ctx_quote = talloc_new (thread);
> const char *authors = notmuch_thread_get_authors (thread);
> + const char *authors_matched = notmuch_thread_get_authors_matched (thread);
> + const char *authors_non_matched = notmuch_thread_get_authors_non_matched (thread);
> const char *subject = notmuch_thread_get_subject (thread);
> const char *thread_id = notmuch_thread_get_thread_id (thread);
> int matched = notmuch_thread_get_matched_messages (thread);
> @@ -152,6 +154,10 @@ do_search_threads (sprinter_t *format,
> format->integer (format, total);
> format->map_key (format, "authors");
> format->string (format, authors);
> + format->map_key (format, "authors_matched");
> + format->string (format, authors_matched);
> + format->map_key (format, "authors_non_matched");
> + format->string (format, authors_non_matched);
> format->map_key (format, "subject");
> format->string (format, subject);
> if (notmuch_format_version >= 2) {
> --
> 2.1.1
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/3] search: Seperately report matching and non-matching authors.
2014-10-24 9:23 ` Mark Walters
@ 2014-10-24 10:21 ` David Edmondson
2014-10-24 12:40 ` Austin Clements
1 sibling, 0 replies; 7+ messages in thread
From: David Edmondson @ 2014-10-24 10:21 UTC (permalink / raw)
To: Mark Walters, notmuch
On Fri, Oct 24 2014, Mark Walters wrote:
> What about having both authors_matched and authors_not_matched as lists
> of authors (ie one string for each author)?
That's a sensible idea. I will look into it.
> Then emacs, for example, wouldn't try and parse the string back into
> authors before splitting.
It doesn't really do that other than to decide where to truncate the
visible string. That whole chunk of code is horrible.
>> first_non_matched_author = 0;
>
> I think I would prefer to make this look like the matched case and drop
> the first_non_matched_author stuff.
Agreed, will do.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/3] search: Seperately report matching and non-matching authors.
2014-10-24 9:23 ` Mark Walters
2014-10-24 10:21 ` David Edmondson
@ 2014-10-24 12:40 ` Austin Clements
1 sibling, 0 replies; 7+ messages in thread
From: Austin Clements @ 2014-10-24 12:40 UTC (permalink / raw)
To: David Edmondson; +Cc: notmuch
Quoth Mark Walters on Oct 24 at 10:23 am:
>
> Hi
>
> I definitely like the idea: some comments below.
Agreed.
> On Fri, 24 Oct 2014, David Edmondson <dme@dme.org> wrote:
> > In addition to the :authors attribute of each search result, include
> > :authors_matched and :authors_non_matched attributes. Both attributes
> > are always included. If there are no non-matching authors, the
> > :authors_non_matched attribute is set to the empty string.
>
> What about having both authors_matched and authors_not_matched as lists
> of authors (ie one string for each author)? Then emacs, for example,
> wouldn't try and parse the string back into authors before
> splitting. And authors_non_matched could be an empty list when
> appropriate which seems more natural than the empty string.
>
> All the above is based on what a client might want in the output rather
> than what is easy or sensible to implement in the C code.
I was going to suggest exactly the same thing.
And I think there's a fairly easy way to do it in C code that will
also prevent library interface bloat: instead of introducing new
library APIs to get at this information, just use the existing
notmuch_thread_get_messages API and construct the matched and
non-matched lists in the CLI. Doing it in the CLI wouldn't require
the library to export yet another string list structure, which is
always a huge pain (thanks C!), and wouldn't introduce more "helper"
functions into the library API.
I think the only disadvantage to doing this would be some duplication
of the {matched_,}authors_{array,hash} logic into the CLI, but those
are only there to support notmuch_thread_get_authors, which I think is
a huge hack and should go away in the long term. (And, by doing this
list building in the CLI, we avoid further embellishing the
unnecessary "get thread authors" API).
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-10-24 12:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-24 8:48 [PATCH v1 0/3] Improve the display of matching/non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 1/3] search: Seperately report matching and non-matching authors David Edmondson
2014-10-24 9:23 ` Mark Walters
2014-10-24 10:21 ` David Edmondson
2014-10-24 12:40 ` Austin Clements
2014-10-24 8:48 ` [PATCH v1 2/3] emacs: Improved display of matching/non-matching authors David Edmondson
2014-10-24 8:48 ` [PATCH v1 3/3] test: Update tests for :authors_matched and :authors_non_matched David Edmondson
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).