unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: query: make sync queries use sexp
@ 2012-12-08 14:11 Mark Walters
  2012-12-09  0:47 ` Austin Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Walters @ 2012-12-08 14:11 UTC (permalink / raw)
  To: notmuch

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.
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] emacs: query: make sync queries use sexp
  2012-12-08 14:11 [PATCH] emacs: query: make sync queries use sexp Mark Walters
@ 2012-12-09  0:47 ` Austin Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Austin Clements @ 2012-12-09  0:47 UTC (permalink / raw)
  To: Mark Walters; +Cc: notmuch

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@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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-09  0:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-08 14:11 [PATCH] emacs: query: make sync queries use sexp Mark Walters
2012-12-09  0:47 ` Austin Clements

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).