On Sun, 02 Dec 2012, Austin Clements <amdragon@MIT.EDU> wrote: > 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))) I am not sure about the erase-buffer in the above: do we definitely want to remove all previous error information? For version mismatch possibly we do but in patch 9 it is done for all show command-line error returns. Incidentally why does show always pop-up an error but search only for version-mismatches? Otherwise this looks good to me (but I am not that familiar with lisp error handling) Best wishes Mark > +(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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch