[PATCH] emacs: query: make sync queries use sexp
Austin Clements
amdragon at MIT.EDU
Sat Dec 8 16:47:39 PST 2012
sexp-at-point is a pretty roundabout way to parse this that I think
will basically parse the S-expression three times (in end-of-sexp, in
beginning-of-sexp, and then for real in read-from-whole-string). How
about
(prog1
(read (current-buffer))
(skip-chars-forward " \t\n\f")
(unless (eobp)
(error "Trailing garbage after notmuch output")))
? Technically, just the (read (current-buffer)) part would be
equivalent to the current (json-read) call (which will ignore any
trailing garbage).
There's also another synchronous JSON query in notmuch-mua.el that
should be fixed.
I wouldn't worry too much about the error handling. I don't think
this can deal worse with errors than the current JSON code does. My
schema versioning series has a patch [1] that should help improve
error handling. It's for JSON right now, but will be trivial to port
to S-expressions.
[1] id:1354416002-3557-9-git-send-email-amdragon at mit.edu
Quoth Mark Walters on Dec 08 at 2:11 pm:
> This changes the queries used by notmuch-show from json to sexp (patch
> based on a comment by Tomi on irc as to the trivial change needed).
>
> The async query parsed used by search is not as easy to convert.
> ---
>
> It's probably worth making this change: sexps are significantly faster
> but I doubt anyone would notice in show (since the query is small and
> the wash processing etc relatively large).
>
> At the moment this doesn't do any error fixing. The json version did
> not either but the sexp parser and the json parser might behave
> differently on malformed input.
>
> Best wishes
>
> Mark
>
>
> emacs/notmuch-query.el | 7 ++-----
> 1 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
> index d66baea..0ee6cca 100644
> --- a/emacs/notmuch-query.el
> +++ b/emacs/notmuch-query.el
> @@ -29,10 +29,7 @@ A thread is a forest or list of trees. A tree is a two element
> list where the first element is a message, and the second element
> is a possibly empty forest of replies.
> "
> - (let ((args '("show" "--format=json"))
> - (json-object-type 'plist)
> - (json-array-type 'list)
> - (json-false 'nil))
> + (let ((args '("show" "--format=sexp")))
> (if notmuch-show-process-crypto
> (setq args (append args '("--decrypt"))))
> (setq args (append args search-terms))
> @@ -40,7 +37,7 @@ is a possibly empty forest of replies.
> (progn
> (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))
> (goto-char (point-min))
> - (json-read)))))
> + (sexp-at-point)))))
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;; Mapping functions across collections of messages.
More information about the notmuch
mailing list