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 D22256DE00C6 for ; Fri, 7 Sep 2018 04:29:31 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.396 X-Spam-Level: X-Spam-Status: No, score=0.396 tagged_above=-999 required=5 tests=[AWL=-0.237, 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 0Rrg3U2c3WF8 for ; Fri, 7 Sep 2018 04:29:31 -0700 (PDT) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by arlo.cworth.org (Postfix) with ESMTPS id 8C9986DE00EF for ; Fri, 7 Sep 2018 04:29:27 -0700 (PDT) Received: by mail-wm0-f47.google.com with SMTP id 207-v6so14206691wme.5 for ; Fri, 07 Sep 2018 04:29:27 -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; bh=mwLMbqjnlzyG2ljaPR6fjdOq4uFy/xTLx7tsovfcv+Q=; b=ERlfILf4DHxhcqztxZgjmpwGmj3ydXSdqg/IiAslNQQHVnUoEI0TQ6P2NAR25MYODL R11iuiEEMmuIfrAku5EC+XfDT35bjmlScf1/0jwkzyJq/KKA4fB5xwoXiRBUw6W7jh24 OhEto54WOe/MebyWsvQQOSmT63K/8whKTnFXLu1co0CKtmlV7+y0UZg8EXDuJCoia9TQ WMXTQ1fzCNERBmQ0+YDe4GTmmnXZh+t6BLR+mBHu7K3sPowW8pHHb/0VyvIPw9g5lv+g C1nfR9tjkEXwbH2v2No+0cCqE+4NqfBFZHxlGS8BRhKEnXMklArOj5YeuyyLWIifdHiZ QrkQ== 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; bh=mwLMbqjnlzyG2ljaPR6fjdOq4uFy/xTLx7tsovfcv+Q=; b=oY5ezg5ofDMk8Htr5GioY/6EAAuaQXpxWSXwC6Qgt9n67cuBHYqSnJXUWM9xjGnVls Ib+hWeyZIJEnGWPWbf8FNVu5oHOoB38k7JB4+3o3P2pWWNQ12rUaFjt/GOEIiqaNGPT3 DgnI+17Je/5gNMK9jAYDqqBDQI6zBWFn1x45LrUD+W+um2IOSXLZYHg3mqXLXVpbcqEr QGZIdhYS+Fneu16/DNacfVstX6e01/yZ9Jg0Gppn9iUN9ygj2yplcwk5iSqAByeyQA90 waF70mxlB4zuCDajSDXa+VkGX0H1Ykajqpfceqa8luhzf2RQgbdH+Wd2O8rj9U6ONSWK elvQ== X-Gm-Message-State: APzg51BamtiRRbhE8cYqOgmdEL5MlKIGPrDvu4M6A/ZawE5c8QE8H0HK 5emyEe5UpfNQWSR4GpQgmhi0LVBh4eg= X-Google-Smtp-Source: ANB0Vdblm1rlooOaASXXnE8RXp/oYTaPeXwsjdpKhUHUOXNHAaO2340PZux96of9HtkX3zMKSKG4zA== X-Received: by 2002:a1c:c147:: with SMTP id r68-v6mr5081548wmf.161.1536319763945; Fri, 07 Sep 2018 04:29:23 -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 66-v6sm10414866wmw.34.2018.09.07.04.29.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:29:22 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 9f64758b for ; Fri, 7 Sep 2018 11:29:21 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v2 1/4] emacs: Asynchronous retrieval of GPG keys Date: Fri, 7 Sep 2018 12:29:17 +0100 Message-Id: <20180907112920.3130-2-dme@dme.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180907112920.3130-1-dme@dme.org> References: <20180907112920.3130-1-dme@dme.org> 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: Fri, 07 Sep 2018 11:29:31 -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 | 79 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el index fc2b5301..ddb447a6 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,73 @@ 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." + (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.11.0