[RFC][PATCH v2] emacs: Replace `notmuch-search-result-format' evaluation.

2014-11-25 Thread David Edmondson
Alternative implementation of code that interprets
`notmuch-search-result-format' to insert the results of a search.
---

Added some more documentation, as per bremner.

 emacs/notmuch.el | 300 +--
 1 file changed, 178 insertions(+), 122 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 218486a..eb79a29 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -66,23 +66,103 @@
 "Placeholder variable when notmuch-version.el[c] is not available."))

 (defcustom notmuch-search-result-format
-  `(("date" . "%12s ")
-("count" . "%-7s ")
-("authors" . "%-20s ")
-("subject" . "%s ")
-("tags" . "(%s)"))
-  "Search result formatting. Supported fields are:
-   date, count, authors, subject, tags
-For example:
-   (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
-\(\"subject\" . \"%s\"\)\)\)
-Line breaks are permitted in format strings (though this is
-currently experimental).  Note that a line break at the end of an
-\"authors\" field will get elided if the authors list is long;
-place it instead at the beginning of the following field.  To
-enter a line break when setting this variable with setq, use \\n.
-To enter a line break in customize, press \\[quoted-insert] C-j."
-  :type '(alist :key-type (string) :value-type (string))
+  '((:width -12 :date_relative) " "
+(:width -7 (:concat "[" :matched "/" :total "]")) " "
+;; This splitting will not be necessary once
+;; id:1414172643-28270-1-git-send-email-dme at dme.org is integrated.
+(:width 40 (:eval (let* ((split-authors (split-string
+(plist-get notmuch-thread :authors)
+"|" t 
split-string-default-separators))
+;; There will always be matched authors.
+(matched-authors (car split-authors))
+;; There may not be non-matched authors.
+(non-matched-authors (mapconcat #'identity (cdr 
split-authors) " ")))
+   (notmuch-search-format-authors matched-authors 
non-matched-authors " "
+:subject " "
+"(" (:eval (notmuch-tag-format-tags (plist-get notmuch-thread :tags)
+   (plist-get notmuch-thread :orig-tags)))
+")" "\n")
+
+  "Template for displaying search results.
+
+The value is a list of items to insert in the search
+results. Individual items should be in one of the following
+forms:
+
+A string that is inserted directly (e.g. \" \").
+
+A number that is inserted directly (e.g. 5).
+
+A list that is recursively evaluated (e.g. `(:concat FORM1
+ FORM2)').
+
+A function that is evaluated with a single argument, the current
+ thread.
+
+A symbol corresponding to an attribute of the
+ thread. Currently available attributes include:
+
+ :date_relative -- a user-readable rendering of the Date: header
+ of the first matching message in the thread, as a string.
+
+ :timestamp -- the number of seconds since the Epoch, 1970-01-01
+ 00:00:00 + (UTC), corresponding to the Date: header of the
+ first matching message in the thread.
+
+ :subject -- the subject of the first matching message in the
+ thread as a string.
+
+ :authors -- a comma separated string containing a list of the
+ authors of messages in the thread. If there are non-matching
+ authors (i.e. the thread contains messages which did not match
+ the search terms and those messages have authors who are not
+ also authors of messages that did match the search terms) then
+ the matching and non-matching authors are separated by a `|'
+ symbol in the results in place of a comma.
+
+ :matched -- the number of messages that matched search terms in
+ the thread (a number).
+
+ :total -- the total number of messages in the thread (i.e. the
+ count of both matching and non-matching messages).
+
+ :tags -- a list of tags associated with messages in the
+ thread. Each tag is included as a distinct string.
+
+ :orig-tags -- a list of tags that were associated with messages
+ in the thread when the search originally took place.
+
+ :query -- a list with two elements. The first element is a query
+ string that will return all of the matching messages in the
+ current thread. The second element is a query string that will
+ return all of the non-matching messages in the current thread.
+
+ :thread -- the thread id of the matching thread, as a string.
+
+ For a full list of the attributes available, see the source code
+ for notmuch itself.
+
+A directive that describes how to evaluate the remainder of the
+ list. The following directives are available:
+
+ `:concat FORM...' -- evaluate each element of FORM and return
+ the concatenated results.
+
+ `:width WIDTH FORM' -- evaluate FORM and return the result
+ truncated to WIDTH characters. The result will be padded with
+ spaces to WIDTH 

[RFC][PATCH v2] emacs: Replace `notmuch-search-result-format' evaluation.

2014-11-25 Thread David Edmondson
Alternative implementation of code that interprets
`notmuch-search-result-format' to insert the results of a search.
---

Added some more documentation, as per bremner.

 emacs/notmuch.el | 300 +--
 1 file changed, 178 insertions(+), 122 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 218486a..eb79a29 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -66,23 +66,103 @@
 "Placeholder variable when notmuch-version.el[c] is not available."))
 
 (defcustom notmuch-search-result-format
-  `(("date" . "%12s ")
-("count" . "%-7s ")
-("authors" . "%-20s ")
-("subject" . "%s ")
-("tags" . "(%s)"))
-  "Search result formatting. Supported fields are:
-   date, count, authors, subject, tags
-For example:
-   (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
-\(\"subject\" . \"%s\"\)\)\)
-Line breaks are permitted in format strings (though this is
-currently experimental).  Note that a line break at the end of an
-\"authors\" field will get elided if the authors list is long;
-place it instead at the beginning of the following field.  To
-enter a line break when setting this variable with setq, use \\n.
-To enter a line break in customize, press \\[quoted-insert] C-j."
-  :type '(alist :key-type (string) :value-type (string))
+  '((:width -12 :date_relative) " "
+(:width -7 (:concat "[" :matched "/" :total "]")) " "
+;; This splitting will not be necessary once
+;; id:1414172643-28270-1-git-send-email-...@dme.org is integrated.
+(:width 40 (:eval (let* ((split-authors (split-string
+(plist-get notmuch-thread :authors)
+"|" t 
split-string-default-separators))
+;; There will always be matched authors.
+(matched-authors (car split-authors))
+;; There may not be non-matched authors.
+(non-matched-authors (mapconcat #'identity (cdr 
split-authors) " ")))
+   (notmuch-search-format-authors matched-authors 
non-matched-authors " "
+:subject " "
+"(" (:eval (notmuch-tag-format-tags (plist-get notmuch-thread :tags)
+   (plist-get notmuch-thread :orig-tags)))
+")" "\n")
+
+  "Template for displaying search results.
+
+The value is a list of items to insert in the search
+results. Individual items should be in one of the following
+forms:
+
+A string that is inserted directly (e.g. \" \").
+
+A number that is inserted directly (e.g. 5).
+
+A list that is recursively evaluated (e.g. `(:concat FORM1
+ FORM2)').
+
+A function that is evaluated with a single argument, the current
+ thread.
+
+A symbol corresponding to an attribute of the
+ thread. Currently available attributes include:
+
+ :date_relative -- a user-readable rendering of the Date: header
+ of the first matching message in the thread, as a string.
+
+ :timestamp -- the number of seconds since the Epoch, 1970-01-01
+ 00:00:00 + (UTC), corresponding to the Date: header of the
+ first matching message in the thread.
+
+ :subject -- the subject of the first matching message in the
+ thread as a string.
+
+ :authors -- a comma separated string containing a list of the
+ authors of messages in the thread. If there are non-matching
+ authors (i.e. the thread contains messages which did not match
+ the search terms and those messages have authors who are not
+ also authors of messages that did match the search terms) then
+ the matching and non-matching authors are separated by a `|'
+ symbol in the results in place of a comma.
+
+ :matched -- the number of messages that matched search terms in
+ the thread (a number).
+
+ :total -- the total number of messages in the thread (i.e. the
+ count of both matching and non-matching messages).
+
+ :tags -- a list of tags associated with messages in the
+ thread. Each tag is included as a distinct string.
+
+ :orig-tags -- a list of tags that were associated with messages
+ in the thread when the search originally took place.
+
+ :query -- a list with two elements. The first element is a query
+ string that will return all of the matching messages in the
+ current thread. The second element is a query string that will
+ return all of the non-matching messages in the current thread.
+
+ :thread -- the thread id of the matching thread, as a string.
+
+ For a full list of the attributes available, see the source code
+ for notmuch itself.
+
+A directive that describes how to evaluate the remainder of the
+ list. The following directives are available:
+
+ `:concat FORM...' -- evaluate each element of FORM and return
+ the concatenated results.
+
+ `:width WIDTH FORM' -- evaluate FORM and return the result
+ truncated to WIDTH characters. The result will be padded with
+ spaces to WIDTH ch