[PATCH v3 0/8] emacs: JSON-based search cleanups
authorAustin Clements <amdragon@MIT.EDU>
Sat, 14 Jul 2012 23:02:12 +0000 (19:02 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:19 +0000 (09:48 -0800)
7a/9481f36c78f4258b9fed70fa6bbc07091ff36b [new file with mode: 0644]

diff --git a/7a/9481f36c78f4258b9fed70fa6bbc07091ff36b b/7a/9481f36c78f4258b9fed70fa6bbc07091ff36b
new file mode 100644 (file)
index 0000000..2454200
--- /dev/null
@@ -0,0 +1,218 @@
+Return-Path: <amdragon@mit.edu>\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 3B0D0431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jul 2012 16:02:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 VLW9yq+XE6wt for <notmuch@notmuchmail.org>;\r
+       Sat, 14 Jul 2012 16:02:27 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9F019431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jul 2012 16:02:26 -0700 (PDT)\r
+X-AuditID: 12074423-b7f396d0000008f4-d7-5001fa82b116\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 85.26.02292.28AF1005; Sat, 14 Jul 2012 19:02:26 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6EN2PjU015442; \r
+       Sat, 14 Jul 2012 19:02:25 -0400\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6EN2NrC008492\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 14 Jul 2012 19:02:24 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SqBLz-0002G1-Md; Sat, 14 Jul 2012 19:02:23 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 0/8] emacs: JSON-based search cleanups\r
+Date: Sat, 14 Jul 2012 19:02:12 -0400\r
+Message-Id: <1342306940-7499-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
+References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrCIsWRmVeSWpSXmKPExsUixCmqrNv0izHA4MoOFos9+7wsVs/lsbh+\r
+       cyazA7PH3dNcHjtn3WX3eLbqFnMAcxSXTUpqTmZZapG+XQJXxq+Tn1gL+vUqmne0sTYwvlLp\r
+       YuTkkBAwkfi+4xgThC0mceHeerYuRi4OIYF9jBL/pjxih3A2MEpsnXKcEaRKSOARk8SP2fIQ\r
+       ibmMEg9v7mIDSbAJaEhs278crEhEQFpi593ZrCA2s4ClxPfWe2BxYSD73vQ/YOtYBFQlNm/t\r
+       ZQaxeQXsJTpOH2GGOENe4un9PrCZnAKOEhu+XGCFWOwg0XhsJvMERv4FjAyrGGVTcqt0cxMz\r
+       c4pTk3WLkxPz8lKLdM30cjNL9FJTSjcxggKL3UV5B+Ofg0qHGAU4GJV4eJP8GQKEWBPLiitz\r
+       DzFKcjApifK+/skYIMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEV+IrUI43JbGyKrUoHyYlzcGi\r
+       JM57LeWmv5BAemJJanZqakFqEUxWhoNDSYL3FchQwaLU9NSKtMycEoQ0EwcnyHAeoOEnQWp4\r
+       iwsSc4sz0yHypxgVpcQhEgIgiYzSPLheWOS/YhQHekWY9yFIFQ8wacB1vwIazAQ0eNbPf/5A\r
+       g0sSEVJSDYy8DF9dnI68Zzsh80js2AK99fUv/RuUs+8XLYxZeGJeYdKl/y5n06NnVGYzKJ++\r
+       w7/2ngnfnGoLQ+NZhvw3Fz54WLN4OzvjPolpoXa5oknJzr/+WFrJzG9at1SO2ZF3y8Q/kxZO\r
+       ODs368Hlr96hmteTfkaETO6+159+XcPfg5Etyqg43eB0+HclluKMREMt5qLiRADK7bRy1wIA        AA==\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: Sat, 14 Jul 2012 23:02:28 -0000\r
+\r
+This version swaps out the notmuch-search-do-results macro for a\r
+higher-order function, notmuch-search-foreach-result.  This requires\r
+less squiting to understand and clearly distinguishes the arguments\r
+passed in to the function from the arguments passed to the callback.\r
+This version also updates the docstring for\r
+notmuch-search-result-format to mention that multi-line result formats\r
+work and how to enter them, and it adds a NEWS patch.\r
+\r
+Diff from v2:\r
+\r
+diff --git a/NEWS b/NEWS\r
+index a1a6e93..7b33f0d 100644\r
+--- a/NEWS\r
++++ b/NEWS\r
+@@ -17,6 +17,20 @@ Maildir tag synchronization\r
+ Emacs Interface\r
+ ---------------\r
+ \r
++Search results now get re-colored when tags are updated\r
++\r
++The formatting of tags in search results can now be customized\r
++\r
++  Previously, attempting to change the format of tags in\r
++  `notmuch-search-result-format` would usually break tagging from\r
++  search-mode.  We no longer make assumptions about the format.\r
++\r
++Multi-line search result formats are now supported\r
++\r
++  It is now possible to embed newlines in\r
++  `notmuch-search-result-format` to make individual search results\r
++  span multiple lines.\r
++\r
+ Search now uses the JSON format internally\r
+ \r
+   This should address problems with unusual characters in authors and\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 7302fa7..ec760dc 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -69,7 +69,13 @@\r
+       date, count, authors, subject, tags\r
+ For example:\r
+       (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
+-                                           \(\"subject\" . \"%s\"\)\)\)"\r
++                                           \(\"subject\" . \"%s\"\)\)\)\r
++Line breaks are permitted in format strings.  Note that a line\r
++break at the end of an \"authors\" field will get elided if the\r
++authors list is long; place it instead at the beginning of the\r
++following field.  To enter a line break when setting this\r
++variable with setq, use \\n.  To enter a line break in customize,\r
++press \\[quoted-insert] C-j."\r
+   :type '(alist :key-type (string) :value-type (string))\r
+   :group 'notmuch-search)\r
+ \r
+@@ -433,32 +439,39 @@ returns nil"\r
+     (next-single-property-change (or pos (point)) 'notmuch-search-result\r
+                                nil (point-max))))\r
+ \r
+-(defmacro notmuch-search-do-results (beg end pos-sym &rest body)\r
+-  "Invoke BODY for each result between BEG and END.\r
+-\r
+-POS-SYM will be bound to the point at the beginning of the\r
+-current result."\r
+-  (declare (indent 3))\r
+-  (let ((end-sym (make-symbol "end"))\r
+-      (first-sym (make-symbol "first")))\r
+-    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))\r
+-         ;; End must be a marker in case body changes the text\r
+-         (,end-sym (copy-marker ,end))\r
+-         ;; Make sure we examine one result, even if (= beg end)\r
+-         (,first-sym t))\r
+-       ;; We have to be careful if the region extends beyond the\r
+-       ;; results.  In this case, pos could be null or there could be\r
+-       ;; no result at pos.\r
+-       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))\r
+-       (when (notmuch-search-get-result ,pos-sym)\r
+-         ,@body)\r
+-       (setq ,pos-sym (notmuch-search-result-end ,pos-sym)\r
+-             ,first-sym nil)))))\r
++(defun notmuch-search-foreach-result (beg end function)\r
++  "Invoke FUNCTION for each result between BEG and END.\r
++\r
++FUNCTION should take one argument.  It will be applied to the\r
++character position of the beginning of each result that overlaps\r
++the region between points BEG and END.  As a special case, if (=\r
++BEG END), FUNCTION will be applied to the result containing point\r
++BEG."\r
++\r
++  (lexical-let ((pos (notmuch-search-result-beginning beg))\r
++              ;; End must be a marker in case function changes the\r
++              ;; text.\r
++              (end (copy-marker end))\r
++              ;; Make sure we examine at least one result, even if\r
++              ;; (= beg end).\r
++              (first t))\r
++    ;; We have to be careful if the region extends beyond the results.\r
++    ;; In this case, pos could be null or there could be no result at\r
++    ;; pos.\r
++    (while (and pos (or (< pos end) first))\r
++      (when (notmuch-search-get-result pos)\r
++      (funcall function pos))\r
++      (setq pos (notmuch-search-result-end pos)\r
++          first nil))))\r
++;; Unindent the function argument of notmuch-search-foreach-result so\r
++;; the indentation of callers doesn't get out of hand.\r
++(put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
+ \r
+ (defun notmuch-search-properties-in-region (property beg end)\r
+   (let (output)\r
+-    (notmuch-search-do-results beg end pos\r
+-      (push (plist-get (notmuch-search-get-result pos) property) output))\r
++    (notmuch-search-foreach-result beg end\r
++      (lambda (pos)\r
++      (push (plist-get (notmuch-search-get-result pos) property) output)))\r
+     output))\r
+ \r
+ (defun notmuch-search-find-thread-id ()\r
+@@ -542,18 +555,20 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
+ \r
+ (defun notmuch-search-get-tags-region (beg end)\r
+   (let (output)\r
+-    (notmuch-search-do-results beg end pos\r
+-      (setq output (append output (notmuch-search-get-tags pos))))\r
++    (notmuch-search-foreach-result beg end\r
++      (lambda (pos)\r
++      (setq output (append output (notmuch-search-get-tags pos)))))\r
+     output))\r
+ \r
+ (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
+   "Change tags for threads in the given region."\r
+   (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
+     (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
+-    (notmuch-search-do-results beg end pos\r
+-      (notmuch-search-set-tags\r
+-       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
+-       pos))))\r
++    (notmuch-search-foreach-result beg end\r
++      (lambda (pos)\r
++      (notmuch-search-set-tags\r
++       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
++       pos)))))\r
+ \r
+ (defun notmuch-search-tag (&optional tag-changes)\r
+   "Change tags for the currently selected thread or region.\r
+\r
+\r