Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 70A91431FB6 for ; Tue, 30 Nov 2010 03:00:38 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.363 X-Spam-Level: * X-Spam-Status: No, score=1.363 tagged_above=-999 required=5 tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FsWrmNF+JQ1K for ; Tue, 30 Nov 2010 03:00:37 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 61375431FB5 for ; Tue, 30 Nov 2010 03:00:37 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id E026659422B; Tue, 30 Nov 2010 11:00:26 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 1/4] emacs: JSON based search improvements. Date: Tue, 30 Nov 2010 11:00:22 +0000 Message-Id: <1291114825-3513-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1291026599-14795-4-git-send-email-dme@dme.org> References: <1291026599-14795-4-git-send-email-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2010 11:00:38 -0000 Fix variable name typos. Attempt to avoid display flashing by removing newlines from the inserted string. Ease debugging by moving the `condition-case' closer into the code that it is really intended to cover (the parsing of the JSON object), allowing errors in the remaining code to still fire correctly. As a consequence, test for :json-eof when examining the next character to be parsed, as that throws an error that was previously covered by the `condition-case'. --- emacs/notmuch.el | 74 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 42 insertions(+), 32 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index bde8c47..f4aefc8 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -717,57 +717,67 @@ foreground and blue background." (put-text-property beg (point-marker) 'notmuch-search-subject subject))) (defvar notmuch-search-parse-start nil) -(make-variable-buffer-local 'notmuch-show-parse-start) +(make-variable-buffer-local 'notmuch-search-parse-start) (defun notmuch-search-process-insert (proc buffer string) (with-current-buffer buffer (let ((inhibit-read-only t) (inhibit-redisplay t) ;; Vectors are not as useful here. - (json-array-type 'list) - object) + (json-array-type 'list)) (save-excursion ;; Insert the text, advancing the process marker (goto-char (point-max)) - (insert string) + ;; Flatten the string (remove newlines) to reduce the flashing + ;; that occurs when we insert the multi-line object and then + ;; replace it with a single line summary. This is safe because + ;; we know that none of the JSON fields can contain newlines - + ;; only the whitespace between fields. + (insert (replace-regexp-in-string "\n" "" string)) (set-marker (process-mark proc) (point))) (save-excursion (goto-char notmuch-search-parse-start) - (condition-case nil (while - (cond - ;; Opening bracket or comma separator between - ;; objects. - ((or (char-equal (json-peek) ?\[) - (char-equal (json-peek) ?\,)) - (json-advance) - (delete-region notmuch-search-parse-start (point)) - t) - - ;; Closing array. - ((char-equal (json-peek) ?\]) - ;; Consume both the closing bracket and any trailing - ;; whitespace (typically a carriage return). - (json-advance) - (json-skip-whitespace) - (delete-region notmuch-search-parse-start (point)) - nil) - - ;; Single object. - ((setq object (json-read-object)) - ;; Delete the object that we consumed. - (delete-region notmuch-search-parse-start (point)) - ;; Insert the corresponding results. - (notmuch-search-process-insert-object object) - t)) + (let ((next-char (json-peek))) + (cond + ;; No more data (yet). + ((eq next-char :json-eof) + nil) + + ;; Opening bracket or comma separator between + ;; objects. + ((or (char-equal next-char ?\[) + (char-equal next-char ?\,)) + (json-advance) + (delete-region notmuch-search-parse-start (point)) + t) + + ;; Closing array. + ((char-equal next-char ?\]) + ;; Consume both the closing bracket and any trailing + ;; whitespace (typically a carriage return). + (json-advance) + (json-skip-whitespace) + (delete-region notmuch-search-parse-start (point)) + nil) + + ;; Single object. + ((condition-case nil + (let ((object (json-read-object))) + ;; Delete the object that we consumed. + (delete-region notmuch-search-parse-start (point)) + ;; Insert the corresponding results. + (notmuch-search-process-insert-object object) + t) + (error nil))))) + ;; Consume any white space between terms. (let ((p (point))) (json-skip-whitespace) (delete-region p (point))) ;; Remember where we got up to. - (setq notmuch-search-parse-start (point))) - (error nil)))))) + (setq notmuch-search-parse-start (point))))))) (defun notmuch-search-process-filter (proc string) "Process and filter the output of `notmuch search'." -- 1.7.2.3