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 177006DE0278 for ; Mon, 1 Oct 2018 09:06:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.398 X-Spam-Level: X-Spam-Status: No, score=0.398 tagged_above=-999 required=5 tests=[AWL=-0.255, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 nC2YqovUjZhG for ; Mon, 1 Oct 2018 09:06:38 -0700 (PDT) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by arlo.cworth.org (Postfix) with ESMTPS id 17E0F6DE0275 for ; Mon, 1 Oct 2018 09:06:38 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id s12-v6so9393732wmc.0 for ; Mon, 01 Oct 2018 09:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5V4kp2fAneTvBZQA3Y+VE1waigUmO94ZwUxHColtkGk=; b=JlGbtqHwa21nXpghMFtxanKQhkYmM83I1JOgGQQGeEPOshELrtXBuVxY8xfIKeCKwD 7jcl8v8Z89Ff6Yx1BGHxofFb8HJz1HK7W012s+fAgaplbtDmBu0Xzf4AR9N/vX5n26CK BtvMYRqrxCFlratKHzMbnN0Nd03AN7P/Pv/6r+CILEO8iqGVHDsFtjBnrf5FEEUma9yX dRrh3ZwpnEhxyvkd/S0xjKWxUQgGV498Tds/96HbAlM9fV9mh7BjCFRDF9sLHxkDuO31 oIQoLCu8bT5gDN4HzWOrht8XpHj5UomtgIuh+sLD3Cgm2swj0GBOMs8PGiJ4eQFfaGR4 q+EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5V4kp2fAneTvBZQA3Y+VE1waigUmO94ZwUxHColtkGk=; b=f3Guf9ZV83q5fiHX6z/Og48UClfg7y6JB3x/UM1WHiY2Q1aTxfW0tW+am5u7mAkGcR PsmpWuRiDI4Ow9bKOITQdRX8pUGtZnLgJexptHBQag/OzDbvEhvMX421G6MJVWkLTCye dVRrKr8YkAzGueV5CTxYY5VdRxUyJor/P6igGLSCffgXngjm/icCGlNN2DjZrIrt/aiT pgJHCZocdbhaF/6PMsXWpBpm05Qsyp9KrGUNXxYLZi0aW3sweoYQghaxdIhS5YZQTnts OZflBTbOaEk0MjH6LAsqw1TaVS/4BegameyTbglnFR8jCR2ggSAd9Mzqu4279wQyHWcl gAPA== X-Gm-Message-State: ABuFfoiRi/CpiK8H9IKxRJ9VwWHRopjZoAfcBAvIcemovqmzoaDGqQO/ 5+mLN305sNIoxw0oB7fkM62JJ0urhEI+yw== X-Google-Smtp-Source: ACcGV63G7ZVeOJpHzm/hjmL90BBpXK2jGSvwCI7UAekPkHxnOK6L9Yv0kyXmaxj0Bgvk9PBJkQ71vw== X-Received: by 2002:a1c:5d54:: with SMTP id r81-v6mr8903255wmb.88.1538409996200; Mon, 01 Oct 2018 09:06:36 -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 t14-v6sm8601422wmi.35.2018.10.01.09.06.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 09:06:35 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 0f2f1e23 for ; Mon, 1 Oct 2018 16:06:33 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v3 1/4] emacs: Asynchronous retrieval of GPG keys Date: Mon, 1 Oct 2018 17:06:30 +0100 Message-Id: <20181001160633.26775-2-dme@dme.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001160633.26775-1-dme@dme.org> References: <20181001160633.26775-1-dme@dme.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, 01 Oct 2018 16:06:39 -0000 Rather than blocking emacs while gpg does its' thing, by default run key retrieval asynchronously, possibly updating the display of the message on successful completion. --- emacs/notmuch-crypto.el | 85 +++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el index fc2b5301..c20fd4f8 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)) @@ -113,7 +118,7 @@ mode." (let ((keyid (concat "0x" (plist-get sigstatus :keyid)))) (setq label (concat "Unknown key ID " keyid " or unsupported algorithm")) (setq button-action 'notmuch-crypto-sigstatus-error-callback) - (setq help-msg (concat "Click to retrieve key ID " keyid " from keyserver and redisplay.")))) + (setq help-msg (concat "Click to retrieve key ID " keyid " from keyserver.")))) ((string= status "bad") (let ((keyid (concat "0x" (plist-get sigstatus :keyid)))) (setq label (concat "Bad signature (claimed key ID " keyid ")")) @@ -145,19 +150,77 @@ mode." (call-process epg-gpg-program nil t t "--list-keys" fingerprint)) (recenter -1)))) +(defun notmuch-crypto--async-key-sentinel (process event) + "When the user asks for a GPG key to be retrieved +asynchronously, handle completion of that task. + +If the retrieval is successful, the thread where the retrieval +was initiated is still displayed and the cursor has not moved, +redisplay the thread." + (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 the original buffer is still alive and point didn't move + ;; (i.e. the user didn't move on or away), refresh the buffer to + ;; show the updated signature status. + (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) + (= show-point + (with-current-buffer show-buffer + (point)))) + (with-current-buffer show-buffer + (notmuch-show-refresh-view))))))) + +(defun notmuch-crypto--set-button-label (button label) + "Set the text displayed in BUTTON to LABEL." + (save-excursion + (let ((inhibit-read-only t)) + ;; This knows rather too much about how we typically format + ;; buttons. + (goto-char (button-start button)) + (forward-char 2) + (delete-region (point) (- (button-end button) 2)) + (insert label)))) + (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 + (progn + (notmuch-crypto--set-button-label + button (format "Retrieving key %s asynchronously..." keyid)) + (let ((p (make-process :name "notmuch GPG key retrieval" + :buffer buffer + :command (list epg-gpg-program "--recv-keys" keyid) + :connection-type 'pipe + :sentinel #'notmuch-crypto--async-key-sentinel + ;; Create the process stopped so that + ;; we have time to store the key id, + ;; etc. 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)) -- 2.19.0