--- /dev/null
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1B933431FC3\r
+ for <notmuch@notmuchmail.org>; Mon, 24 Nov 2014 02:44:43 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4lPDwKPrIUhH for <notmuch@notmuchmail.org>;\r
+ Mon, 24 Nov 2014 02:44:35 -0800 (PST)\r
+Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com\r
+ [209.85.212.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 726FE431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 24 Nov 2014 02:44:35 -0800 (PST)\r
+Received: by mail-wi0-f175.google.com with SMTP id l15so5192792wiw.2\r
+ for <notmuch@notmuchmail.org>; Mon, 24 Nov 2014 02:44:33 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:user-agent:from:to:subject:date:message-id;\r
+ bh=xjV5NQcf5hT6+6v4H6Ui+UknvaZ0tlFMq7h6dt3ftcw=;\r
+ b=IAUUXQTA8j3CT7nMULZx019XqFkLpngTHZkkuv3U/g4oHUDC0lLKi+ftRwMwPKhyjA\r
+ iZVMS62jmBwoU1grLVGHdPzIHfUx40priVekxgiMn/CM21Z1vWX6sBcgaUsHEnjWdjRf\r
+ GnbXuUZezDSnv5n45AQ8owQrsumKPiliIuDenbEv/RRFRkEzRxihngSwl3MNULRfMqaf\r
+ C2cf2+exXFYV5kJHDc4trLU2FFZYq8eWJe4brPaMiLlxZCHo3rsnHUvgrYqXVRbI4mS8\r
+ R5lu5EW83ZbKbHCnyhTboqof+gBPMhf7yytPexks/PYgzwDwlT2tpYnv1V5EJjkEuilY\r
+ r72g==\r
+X-Gm-Message-State:\r
+ ALoCoQnCVqWL8ShdLKZCLydMldj9U9lCgORb0ZjY4RU+ohyZ4d37v9Ume2/Gw0+xqxK3WpEFBYyd\r
+X-Received: by 10.194.81.70 with SMTP id y6mr31256421wjx.113.1416825872035;\r
+ Mon, 24 Nov 2014 02:44:32 -0800 (PST)\r
+Received: from disaster-area.hh.sledj.net\r
+ ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
+ by mx.google.com with ESMTPSA id\r
+ ec2sm11434921wib.23.2014.11.24.02.44.31 for <notmuch@notmuchmail.org>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Mon, 24 Nov 2014 02:44:31 -0800 (PST)\r
+Received: from localhost (30000@localhost [local]);\r
+ by localhost (OpenSMTPD) with ESMTPA id 1811d9ff;\r
+ for <notmuch@notmuchmail.org>; Mon, 24 Nov 2014 10:44:29 +0000 (UTC)\r
+User-Agent: OpenSMTPD enqueuer (Demoostik)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC][PATCH v1] emacs: Replace `notmuch-search-result-format'\r
+ evaluation.\r
+Date: Mon, 24 Nov 2014 10:44:29 +0000\r
+Message-Id: <1416825869-28472-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 2.1.3\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 24 Nov 2014 10:44:43 -0000\r
+\r
+Alternative implementation of code that interprets\r
+`notmuch-search-result-format' to insert the results of a search.\r
+---\r
+\r
+First pass at this. Thoughts?\r
+\r
+ emacs/notmuch.el | 260 +++++++++++++++++++++++++++++--------------------------\r
+ 1 file changed, 138 insertions(+), 122 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 218486a..0490936 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -66,23 +66,63 @@\r
+ "Placeholder variable when notmuch-version.el[c] is not available."))\r
+ \r
+ (defcustom notmuch-search-result-format\r
+- `(("date" . "%12s ")\r
+- ("count" . "%-7s ")\r
+- ("authors" . "%-20s ")\r
+- ("subject" . "%s ")\r
+- ("tags" . "(%s)"))\r
+- "Search result formatting. Supported fields are:\r
+- date, count, authors, subject, tags\r
+-For example:\r
+- (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
+- \(\"subject\" . \"%s\"\)\)\)\r
+-Line breaks are permitted in format strings (though this is\r
+-currently experimental). Note that a line break at the end of an\r
+-\"authors\" field will get elided if the authors list is long;\r
+-place it instead at the beginning of the following field. To\r
+-enter a line break when setting this variable with setq, use \\n.\r
+-To enter a line break in customize, press \\[quoted-insert] C-j."\r
+- :type '(alist :key-type (string) :value-type (string))\r
++ '((:width -12 :date_relative) " "\r
++ (:width -7 (:concat "[" :matched "/" :total "]")) " "\r
++ ;; This splitting will not be necessary once\r
++ ;; id:1414172643-28270-1-git-send-email-dme@dme.org is integrated.\r
++ (:width 40 (:eval (let* ((split-authors (split-string\r
++ (plist-get notmuch-thread :authors)\r
++ "|" t split-string-default-separators))\r
++ ;; There will always be matched authors.\r
++ (matched-authors (car split-authors))\r
++ ;; There may not be non-matched authors.\r
++ (non-matched-authors (mapconcat #'identity (cdr split-authors) " ")))\r
++ (notmuch-search-format-authors matched-authors non-matched-authors)))) " "\r
++ :subject " "\r
++ "(" (:eval (notmuch-tag-format-tags (plist-get notmuch-thread :tags)\r
++ (plist-get notmuch-thread :orig-tags)))\r
++ ")" "\n")\r
++\r
++ "Template for displaying search results.\r
++\r
++The value is a list of items to insert in the search\r
++results. Individual items should be in one of the following\r
++forms:\r
++\r
++A string that is inserted directly (e.g. \" \").\r
++\r
++A number that is inserted directly (e.g. 5).\r
++\r
++A list that is recursively evaluated (e.g. `(:concat FORM1\r
++ FORM2)').\r
++\r
++A function that is evaluated with a single argument, the current\r
++ thread.\r
++\r
++A symbol corresponding to an attribute of the\r
++ thread (e.g. `:date_relative' or `:subject').\r
++\r
++A directive that describes how to evaluate the remainder of the\r
++ list. The following directives are available:\r
++\r
++ `:concat FORM...' -- evaluate each element of FORM and return\r
++ the concatenated results,\r
++\r
++ `:width WIDTH FORM' -- evaluate FORM and return the result\r
++ truncated to WIDTH characters. The result will be padded with\r
++ spaces to WIDTH characters, with padding at on the left if the\r
++ WIDTH is negative.\r
++\r
++ `:tag TAG FORM' -- if the thread has the tag TAG, insert the\r
++ result of evaluating FORM.\r
++\r
++ `:eval COMPLEX-FORM' -- evaluate COMPLEX-FORM as emacs lisp and\r
++ evaluate the result.\r
++\r
++During the evaluation of `notmuch-search-result-format', the\r
++symbol `notmuch-thread' is bound to the current thread (a\r
++property list), which can then be used in `:eval' forms."\r
++ :type 'list\r
+ :group 'notmuch-search)\r
+ \r
+ ;; The name of this variable `notmuch-init-file' is consistent with the\r
+@@ -672,109 +712,84 @@ foreground and blue background."\r
+ ;; Reverse the list so earlier entries take precedence\r
+ (reverse notmuch-search-line-faces)))\r
+ \r
+-(defun notmuch-search-author-propertize (authors)\r
+- "Split `authors' into matching and non-matching authors and\r
+-propertize appropriately. If no boundary between authors and\r
+-non-authors is found, assume that all of the authors match."\r
+- (if (string-match "\\(.*\\)|\\(.*\\)" authors)\r
+- (concat (propertize (concat (match-string 1 authors) ",")\r
+- 'face 'notmuch-search-matching-authors)\r
+- (propertize (match-string 2 authors)\r
+- 'face 'notmuch-search-non-matching-authors))\r
+- (propertize authors 'face 'notmuch-search-matching-authors)))\r
+-\r
+-(defun notmuch-search-insert-authors (format-string authors)\r
+- ;; Save the match data to avoid interfering with\r
+- ;; `notmuch-search-process-filter'.\r
+- (save-match-data\r
+- (let* ((formatted-authors (format format-string authors))\r
+- (formatted-sample (format format-string ""))\r
+- (visible-string formatted-authors)\r
+- (invisible-string "")\r
+- (padding ""))\r
+-\r
+- ;; Truncate the author string to fit the specification.\r
+- (if (> (length formatted-authors)\r
+- (length formatted-sample))\r
+- (let ((visible-length (- (length formatted-sample)\r
+- (length "... "))))\r
+- ;; Truncate the visible string according to the width of\r
+- ;; the display string.\r
+- (setq visible-string (substring formatted-authors 0 visible-length)\r
+- invisible-string (substring formatted-authors visible-length))\r
+- ;; If possible, truncate the visible string at a natural\r
+- ;; break (comma or pipe), as incremental search doesn't\r
+- ;; match across the visible/invisible border.\r
+- (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)\r
+- ;; Second clause is destructive on `visible-string', so\r
+- ;; order is important.\r
+- (setq invisible-string (concat (match-string 3 visible-string)\r
+- invisible-string)\r
+- visible-string (concat (match-string 1 visible-string)\r
+- (match-string 2 visible-string))))\r
+- ;; `visible-string' may be shorter than the space allowed\r
+- ;; by `format-string'. If so we must insert some padding\r
+- ;; after `invisible-string'.\r
+- (setq padding (make-string (- (length formatted-sample)\r
+- (length visible-string)\r
+- (length "..."))\r
+- ? ))))\r
+-\r
+- ;; Use different faces to show matching and non-matching authors.\r
+- (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)\r
+- ;; The visible string contains both matching and\r
+- ;; non-matching authors.\r
+- (setq visible-string (notmuch-search-author-propertize visible-string)\r
+- ;; The invisible string must contain only non-matching\r
+- ;; authors, as the visible-string contains both.\r
+- invisible-string (propertize invisible-string\r
+- 'face 'notmuch-search-non-matching-authors))\r
+- ;; The visible string contains only matching authors.\r
+- (setq visible-string (propertize visible-string\r
+- 'face 'notmuch-search-matching-authors)\r
+- ;; The invisible string may contain both matching and\r
+- ;; non-matching authors.\r
+- invisible-string (notmuch-search-author-propertize invisible-string)))\r
+-\r
+- ;; If there is any invisible text, add it as a tooltip to the\r
+- ;; visible text.\r
+- (when (not (string= invisible-string ""))\r
+- (setq visible-string (propertize visible-string 'help-echo (concat "..." invisible-string))))\r
+-\r
+- ;; Insert the visible and, if present, invisible author strings.\r
+- (insert visible-string)\r
+- (when (not (string= invisible-string ""))\r
+- (let ((start (point))\r
+- overlay)\r
+- (insert invisible-string)\r
+- (setq overlay (make-overlay start (point)))\r
+- (overlay-put overlay 'invisible 'ellipsis)\r
+- (overlay-put overlay 'isearch-open-invisible #'delete-overlay)))\r
+- (insert padding))))\r
+-\r
+-(defun notmuch-search-insert-field (field format-string result)\r
++(defun notmuch-search-format-authors (matched non-matched)\r
++ (if (string-equal "" non-matched)\r
++ (propertize matched 'face 'notmuch-search-matching-authors)\r
++ (concat (propertize (concat matched ", ")\r
++ 'face 'notmuch-search-matching-authors)\r
++ (propertize non-matched\r
++ 'face 'notmuch-search-non-matching-authors))))\r
++\r
++(defun notmuch-search-make-width (width string)\r
++ (let ((neg (< 0 width))\r
++ (width (abs width))\r
++ (orig-len (length string)))\r
++\r
++ (if (< width orig-len)\r
++ ;; A sub-set of the string will be visible.\r
++ (let* ((ellipsis "...")\r
++ (visible-len (- width (length ellipsis)))\r
++ (visible-string (substring string 0 visible-len))\r
++ (invisible-string (substring string visible-len)))\r
++\r
++ (concat (propertize (concat visible-string\r
++ ;; The ellipsis should share the\r
++ ;; face of the preceding\r
++ ;; character.\r
++ (propertize ellipsis 'face\r
++ (get-text-property visible-len 'face string)))\r
++ 'help-echo (concat ellipsis invisible-string))))\r
++\r
++ ;; All of the string is visible - pad it.\r
++ (concat (if neg string)\r
++ (make-string (- width orig-len) ? )\r
++ (if neg "" string)))))\r
++\r
++(defun notmuch-search-elem-repr (elem thread)\r
+ (cond\r
+- ((string-equal field "date")\r
+- (insert (propertize (format format-string (plist-get result :date_relative))\r
+- 'face 'notmuch-search-date)))\r
+- ((string-equal field "count")\r
+- (insert (propertize (format format-string\r
+- (format "[%s/%s]" (plist-get result :matched)\r
+- (plist-get result :total)))\r
+- 'face 'notmuch-search-count)))\r
+- ((string-equal field "subject")\r
+- (insert (propertize (format format-string\r
+- (notmuch-sanitize (plist-get result :subject)))\r
+- 'face 'notmuch-search-subject)))\r
+-\r
+- ((string-equal field "authors")\r
+- (notmuch-search-insert-authors\r
+- format-string (notmuch-sanitize (plist-get result :authors))))\r
+-\r
+- ((string-equal field "tags")\r
+- (let ((tags (plist-get result :tags))\r
+- (orig-tags (plist-get result :orig-tags)))\r
+- (insert (format format-string (notmuch-tag-format-tags tags orig-tags)))))))\r
++ ((not elem)\r
++ "")\r
++ \r
++ ((numberp elem)\r
++ (format "%d" elem))\r
++\r
++ ((stringp elem)\r
++ elem)\r
++\r
++ ((functionp elem)\r
++ (funcall elem thread))\r
++\r
++ ((listp elem)\r
++ (let ((op (car elem))\r
++ (rest (cdr elem)))\r
++ (case op\r
++ (:concat\r
++ (mapconcat (lambda (inner-elem)\r
++ (notmuch-search-elem-repr inner-elem thread))\r
++ rest ""))\r
++\r
++ (:width\r
++ (notmuch-search-make-width (car rest)\r
++ (notmuch-search-elem-repr (cadr rest) thread)))\r
++\r
++ (:tag\r
++ (when (member (car rest) (plist-get thread :tags))\r
++ (notmuch-search-elem-repr (cadr rest) thread)))\r
++\r
++ (:eval\r
++ (notmuch-search-elem-repr (apply #'eval rest) thread))\r
++\r
++ (otherwise\r
++ (mapconcat\r
++ (lambda (inner-elem) (notmuch-search-elem-repr inner-elem thread))\r
++ elem "")))))\r
++\r
++ (t\r
++ (let ((val (plist-get thread elem)))\r
++ (if val\r
++ (notmuch-search-elem-repr val thread)\r
++ (message "Unknown message attribute in `notmuch-search-elem-repr': %s" elem)\r
++ "")))))\r
+ \r
+ (defun notmuch-search-show-result (result pos)\r
+ "Insert RESULT at POS."\r
+@@ -782,9 +797,10 @@ non-authors is found, assume that all of the authors match."\r
+ (unless (= (plist-get result :matched) 0)\r
+ (save-excursion\r
+ (goto-char pos)\r
+- (dolist (spec notmuch-search-result-format)\r
+- (notmuch-search-insert-field (car spec) (cdr spec) result))\r
+- (insert "\n")\r
++ ;; `notmuch-thread' is a well known symbol for functions to\r
++ ;; use during evaluation of `notmuch-search-result-format'.\r
++ (insert (let ((notmuch-thread result))\r
++ (notmuch-search-elem-repr notmuch-search-result-format notmuch-thread)))\r
+ (notmuch-search-color-line pos (point) (plist-get result :tags))\r
+ (put-text-property pos (point) 'notmuch-search-result result))))\r
+ \r
+-- \r
+2.1.3\r
+\r