[PATCH 5/5] emacs: Use streaming S-expr parser for search
authorAustin Clements <amdragon@MIT.EDU>
Sat, 18 May 2013 04:31:12 +0000 (00:31 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:49 +0000 (09:54 -0800)
c1/7ab396688e260a1ee314235d27b25a89399636 [new file with mode: 0644]

diff --git a/c1/7ab396688e260a1ee314235d27b25a89399636 b/c1/7ab396688e260a1ee314235d27b25a89399636
new file mode 100644 (file)
index 0000000..7de3b30
--- /dev/null
@@ -0,0 +1,180 @@
+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 E80EA429E27\r
+       for <notmuch@notmuchmail.org>; Fri, 17 May 2013 21:33:08 -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 qNx0cGONGkaf for <notmuch@notmuchmail.org>;\r
+       Fri, 17 May 2013 21:33:02 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4312E429E30\r
+       for <notmuch@notmuchmail.org>; Fri, 17 May 2013 21:32:25 -0700 (PDT)\r
+X-AuditID: 1209190c-b7f566d000004c69-92-51970458ba7c\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 51.A4.19561.85407915; Sat, 18 May 2013 00:32:24 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH-1.MIT.EDU [18.9.28.11])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r4I4WD1t016939; \r
+       Sat, 18 May 2013 00:32:13 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4I4WBoQ018837\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 18 May 2013 00:32:12 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1UdYo1-0001Z2-Lh; Sat, 18 May 2013 00:31:41 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 5/5] emacs: Use streaming S-expr parser for search\r
+Date: Sat, 18 May 2013 00:31:12 -0400\r
+Message-Id: <1368851472-5382-6-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+References: <1368851472-5382-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsUixG6nohvBMj3Q4GKnocXquTwW12/OZHZg\r
+       8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mp7PVSq4Ll/x/vBVxgbGt5JdjJwcEgImElse\r
+       t7JA2GISF+6tZwOxhQT2MUqsX5cLYW9klFj617iLkQvIvsMksWLhI2YIZy6jxJqGO+wgVWwC\r
+       GhLb9i9nBLFFBKQldt6dzQpiMws4SnzevwhsqrCAk8Tsf//AbBYBVYnd5/6C2bwC9hIvvj1n\r
+       h7hCUaL72QSwOKeAg8Th+cegLrKX6Lpwk20CI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealF\r
+       uoZ6uZkleqkppZsYQUHEKcmzg/HNQaVDjAIcjEo8vB9cpwUKsSaWFVfmHmKU5GBSEuU1+QcU\r
+       4kvKT6nMSCzOiC8qzUktPsQowcGsJML7vBgox5uSWFmVWpQPk5LmYFES572cctNfSCA9sSQ1\r
+       OzW1ILUIJivDwaEkwVvEPD1QSLAoNT21Ii0zpwQhzcTBCTKcB2i4FUgNb3FBYm5xZjpE/hSj\r
+       opQ4bzFIQgAkkVGaB9cLi/JXjOJArwjzSoNU8QATBFz3K6DBTECDWa9NBRlckoiQkmpg3BHc\r
+       bRz5yvsX/47W9CcG+fHf1TMVyv+sYZmlb2iv8usAg3uc5JNJQK9N3GWgOJk3f7XeDM7YJZ6J\r
+       iff+hDtfZ/lTW7Gr6Vh2tNPM+9NUlgqHKDuFWNiumy9y+w1nzErW64KHeD2KeFONOLuLlq6c\r
+       nRLUe/RkQ1z3RYaoJa8OGVvfdlnleEmJpTgj0VCLuag4EQC3mWWVzQIAAA==\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, 18 May 2013 04:33:09 -0000\r
+\r
+In addition to being the Right Thing to do, this noticeably improves\r
+the time taken to display the first page of search results, since it's\r
+roughly an order of magnitude faster than the JSON parser.\r
+Interestingly, it does *not* significantly improve the time to\r
+completely fill a large search buffer because for large search\r
+buffers, the cost of creating author invisibility overlays and\r
+inserting text (which slows down with more overlays) dominates.\r
+However, the time required to display the first page of results is\r
+generally more important to the user experience.\r
+---\r
+ emacs/notmuch.el |   13 +++----------\r
+ test/emacs       |   10 +++-------\r
+ 2 files changed, 6 insertions(+), 17 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index b8d9c44..5a8c957 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -58,6 +58,7 @@\r
+ (require 'notmuch-hello)\r
+ (require 'notmuch-maildir-fcc)\r
+ (require 'notmuch-message)\r
++(require 'notmuch-parser)\r
\r
+ (defcustom notmuch-search-result-format\r
+   `(("date" . "%12s ")\r
+@@ -809,13 +810,6 @@ non-authors is found, assume that all of the authors match."\r
+       (setq notmuch-search-target-thread "found")\r
+       (goto-char beg)))))\r
\r
+-(defun notmuch-search-show-error (string &rest objects)\r
+-  (save-excursion\r
+-    (goto-char (point-max))\r
+-    (insert "Error: Unexpected output from notmuch search:\n")\r
+-    (insert (apply #'format string objects))\r
+-    (insert "\n")))\r
+-\r
+ (defun notmuch-search-process-filter (proc string)\r
+   "Process and filter the output of \"notmuch search\""\r
+   (let ((results-buf (process-buffer proc))\r
+@@ -829,8 +823,7 @@ non-authors is found, assume that all of the authors match."\r
+       (save-excursion\r
+         (goto-char (point-max))\r
+         (insert string))\r
+-      (notmuch-json-parse-partial-list 'notmuch-search-show-result\r
+-                                       'notmuch-search-show-error\r
++      (notmuch-sexp-parse-partial-list 'notmuch-search-show-result\r
+                                        results-buf)))))\r
\r
+ (defun notmuch-search-tag-all (&optional tag-changes)\r
+@@ -933,7 +926,7 @@ Other optional parameters are used as follows:\r
+       (save-excursion\r
+       (let ((proc (notmuch-start-notmuch\r
+                    "notmuch-search" buffer #'notmuch-search-process-sentinel\r
+-                   "search" "--format=json" "--format-version=1"\r
++                   "search" "--format=sexp" "--format-version=1"\r
+                    (if oldest-first\r
+                        "--sort=oldest-first"\r
+                      "--sort=newest-first")\r
+diff --git a/test/emacs b/test/emacs\r
+index d38ae8c..7d42abf 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -856,7 +856,7 @@ test_expect_success "Rendering HTML mail with images" \\r
+ test_begin_subtest "Search handles subprocess error exit codes"\r
+ cat > notmuch_fail <<EOF\r
+ #!/bin/sh\r
+-echo This is output\r
++echo '()'\r
+ exit 1\r
+ EOF\r
+ chmod a+x notmuch_fail\r
+@@ -871,21 +871,19 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
+              (test-output))"\r
+ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
+ test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
+-Error: Unexpected output from notmuch search:\r
+-This is output\r
+ End of search results.\r
+ ---\r
+ $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
+ ---\r
+ [XXX]\r
+ $PWD/notmuch_fail exited with status 1\r
+-command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
++command: $PWD/notmuch_fail search --format\=sexp --format-version\=1 --sort\=newest-first tag\:inbox\r
+ exit status: 1"\r
\r
+ test_begin_subtest "Search handles subprocess warnings"\r
+ cat > notmuch_fail <<EOF\r
+ #!/bin/sh\r
+-echo This is output\r
++echo '()'\r
+ echo This is a warning >&2\r
+ echo This is another warning >&2\r
+ exit 0\r
+@@ -903,8 +901,6 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
+              (test-output))"\r
+ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
+ test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
+-Error: Unexpected output from notmuch search:\r
+-This is output\r
+ End of search results.\r
+ ---\r
+ This is a warning (see *Notmuch errors* for more details)\r
+-- \r
+1.7.10.4\r
+\r