From: Mark Walters Date: Sun, 28 Oct 2012 13:37:10 +0000 (+0000) Subject: [PATCH] contrib: pick: use async parser from lib X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=f808d495184c483ac5b38b21196fc3be1f09096c;p=notmuch-archives.git [PATCH] contrib: pick: use async parser from lib --- diff --git a/2e/ece307348c01999ba14916fb3d35ece5769c87 b/2e/ece307348c01999ba14916fb3d35ece5769c87 new file mode 100644 index 000000000..000ff16cb --- /dev/null +++ b/2e/ece307348c01999ba14916fb3d35ece5769c87 @@ -0,0 +1,164 @@ +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 9236F431FCF + for ; Sun, 28 Oct 2012 06:37:17 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] 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 lNl8o1TE9-e9 for ; + Sun, 28 Oct 2012 06:37:17 -0700 (PDT) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D3BFA431FAF + for ; Sun, 28 Oct 2012 06:37:16 -0700 (PDT) +Received: by mail-wi0-f173.google.com with SMTP id hm4so1231150wib.2 + for ; Sun, 28 Oct 2012 06:37:15 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer; + bh=VAp1I7ti0Vnq+/HbGWGGOkWZ9e9YLHtXkonTs3C2i6E=; + b=Ak2CNrDnqGH67O4f6SAYTzPlvENWH/z6GlwYQatvxXpR3rRITYAzGcwlBNjQGr3jvB + dWXRUU5OwFKcdKKRMvRrUKA2AyQQbo0HLkBlAj+ahvS2ARafXEg3ke0JpshJMWAIuiqR + hhD2Lj3TOtIIOm54KXwYP0OSET/Rh2jGy8Lpnh4HwoKHm8mH1tpHSwwoQ+nwsN379aOC + 6Lt5tS9tFt233/RHNz9f0AsjLwDj8ihiq0kxrcSevqPuJ78ahfyCxD5jq8nxGOb6Ea2q + sqQWT2p5yNxKYUxgIjXm/tzPtEDRvdnTDMAjsmEl22S86M0n18A3ZCikMmyfo4vJAZVu + GgiA== +Received: by 10.180.8.134 with SMTP id r6mr11475074wia.18.1351431435519; + Sun, 28 Oct 2012 06:37:15 -0700 (PDT) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPS id bf6sm3156751wib.3.2012.10.28.06.37.13 + (version=TLSv1/SSLv3 cipher=OTHER); + Sun, 28 Oct 2012 06:37:14 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH] contrib: pick: use async parser from lib +Date: Sun, 28 Oct 2012 13:37:10 +0000 +Message-Id: <1351431430-5308-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +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: Sun, 28 Oct 2012 13:37:17 -0000 + +This moves notmuch-pick to use the newly split out async json parser +from notmuch-lib.el. + +--- + +I hadn't expected the split out json parser to go in so quickly: this +moves notmuch-pick to use the new function. + +Best wishes + +Mark + + + + contrib/notmuch-pick/notmuch-pick.el | 52 +++------------------------------ + 1 files changed, 5 insertions(+), 47 deletions(-) + +diff --git a/contrib/notmuch-pick/notmuch-pick.el b/contrib/notmuch-pick/notmuch-pick.el +index be6a91a..15ac5e8 100644 +--- a/contrib/notmuch-pick/notmuch-pick.el ++++ b/contrib/notmuch-pick/notmuch-pick.el +@@ -435,7 +435,7 @@ Does NOT change the database." + (unless (notmuch-pick-get-match) + (notmuch-pick-next-matching-message)) + (while (and (not (notmuch-pick-get-match)) +- (not (eq notmuch-pick-process-state 'end))) ++ (get-buffer-process (current-buffer))) + (message "waiting for message") + (sit-for 0.1) + (goto-char (point-min)) +@@ -733,9 +733,6 @@ Complete list of currently available key bindings: + (insert "\n"))) + + +-(defvar notmuch-pick-json-parser nil +- "Incremental JSON parser for the search process filter.") +- + (defun notmuch-pick-process-filter (proc string) + "Process and filter the output of \"notmuch show\" (for pick)" + (let ((results-buf (process-buffer proc)) +@@ -748,46 +745,10 @@ Complete list of currently available key bindings: + ;; Insert new data + (save-excursion + (goto-char (point-max)) +- (insert string))) +- (with-current-buffer results-buf +- (save-excursion +- (goto-char (point-max)) +- (while (not done) +- (condition-case nil +- (case notmuch-pick-process-state +- ((begin) +- ;; Enter the results list +- (if (eq (notmuch-json-begin-compound +- notmuch-pick-json-parser) 'retry) +- (setq done t) +- (setq notmuch-pick-process-state 'result))) +- ((result) +- ;; Parse a result +- (let ((result (notmuch-json-read notmuch-pick-json-parser))) +- (case result +- ((retry) (setq done t)) +- ((end) (setq notmuch-pick-process-state 'end)) +- (otherwise (notmuch-pick-insert-forest-thread result))))) +- ((end) +- ;; Any trailing data is unexpected +- (with-current-buffer parse-buf +- (skip-chars-forward " \t\r\n") +- (if (eobp) +- (setq done t) +- (signal 'json-error nil))))) +- (json-error +- ;; Do our best to resynchronize and ensure forward +- ;; progress +- (notmuch-pick-show-error +- "%s" +- (with-current-buffer parse-buf +- (let ((bad (buffer-substring (line-beginning-position) +- (line-end-position)))) +- (forward-line) +- bad)))))) +- ;; Clear out what we've parsed +- (with-current-buffer parse-buf +- (delete-region (point-min) (point)))))))) ++ (insert string)) ++ (notmuch-json-parse-partial-list 'notmuch-pick-insert-forest-thread ++ 'notmuch-pick-show-error ++ results-buf))))) + + (defun notmuch-pick-worker (basic-query &optional query-context buffer) + (interactive) +@@ -815,9 +776,6 @@ Complete list of currently available key bindings: + ;; This buffer will be killed by the sentinel, which + ;; should be called no matter how the process dies. + (parse-buf (generate-new-buffer " *notmuch pick parse*"))) +- (set (make-local-variable 'notmuch-pick-process-state) 'begin) +- (set (make-local-variable 'notmuch-pick-json-parser) +- (notmuch-json-create-parser parse-buf)) + (process-put proc 'parse-buf parse-buf) + (set-process-sentinel proc 'notmuch-pick-process-sentinel) + (set-process-filter proc 'notmuch-pick-process-filter) +-- +1.7.9.1 +