From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/4] emacs: JSON based search improvements.
Date: Tue, 30 Nov 2010 11:00:22 +0000 [thread overview]
Message-ID: <1291114825-3513-1-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1291026599-14795-4-git-send-email-dme@dme.org>
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
next prev parent reply other threads:[~2010-11-30 11:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-29 10:29 second attempt: JSON based search David Edmondson
2010-11-29 10:29 ` [PATCH 1/3] notmuch: Add `date_relative' to JSON search output David Edmondson
2010-11-29 10:29 ` [PATCH 2/3] test: Expect `date_relative' in " David Edmondson
2010-11-29 10:29 ` [PATCH 3/3] emacs: Use JSON output for search David Edmondson
2010-11-30 11:00 ` David Edmondson [this message]
2010-11-30 11:00 ` [PATCH 2/4] emacs: Use a plists rather than an assoc list in JSON search David Edmondson
2010-11-30 11:00 ` [PATCH 3/4] test: Add tests for JSON parsing of search results David Edmondson
2010-11-30 11:00 ` [PATCH 4/4] emacs: Fix indentation, add comments David Edmondson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291114825-3513-1-git-send-email-dme@dme.org \
--to=dme@dme.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).