unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
Subject: Re: [PATCH 07/10] emacs: Use --use-schema for search
Date: Sat, 08 Dec 2012 08:48:26 +0000	[thread overview]
Message-ID: <87ehj1gc9x.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1354416002-3557-7-git-send-email-amdragon@mit.edu>

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

  reply	other threads:[~2012-12-08  8:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-02  2:39 [PATCH 01/10] cli: Framework for structured output versioning Austin Clements
2012-12-02  2:39 ` [PATCH 02/10] search: Support --use-schema Austin Clements
2012-12-02  2:39 ` [PATCH 03/10] show: " Austin Clements
2012-12-02  2:39 ` [PATCH 04/10] reply: " Austin Clements
2012-12-02  2:39 ` [PATCH 05/10] test: Sanity tests for --use-schema argument Austin Clements
2012-12-02  2:39 ` [PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse error Austin Clements
2012-12-08  8:32   ` Mark Walters
2012-12-02  2:39 ` [PATCH 07/10] emacs: Use --use-schema for search Austin Clements
2012-12-08  8:48   ` Mark Walters [this message]
2012-12-13  1:43     ` Austin Clements
2012-12-13 11:00       ` Mark Walters
2012-12-02  2:40 ` [PATCH 08/10] emacs: Factor out synchronous notmuch JSON invocations Austin Clements
2012-12-02  2:40 ` [PATCH 09/10] emacs: Improve error handling for notmuch-call-notmuch-json Austin Clements
2012-12-02  2:40 ` [PATCH 10/10] emacs: Use --use-schema for show and reply Austin Clements
2012-12-03  0:58 ` [PATCH 00/10] CLI output versioning Austin Clements
2012-12-08  9:29   ` Mark Walters
2012-12-13  1:46     ` Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ehj1gc9x.fsf@qmul.ac.uk \
    --to=markwalters1009@gmail.com \
    --cc=amdragon@MIT.EDU \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).