--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 080AC6DE0BF6\r
+ for <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.231\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.231 tagged_above=-999 required=5 tests=[AWL=0.339,\r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id KwcC-TjxzFOD for <notmuch@notmuchmail.org>;\r
+ Wed, 10 Feb 2016 10:50:18 -0800 (PST)\r
+Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
+ [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 184CB6DE0B36 for\r
+ <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:18 -0800 (PST)\r
+Received: by mail-wm0-f65.google.com with SMTP id p63so6034401wmp.1\r
+ for <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:18 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+ :mime-version:content-type;\r
+ bh=Sz9q4FP8+lzIPxRFUhIYBHYeH7zBzHXgmLnxB1JYcPg=;\r
+ b=BTInDxuBVLchMPvv7roA8Xr9Q18mwtLZQXgL+eJcpxY7cpbQQjdTR1+2wKNvv5t73h\r
+ Coto3acKo2XQXNYVdrePH1R7GbdzUiexZ6OYmy9TQuVEKTQAFbR8u1LGeB7y4rfB9tqh\r
+ YLVRZ4GiW4jCXy/tcY0ueOYhPaHdZW9uvp5VDBSH6DYmyGskqwlwApSmwGfwpyZsvhPD\r
+ Vf+Z2k0wXQdpTRPHydSSjecsSJurDHvcBi5R3B8MGI+jq5pyfeDrM3VQS65oDYRd6sWN\r
+ 5WlwbIYpEjw8r2l7x50TcnpHpvgnF7JMij3E9lFSky8zP/U2jGT3Vsonqc6UQstMfC8q\r
+ 8lXg==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=Sz9q4FP8+lzIPxRFUhIYBHYeH7zBzHXgmLnxB1JYcPg=;\r
+ b=jLR4/33TEe1l/6ezUxNMj1+hkc5nLyFhSNsiJf2k+8aFmx4H2GvQjnpJ+Mg9wypNqT\r
+ MdocK2gvwfB/jEe6GOUl3lqAiK5gGpglrTFcUlBh9HYrhQV4dogd0Kw5vF2tbXK+F2mu\r
+ 6U2sNXMzoFKRj6rGPp76pjWi2WThf3hMsKlRr01ZvYLocCvBNuOSu/IT1Q67ILJiLL8h\r
+ +AqUwG0qSN0mDPQJZHSiTaRrM1Q1EkGfIgpexa+ptcLGJaD9V81Ov6qSix1dwsIb/2dH\r
+ aRHdu39YztwsUfYbplwUZf8o5p1OG282oxTJdSKi1yc2xfTKhcF92fqIeXphuIcjqi3R\r
+ NEOg==\r
+X-Gm-Message-State:\r
+ AG10YOTuogozUK/7YOdEu2gQqe2LxGM9V5QBYKRJUVxjveR7Xd9rbTs//2CKNTONdwTiUQ==\r
+X-Received: by 10.28.174.72 with SMTP id x69mr12665074wme.68.1455130216412;\r
+ Wed, 10 Feb 2016 10:50:16 -0800 (PST)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by smtp.gmail.com with ESMTPSA id i12sm4626997wmf.10.2016.02.10.10.50.15\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Wed, 10 Feb 2016 10:50:15 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2] emacs: Report a lack of matches when calling\r
+ `notmuch-show'.\r
+In-Reply-To: <1455112878-23497-2-git-send-email-dme@dme.org>\r
+References: <1455112878-23497-1-git-send-email-dme@dme.org>\r
+ <1455112878-23497-2-git-send-email-dme@dme.org>\r
+User-Agent: Notmuch/0.18.1+485~gca076ce (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Wed, 10 Feb 2016 18:50:14 +0000\r
+Message-ID: <87oabo5rix.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 10 Feb 2016 18:50:21 -0000\r
+\r
+\r
+\r
+On Wed, 10 Feb 2016, David Edmondson <dme@dme.org> wrote:\r
+> If the basic query passed to `notmuch-show' generates no results, ring\r
+> the bell and inform the user that no messages matched the query rather\r
+> than displaying an empty buffer and showing an obscure error.\r
+>\r
+> Similarly when refreshing a `notmuch-show' buffer and no messages match.\r
+\r
+This basically looks fine to me and all tests pass. The code movement\r
+and cleanup all looks fine. Two minor things, one tiny nit below; and I\r
+wonder whether just having the buffer say "No search results" (or\r
+something similar) and leave the user to kill it would be nicer than\r
+dinging (and more in line with the way search and tree behave).\r
+\r
+[In some sense I think this way is right and search and tree are wrong,\r
+but that is probably difficult to get round as search and tree run\r
+asynchronously.]\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+> ---\r
+> emacs/notmuch-show.el | 144 +++++++++++++++++++++++++++++---------------------\r
+> emacs/notmuch.el | 6 ++-\r
+> 2 files changed, 89 insertions(+), 61 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 3345878..9a74848 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -153,27 +153,21 @@ indentation."\r
+> \r
+> (defvar notmuch-show-thread-id nil)\r
+> (make-variable-buffer-local 'notmuch-show-thread-id)\r
+> -(put 'notmuch-show-thread-id 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-parent-buffer nil)\r
+> (make-variable-buffer-local 'notmuch-show-parent-buffer)\r
+> -(put 'notmuch-show-parent-buffer 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-query-context nil)\r
+> (make-variable-buffer-local 'notmuch-show-query-context)\r
+> -(put 'notmuch-show-query-context 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-process-crypto nil)\r
+> (make-variable-buffer-local 'notmuch-show-process-crypto)\r
+> -(put 'notmuch-show-process-crypto 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-elide-non-matching-messages nil)\r
+> (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)\r
+> -(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-indent-content t)\r
+> (make-variable-buffer-local 'notmuch-show-indent-content)\r
+> -(put 'notmuch-show-indent-content 'permanent-local t)\r
+> \r
+> (defvar notmuch-show-attachment-debug nil\r
+> "If t log stdout and stderr from attachment handlers\r
+> @@ -1197,71 +1191,101 @@ non-nil.\r
+> The optional BUFFER-NAME provides the name of the buffer in\r
+> which the message thread is shown. If it is nil (which occurs\r
+> when the command is called interactively) the argument to the\r
+> -function is used."\r
+> +function is used.\r
+> +\r
+> +Returns the buffer containing the messages, or NIL if no messages\r
+> +matched."\r
+> (interactive "sNotmuch show: \nP")\r
+> (let ((buffer-name (generate-new-buffer-name\r
+> (or buffer-name\r
+> (concat "*notmuch-" thread-id "*")))))\r
+> (switch-to-buffer (get-buffer-create buffer-name))\r
+> - ;; Set the default value for `notmuch-show-process-crypto' in this\r
+> - ;; buffer.\r
+> - (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
+> - ;; Set the default value for\r
+> - ;; `notmuch-show-elide-non-matching-messages' in this buffer. If\r
+> - ;; elide-toggle is set, invert the default.\r
+> - (setq notmuch-show-elide-non-matching-messages notmuch-show-only-matching-messages)\r
+> - (if elide-toggle\r
+> - (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages)))\r
+> + ;; No need to track undo information for this buffer.\r
+> + (setq buffer-undo-list t)\r
+> +\r
+> + (notmuch-show-mode)\r
+> \r
+> + ;; Set various buffer local variables to their appropriate initial\r
+> + ;; state. Do this after enabling `notmuch-show-mode' so that they\r
+> + ;; aren't wiped out.\r
+> (setq notmuch-show-thread-id thread-id\r
+> notmuch-show-parent-buffer parent-buffer\r
+> - notmuch-show-query-context query-context)\r
+> - (notmuch-show-build-buffer)\r
+> - (notmuch-show-goto-first-wanted-message)\r
+> - (current-buffer)))\r
+> + notmuch-show-query-context query-context\r
+> \r
+> -(defun notmuch-show-build-buffer ()\r
+> - (let ((inhibit-read-only t))\r
+> + notmuch-show-process-crypto notmuch-crypto-process-mime\r
+> + ;; If `elide-toggle', invert the default value.\r
+> + notmuch-show-elide-non-matching-messages\r
+> + (if elide-toggle\r
+> + (not notmuch-show-only-matching-messages)\r
+> + notmuch-show-only-matching-messages))\r
+> \r
+> - (notmuch-show-mode)\r
+> (add-hook 'post-command-hook #'notmuch-show-command-hook nil t)\r
+> -\r
+> - ;; Don't track undo information for this buffer\r
+> - (set 'buffer-undo-list t)\r
+> + (jit-lock-register #'notmuch-show-buttonise-links)\r
+> \r
+> (notmuch-tag-clear-cache)\r
+> - (erase-buffer)\r
+> - (goto-char (point-min))\r
+> - (save-excursion\r
+> - (let* ((basic-args (list notmuch-show-thread-id))\r
+> - (args (if notmuch-show-query-context\r
+> - (append (list "\'") basic-args\r
+> - (list "and (" notmuch-show-query-context ")\'"))\r
+> - (append (list "\'") basic-args (list "\'"))))\r
+> - (cli-args (cons "--exclude=false"\r
+> - (when notmuch-show-elide-non-matching-messages\r
+> - (list "--entire-thread=false")))))\r
+> -\r
+> - (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))\r
+> - ;; If the query context reduced the results to nothing, run\r
+> - ;; the basic query.\r
+> - (when (and (eq (buffer-size) 0)\r
+> - notmuch-show-query-context)\r
+> - (notmuch-show-insert-forest\r
+> - (notmuch-query-get-threads (append cli-args basic-args)))))\r
+> -\r
+> - (jit-lock-register #'notmuch-show-buttonise-links)\r
+> -\r
+> - (notmuch-show-mapc (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
+> +\r
+> + (let ((inhibit-read-only t))\r
+> + (if (notmuch-show--build-buffer)\r
+> + ;; Messages were inserted into the buffer.\r
+> + (current-buffer)\r
+> +\r
+> + ;; No messages were inserted - presumably none matched the\r
+> + ;; query.\r
+> + (kill-buffer (current-buffer))\r
+> + (ding)\r
+> + (message "No messages matched the query!")\r
+> + nil))))\r
+> +\r
+> +(defun notmuch-show--build-buffer (&optional state)\r
+> + "Display messages matching the current buffer context.\r
+> +\r
+> +Apply the previously saved STATE if supplied, otherwise show the\r
+> +first relevant message.\r
+> +\r
+> +If no messages match the query return NIL."\r
+> + (let* ((basic-args (list notmuch-show-thread-id))\r
+> + (args (if notmuch-show-query-context\r
+> + (append (list "\'") basic-args\r
+> + (list "and (" notmuch-show-query-context ")\'"))\r
+> + (append (list "\'") basic-args (list "\'"))))\r
+> + (cli-args (cons "--exclude=false"\r
+> + (when notmuch-show-elide-non-matching-messages\r
+> + (list "--entire-thread=false"))))\r
+> +\r
+> + (forest (or (notmuch-query-get-threads (append cli-args args))\r
+> + ;; If a query context reduced the number of\r
+> + ;; results to zero, try again without it.\r
+> + (and notmuch-show-query-context\r
+> + (notmuch-query-get-threads (append cli-args basic-args)))))\r
+> +\r
+> + ;; Must be reset every time we are going to start inserting\r
+> + ;; messages into the buffer.\r
+> + (notmuch-show-previous-subject ""))\r
+> +\r
+> + (when forest\r
+> + (notmuch-show-insert-forest forest)\r
+> +\r
+> + ;; Cache the original tags for each message so that we can display\r
+> + ;; changes.\r
+\r
+^^ I think "Store the original tags for each message" would be better,\r
+particularly as this is nothing to do with the tag cache as used by say\r
+notmuch-tag-clear-cache.\r
+\r
+\r
+> + (notmuch-show-mapc\r
+> + (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
+> \r
+> ;; Set the header line to the subject of the first message.\r
+> (setq header-line-format\r
+> (replace-regexp-in-string "%" "%%"\r
+> - (notmuch-sanitize\r
+> - (notmuch-show-strip-re\r
+> - (notmuch-show-get-subject)))))\r
+> + (notmuch-sanitize\r
+> + (notmuch-show-strip-re\r
+> + (notmuch-show-get-subject)))))\r
+> \r
+> - (run-hooks 'notmuch-show-hook))))\r
+> + (run-hooks 'notmuch-show-hook)\r
+> +\r
+> + (if state\r
+> + (notmuch-show-apply-state state)\r
+> + ;; With no state to apply, just go to the first message.\r
+> + (notmuch-show-goto-first-wanted-message)))\r
+> +\r
+> + ;; Report back to the caller whether any messages matched.\r
+> + forest))\r
+> \r
+> (defun notmuch-show-capture-state ()\r
+> "Capture the state of the current buffer.\r
+> @@ -1320,17 +1344,17 @@ reset based on the original query."\r
+> (let ((inhibit-read-only t)\r
+> (state (unless reset-state\r
+> (notmuch-show-capture-state))))\r
+> - ;; erase-buffer does not seem to remove overlays, which can lead\r
+> + ;; `erase-buffer' does not seem to remove overlays, which can lead\r
+> ;; to weird effects such as remaining images, so remove them\r
+> ;; manually.\r
+> (remove-overlays)\r
+> (erase-buffer)\r
+> - (notmuch-show-build-buffer)\r
+> - (if state\r
+> - (notmuch-show-apply-state state)\r
+> - ;; We're resetting state, so navigate to the first open message\r
+> - ;; and mark it read, just like opening a new show buffer.\r
+> - (notmuch-show-goto-first-wanted-message))))\r
+> +\r
+> + (unless (notmuch-show--build-buffer state)\r
+> + ;; No messages were inserted.\r
+> + (kill-buffer (current-buffer))\r
+> + (ding)\r
+> + (message "Refreshing the buffer resulted in no messages!"))))\r
+> \r
+> (defvar notmuch-show-stash-map\r
+> (let ((map (make-sparse-keymap)))\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 463b926..3100b97 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -458,7 +458,11 @@ no messages in the region then return nil."\r
+> (notmuch-search-properties-in-region :subject beg end))\r
+> \r
+> (defun notmuch-search-show-thread (&optional elide-toggle)\r
+> - "Display the currently selected thread."\r
+> + "Display the currently selected thread.\r
+> +\r
+> +With a prefix argument, invert the default value of\r
+> +`notmuch-show-only-matching-messages' when displaying the\r
+> +thread."\r
+> (interactive "P")\r
+> (let ((thread-id (notmuch-search-find-thread-id))\r
+> (subject (notmuch-search-find-subject)))\r
+> -- \r
+> 2.1.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> https://notmuchmail.org/mailman/listinfo/notmuch\r