From 9fc30d4c309798172566b38aae0151da1d555379 Mon Sep 17 00:00:00 2001
From: Amin Bandali <mab@gnu.org>
Date: Thu, 4 Jul 2019 13:00:47 -0400
Subject: [PATCH] emacs: try out pinentry
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

setting pinentry--socket-dir is needed because /tmp/emacs1000 is a
symlink on systemd systems and doesn’t pass server-ensure-safe-dir.
---
 .config/getmail/getmailrc             |  2 +-
 .emacs.d/init.el                      | 14 +++++++++++++-
 .emacs.d/straight/versions/default.el |  1 +
 .gnupg/gpg-agent.conf                 |  1 +
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/.config/getmail/getmailrc b/.config/getmail/getmailrc
index 60ad43d..e89702a 100644
--- a/.config/getmail/getmailrc
+++ b/.config/getmail/getmailrc
@@ -2,7 +2,7 @@
 type = SimplePOP3SSLRetriever
 server = fencepost.gnu.org
 username = bandali
-password_command = ("gpg2", "--no-tty", "-q", "-d", "/home/amin/.passwd/gnu.gpg")
+password_command = ("gpg", "--no-tty", "-q", "-d", "/home/amin/.passwd/gnu.gpg")
 port = 995
 use_apop = True
 
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 535e7c5..f5e87ec 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -295,7 +295,19 @@ For disabling the behaviour for certain buffers and/or modes."
   :config (pixel-scroll-mode 1))
 
 ;; ask for GPG passphrase in minibuffer
-(setq epg-pinentry-mode 'loopback)
+(use-feature epg-config
+  :defer 0.4
+  :custom
+  ((epg-gpg-program (executable-find "gpg"))
+   (epg-pinentry-mode 'loopback)))
+(use-feature epg
+  :after epg-config)
+(use-package pinentry
+  :demand
+  :after (epg server)
+  :config
+  (setq pinentry--socket-dir server-socket-dir)
+  (pinentry-start))
 
 ;; useful libraries
 (require 'cl-lib)
diff --git a/.emacs.d/straight/versions/default.el b/.emacs.d/straight/versions/default.el
index df62b3a..af4b551 100644
--- a/.emacs.d/straight/versions/default.el
+++ b/.emacs.d/straight/versions/default.el
@@ -79,6 +79,7 @@
  ("password-store" . "5a52772156b44ef9785e91ab78ab2e1c3b1e510e")
  ("password-store-otp.el" . "1819cd88463cd98a5be9a63273b09202dc2bba63")
  ("pdf-tools" . "db7de3901ae0e55f6ab8cf9baec257f706c3d16e")
+ ("pinentry" . "cd942f755c38a7ac270ce858bb887ebdd59edd26")
  ("pkg-info.el" . "76ba7415480687d05a4353b27fea2ae02b8d9d61")
  ("popup-el" . "80829dd46381754639fb764da11c67235fe63282")
  ("projectile" . "71a01f409a319d57eb3832e93e8a412fbc9d7a65")
diff --git a/.gnupg/gpg-agent.conf b/.gnupg/gpg-agent.conf
index 9fd7c4f..6b5bd7d 100644
--- a/.gnupg/gpg-agent.conf
+++ b/.gnupg/gpg-agent.conf
@@ -4,5 +4,6 @@ max-cache-ttl 43200
 default-cache-ttl-ssh 10800
 max-cache-ttl-ssh 10800
 
+# allow-emacs-pinentry
 allow-loopback-pinentry
 pinentry-program /usr/bin/pinentry-gnome3
-- 
2.20.1