[PATCH 6/8] CLI: refactor dumping of tags.
[notmuch-archives.git] / d6 / bbc3a6066c8ae9ee11c0206cc69b62893413aa
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 26198431FAF\r
6         for <notmuch@notmuchmail.org>; Sat,  1 Dec 2012 18:40:35 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id FFJERYebJdiz for <notmuch@notmuchmail.org>;\r
16         Sat,  1 Dec 2012 18:40:33 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1F26F429E3B\r
20         for <notmuch@notmuchmail.org>; Sat,  1 Dec 2012 18:40:22 -0800 (PST)\r
21 X-AuditID: 1209190f-b7fec6d00000090d-9b-50babf96250a\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 50.06.02317.69FBAB05; Sat,  1 Dec 2012 21:40:22 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qB22eC44019892; \r
27         Sat, 1 Dec 2012 21:40:12 -0500\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB22e6rt025600\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 1 Dec 2012 21:40:10 -0500 (EST)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1TezTS-0000xe-0h; Sat, 01 Dec 2012 21:40:06 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse\r
41         error\r
42 Date: Sat,  1 Dec 2012 21:39:58 -0500\r
43 Message-Id: <1354416002-3557-6-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10.4\r
45 In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu>\r
46 References: <1354416002-3557-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nojtt/64Ag0nnZC2u35zJ7MDo8WzV\r
49         LeYAxigum5TUnMyy1CJ9uwSujJ+LPzIXHBOoWL3iFmMD4wbeLkZODgkBE4l/b7tYIWwxiQv3\r
50         1rN1MXJxCAnsY5SY+6+fFcJZzyix4cIxZpAqIYGHTBJLDxdCJOYySnxc/QIswSagIbFt/3JG\r
51         EFtEQFpi593ZQN0cHMwCahJ/ulRAwsICgRIrVz4F28YioCpxdeZvsFZeAXuJC03zGSGuUJTo\r
52         fjaBDaSVU8BBYkU3D8Rae4n/v6+xTWDkX8DIsIpRNiW3Sjc3MTOnODVZtzg5MS8vtUjXRC83\r
53         s0QvNaV0EyMoZDgl+XcwfjuodIhRgINRiYeXcdauACHWxLLiytxDjJIcTEqivFd2AIX4kvJT\r
54         KjMSizPii0pzUosPMUpwMCuJ8LKYAOV4UxIrq1KL8mFS0hwsSuK8V1Nu+gsJpCeWpGanphak\r
55         FsFkZTg4lCR4q/cBNQoWpaanVqRl5pQgpJk4OEGG8wANf7QXZHhxQWJucWY6RP4Uo6KUOO81\r
56         kIQASCKjNA+uFxbTrxjFgV4R5vUEWcEDTAdw3a+ABjMBDX6zbDvI4JJEhJRUA+PE/IqwG8wH\r
57         jIzyjGs63/hW1m+2Z1+Zc4rVLquH89fLJRNPcigsqV52uZ75C7fqyjNGkZ+utBZXna5a7cFv\r
58         qXdv6oScNek38yd7evALf6y+K/FmZfTEBWbOgXd/257nZRPO2NGQwvp2V5PVpTMHsxvDrznX\r
59         5NmvvdD+IfuUv5X7hqU/Nxq/UFdiKc5INNRiLipOBAAkaR7vxAIAAA==\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Sun, 02 Dec 2012 02:40:35 -0000\r
73 \r
74 Previously, if the input stream consisted only of an error message,\r
75 notmuch-json-begin-compound would signal a (wrong-type-argument\r
76 number-or-marker-p nil) error when reaching the end of the error\r
77 message.  This happened because notmuch-json-scan-to-value would think\r
78 that it reached a value and put the parser into the 'value state.\r
79 Even after notmuch-json-begin-compound signaled the syntax error, the\r
80 parser would remain in this state and when the resynchronization logic\r
81 reached the end of the buffer, the parser would fail because the\r
82 'value state indicates that characters are available.\r
83 \r
84 This fixes this problem by restoring the parser's previous state if it\r
85 encounters a syntax error.\r
86 ---\r
87  emacs/notmuch-lib.el |   22 +++++++++++++---------\r
88  1 file changed, 13 insertions(+), 9 deletions(-)\r
89 \r
90 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
91 index 1d0ec17..9402456 100644\r
92 --- a/emacs/notmuch-lib.el\r
93 +++ b/emacs/notmuch-lib.el\r
94 @@ -474,15 +474,19 @@ Entering JSON objects is currently unimplemented."\r
95    (with-current-buffer (notmuch-json-buffer jp)\r
96      ;; Disallow terminators\r
97      (setf (notmuch-json-allow-term jp) nil)\r
98 -    (or (notmuch-json-scan-to-value jp)\r
99 -       (if (/= (char-after) ?\[)\r
100 -           (signal 'json-readtable-error (list "expected '['"))\r
101 -         (forward-char)\r
102 -         (push ?\] (notmuch-json-term-stack jp))\r
103 -         ;; Expect a value or terminator next\r
104 -         (setf (notmuch-json-next jp) 'expect-value\r
105 -               (notmuch-json-allow-term jp) t)\r
106 -         t))))\r
107 +    ;; Save "next" so we can restore it if there's a syntax error\r
108 +    (let ((saved-next (notmuch-json-next jp)))\r
109 +      (or (notmuch-json-scan-to-value jp)\r
110 +         (if (/= (char-after) ?\[)\r
111 +             (progn\r
112 +               (setf (notmuch-json-next jp) saved-next)\r
113 +               (signal 'json-readtable-error (list "expected '['")))\r
114 +           (forward-char)\r
115 +           (push ?\] (notmuch-json-term-stack jp))\r
116 +           ;; Expect a value or terminator next\r
117 +           (setf (notmuch-json-next jp) 'expect-value\r
118 +                 (notmuch-json-allow-term jp) t)\r
119 +           t)))))\r
120  \r
121  (defun notmuch-json-read (jp)\r
122    "Parse the value at point in JP's buffer.\r
123 -- \r
124 1.7.10.4\r
125 \r