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 57DDF431FBD for ; Sat, 1 Dec 2012 18:40:35 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 r0mFkuGIQxoe for ; Sat, 1 Dec 2012 18:40:32 -0800 (PST) Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU [18.7.68.35]) by olra.theworths.org (Postfix) with ESMTP id 22E6E429E3C for ; Sat, 1 Dec 2012 18:40:23 -0800 (PST) X-AuditID: 12074423-b7fcb6d000000927-c2-50babf9667f3 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id E6.57.02343.69FBAB05; Sat, 1 Dec 2012 21:40:22 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qB22eBLU022862; Sat, 1 Dec 2012 21:40:11 -0500 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB22e6dF025602 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 1 Dec 2012 21:40:10 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TezTS-0000xh-28; Sat, 01 Dec 2012 21:40:06 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 07/10] emacs: Use --use-schema for search Date: Sat, 1 Dec 2012 21:39:59 -0500 Message-Id: <1354416002-3557-7-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu> References: <1354416002-3557-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixG6nrjtt/64Ag/anphbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxtU3Z5kLlshVbF/8mbmB8Yp4FyMnh4SAiUTHhgvsELaYxIV7 69m6GLk4hAT2MUp0dmxnAkkICaxnlGicnAyReMgk0bN6NzNEYi5Q4okwiM0moCGxbf9yRhBb REBaYufd2axdjBwczAJqEn+6VEDCwgKWEvPP/2IFsVkEVCWWLm4AK+cVsJe4PXsdI8QRihLd zyawgbRyCjhIrOjmgdhkL/H/9zW2CYz8CxgZVjHKpuRW6eYmZuYUpybrFicn5uWlFuma6eVm luilppRuYgQHjIvyDsY/B5UOMQpwMCrx8EbM2RUgxJpYVlyZe4hRkoNJSZT3yg6gEF9Sfkpl RmJxRnxRaU5q8SFGCQ5mJRFeFhOgHG9KYmVValE+TEqag0VJnPdayk1/IYH0xJLU7NTUgtQi mKwMB4eSBO/lvUCNgkWp6akVaZk5JQhpJg5OkOE8QMPD94EMLy5IzC3OTIfIn2JUlBLn9QNJ CIAkMkrz4HphEf2KURzoFWFeT5AqHmAygOt+BTSYCWjwm2XbQQaXJCKkpBoYI65+KVvN+KTi 0ozjSwP0yspOrrq9xu73Pa8lEaKuz7r/CetyMOhxaS7XX6X5qGVK4jtrO4u7014d+jj5VLvh zgvdwW55z5gXPZ/SzaYzfYNjo8uUq1HhDPdi9KN2L1d3E0vu9cpcsu23b5TEwo2OMzx9Ey75 ZomvmMRld1DS6f66WykrVlbZKrEUZyQaajEXFScCAA6i2aTDAgAA 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, 02 Dec 2012 02:40:35 -0000 We detect the special exit statuses and use these to produce specific diagnostic messages. --- emacs/notmuch-lib.el | 32 ++++++++++++++++++++++++++++++++ emacs/notmuch.el | 17 +++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 9402456..49b0da6 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -325,6 +325,38 @@ string), a property list of face attributes, or a list of these." (put-text-property pos next 'face (cons face cur)) (setq pos next))))) +(defun notmuch-pop-up-error (msg) + "Pop up an error buffer displaying MSG." + + (let ((buf (get-buffer-create "*Notmuch errors*"))) + (with-current-buffer buf + (view-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (insert msg) + (unless (bolp) + (insert "\n")) + (goto-char (point-min)))) + (pop-to-buffer buf))) + +(defun notmuch-version-mismatch-error (exit-status) + "Signal a schema version mismatch error. + +EXIT-STATUS must be the exit status of the notmuch CLI command, +and must have the value 20 or 21. This function will pop up an +error buffer with a descriptive message and signal an error." + (cond ((= exit-status 20) + (notmuch-pop-up-error "Error: Version mismatch. +Emacs requested an older output format than supported by the notmuch CLI. +You may need to restart Emacs or upgrade your notmuch Emacs package.")) + ((= exit-status 21) + (notmuch-pop-up-error "Error: Version mismatch. +Emacs requested a newer output format than supported by the notmuch CLI. +You may need to restart Emacs or upgrade your notmuch package.")) + (t + (error "Bad exit status %d" exit-status))) + (error "notmuch CLI version mismatch")) + ;; Compatibility functions for versions of emacs before emacs 23. ;; ;; Both functions here were copied from emacs 23 with the following copyright: diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f9454d8..e1f28ca 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -644,6 +644,7 @@ of the result." (exit-status (process-exit-status proc)) (never-found-target-thread nil)) (when (memq status '(exit signal)) + (catch 'return (kill-buffer (process-get proc 'parse-buf)) (if (buffer-live-p buffer) (with-current-buffer buffer @@ -655,8 +656,16 @@ of the result." (insert "Incomplete search results (search process was killed).\n")) (when (eq status 'exit) (insert "End of search results.") - (unless (= exit-status 0) - (insert (format " (process returned %d)" exit-status))) + (cond ((or (= exit-status 20) (= exit-status 21)) + (kill-buffer) + (condition-case err + (notmuch-version-mismatch-error exit-status) + ;; Strange things happen when you signal + ;; an error from a sentinel. + (error (throw 'return nil)))) + ((/= exit-status 0) + (insert (format " (process returned %d)" + exit-status)))) (insert "\n") (if (and atbob (not (string= notmuch-search-target-thread "found"))) @@ -664,7 +673,7 @@ of the result." (when (and never-found-target-thread notmuch-search-target-line) (goto-char (point-min)) - (forward-line (1- notmuch-search-target-line)))))))) + (forward-line (1- notmuch-search-target-line))))))))) (defcustom notmuch-search-line-faces '(("unread" :weight bold) ("flagged" :foreground "blue")) @@ -938,7 +947,7 @@ Other optional parameters are used as follows: (let ((proc (start-process "notmuch-search" buffer notmuch-command "search" - "--format=json" + "--format=json" "--use-schema=1" (if oldest-first "--sort=oldest-first" "--sort=newest-first") -- 1.7.10.4