From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 2026D6DE0A9A for ; Mon, 3 Sep 2018 11:19:49 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.408 X-Spam-Level: X-Spam-Status: No, score=0.408 tagged_above=-999 required=5 tests=[AWL=-0.225, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_NEUTRAL=0.652, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v-ZDr3EdmbgY for ; Mon, 3 Sep 2018 11:19:48 -0700 (PDT) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by arlo.cworth.org (Postfix) with ESMTPS id F39486DE0A90 for ; Mon, 3 Sep 2018 11:19:47 -0700 (PDT) Received: by mail-wm0-f50.google.com with SMTP id y139-v6so1964926wmc.2 for ; Mon, 03 Sep 2018 11:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=to:subject:in-reply-to:references:from:date:message-id:mime-version; bh=Efks8mK4gshubvoXVexKBBijihHHk4BuEipyYsv+rcs=; b=1zgvWBbeYV8wQGLVktW6nXZHndkmJJFkR602yq06uXPd5bilteTyWpukk49wBZ4Uye bZNUp8YmEY2+eR6IMGyHq7jLYpUOArl0YvPFlnySPcKDaXqFtwOSUwJpDCxVZiXyhz/p +aT/wsSKiqENdQVLQXJT/1aTWfobpY5Ux2jLj/Oin085tktfbH9e+abP8e3fOWtHGLO6 PPLzUBeT7DK9BD4NtqCrY/zABVwvl233GD0nRvKvmUx0jyo4hTnnYmfncAywcNK36G5d JlO4QfFeh19cOhjK4oBQ6SsxJ5icyTjE6GOHiTYu3r8u5ftqXvm3aMF3yyncfvj3l7jy 7ecw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:subject:in-reply-to:references:from:date :message-id:mime-version; bh=Efks8mK4gshubvoXVexKBBijihHHk4BuEipyYsv+rcs=; b=UOvBmW1lQd8vG8v+g8LjU2CqPPj8jexDKOsy1ONvN8HB54KSz0lmf6asZJqnSSk2bt jXq/VMtT+s1ukzyGcI0AMrfuGwx/EWfPUAEhlLBInh9XvAz+H2K4/u7j/sEbStKvRNxM PKMdnbNWlvIq4TtxhwKiHwYKaHb4g+B+vOZdgn6B2CxI6UqMcejSI6fBc0Ubec9GTRMx OfeIpQxeyNMv3uTr22Q1jAU7VkLIJ5hISjrjGCzn4q9ff4CNs99iGmoEfP3VxPGQSUtc SI1usm2EoguIWvnyovf22kKVP8QB5WClGQjsuTABxBgJij8AYRMJVlR1zUtjWxk9PFfG RaKQ== X-Gm-Message-State: APzg51An8V4jn6NMWajZxHAb+iU/UtRPBJD/DSi6O5BmWwdVotJTj6wY QJg8r9+UwUVSfecJZpd0oqR47f8+ki6ksw== X-Google-Smtp-Source: ANB0VdaRDH6dgSvIa7hWqblycPzcN3GfzNKOBz5rH0SXd9hlxJTax9jSgfCJz7gTJ5ZJ+Ba2XAeyAg== X-Received: by 2002:a1c:b54b:: with SMTP id e72-v6mr6138277wmf.117.1535998786200; Mon, 03 Sep 2018 11:19:46 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by smtp.gmail.com with ESMTPSA id s10-v6sm16995154wmd.22.2018.09.03.11.19.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 11:19:45 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 66058f4d; Mon, 3 Sep 2018 18:19:44 +0000 (UTC) To: Antoine =?utf-8?Q?Beaupr=C3=A9?= , notmuch@notmuchmail.org Subject: Re: PATCH: fetch missing keys in the background In-Reply-To: <87sh2qv5gi.fsf@curie.anarc.at> References: <871saawphm.fsf@curie.anarc.at> <87va7mv75u.fsf@curie.anarc.at> <87sh2qv5gi.fsf@curie.anarc.at> X-HGTTG: disaster-area From: David Edmondson Date: Mon, 03 Sep 2018 19:19:44 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 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: Mon, 03 Sep 2018 18:19:49 -0000 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Monday, 2018-09-03 at 13:47:09 -0400, Antoine Beaupr=C3=A9 wrote: > On 2018-09-03 18:21:32, David Edmondson wrote: >> How about this patch? >> >> You'll need to set =E2=80=9Cnotmuch-crypto-get-keys-asynchronously=E2=80= =9D to =E2=80=9Ct=E2=80=9D to >> see any benefit. > > This is great! > > As you said on IRC, the patch is more likely: Another version, which attempts to redisplay the buffer if it thinks that it's safe and sensible to do so. This version *defaults* to async behaviour, as I think that it's safe to do so. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=async-keys.patch diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el index fc2b5301..6e003f51 100644 --- a/emacs/notmuch-crypto.el +++ b/emacs/notmuch-crypto.el @@ -43,6 +43,11 @@ mode." :package-version '(notmuch . "0.25") :group 'notmuch-crypto) +(defcustom notmuch-crypto-get-keys-asynchronously t + "Retrieve gpg keys asynchronously." + :type 'boolean + :group 'notmuch-crypto) + (defface notmuch-crypto-part-header '((((class color) (background dark)) @@ -145,19 +150,56 @@ mode." (call-process epg-gpg-program nil t t "--list-keys" fingerprint)) (recenter -1)))) +(defun notmuch-crypto--async-key-sentinel (process event) + (let ((status (process-status process)) + (exit-status (process-exit-status process)) + (keyid (process-get process :gpg-key-id))) + (when (memq status '(exit signal)) + (message "Getting the GPG key %s asynchronously...%s." + keyid + (if (= exit-status 0) + "completed" + "failed")) + ;; If retrieving the key was successful, the original buffer is + ;; still alive and point didn't move (i.e. the user didn't move + ;; on or away), refresh the buffer. + (when (= exit-status 0) + (let ((show-buffer (process-get process :notmuch-show-buffer)) + (show-point (process-get process :notmuch-show-point))) + (when (and (bufferp show-buffer) + (buffer-live-p show-buffer) + (with-current-buffer show-buffer + (= show-point (point)))) + (with-current-buffer show-buffer + (notmuch-show-refresh-view)))))))) + (defun notmuch-crypto-sigstatus-error-callback (button) (let* ((sigstatus (button-get button :notmuch-sigstatus)) (keyid (concat "0x" (plist-get sigstatus :keyid))) - (buffer (get-buffer-create "*notmuch-crypto-gpg-out*")) - (window (display-buffer buffer t nil))) - (with-selected-window window - (with-current-buffer buffer - (goto-char (point-max)) - (call-process epg-gpg-program nil t t "--recv-keys" keyid) - (insert "\n") - (call-process epg-gpg-program nil t t "--list-keys" keyid)) - (recenter -1)) - (notmuch-show-refresh-view))) + (buffer (get-buffer-create "*notmuch-crypto-gpg-out*"))) + (if notmuch-crypto-get-keys-asynchronously + (let ((p (make-process :name "notmuch GPG key retrieval" + :buffer buffer + :command (list epg-gpg-program "--recv-keys" keyid) + :sentinel #'notmuch-crypto--async-key-sentinel + ;; Create the process stopped so that + ;; we have time to store the key id on + ;; it. + :stop t))) + (process-put p :gpg-key-id keyid) + (process-put p :notmuch-show-buffer (current-buffer)) + (process-put p :notmuch-show-point (point)) + (message "Getting the GPG key %s asynchronously..." keyid) + (continue-process p)) + (let ((window (display-buffer buffer t nil))) + (with-selected-window window + (with-current-buffer buffer + (goto-char (point-max)) + (call-process epg-gpg-program nil t t "--recv-keys" keyid) + (insert "\n") + (call-process epg-gpg-program nil t t "--list-keys" keyid)) + (recenter -1)) + (notmuch-show-refresh-view))))) (defun notmuch-crypto-insert-encstatus-button (encstatus) (let* ((status (plist-get encstatus :status)) --=-=-= Content-Type: text/plain dme. -- Please don't stand so close to me. --=-=-=--