11

Using Emacs for Mac OS X 25.1.1 and gnupg2 2.0.30 installed via homebrew on macOS Sierra 10.12.2.

Emacs works correctly and gnugp2 also works well on the command line level (email addresses removed):

pu@pumbair.local 528 ~/Dropbox/org $  echo "Hello World" >text.txt
pu@pumbair.local 536 ~/Dropbox/org $  gpg -a -e -r x@y <text.txt >text.gpg
pu@pumbair.local 537 ~/Dropbox/org $  gpg -d text.gpg
You need a passphrase to unlock the secret key for
2048-bit RSA key, ID 37B58834, created 2017-01-18 (main key ID 45C04EA8)
gpg: encrypted with 2048-bit RSA key, ID 37B58834, created 2017-01-18
Hello World

My ./emacs/init.el says

; gpg
(require 'epa-file)
(epa-file-enable)
(setq epg-gpg-program "/usr/local/bin/gpg2")

and

pu@pumbair.local 505 ~/.emacs.d $  file /usr/local/bin/gpg2
/usr/local/bin/gpg2: Mach-O 64-bit executable x86_64

but I cannot seem to get Emacs to use gpg2; Meta-x epa-list-keys yields:

GPG error: "no usable configuration", OpenPGP

I'm using gpg and gpg2 here but the first is a symlink to the latter.

What did I miss?

EDIT

Browsing trough EasyPG's source I got the impression that it only worked with gpg2 2.1+ so I uninstalled the homebrew version and installed version 2.1.17 from Sourceforge but that didn't help either.

uselpa
  • 18,732
  • 2
  • 34
  • 52

2 Answers2

19

So I ended up browsing some source files related to this question and mailed Daiki Ueno directly. He replied quickly, telling me to use custom-set-variables instead of setq:

(require 'epa-file)
(custom-set-variables '(epg-gpg-program  "/usr/local/bin/gpg2"))
(epa-file-enable)

I assume this is obvious to Emacs people but I hardly use Emacs for anything else than org-mode, so it wasn't for me.

uselpa
  • 18,732
  • 2
  • 34
  • 52
  • 2
    As a regular emacs users this is not obvious, and something that is advertised as working out of the box – kevzettler Mar 18 '17 at 22:25
  • 1
    Looks like it's a bug we cannot use `setq` and have to resort to `customize`: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24229 – ctietze Apr 10 '18 at 13:58
  • gpg changed folder I think - should now be (custom-set-variables '(epg-gpg-program "/usr/local/bin/gpg")) – Henrik K Jan 27 '19 at 21:32
3

gpg in only inside /usr/local/gnupg-2.2/bin. In Eamcs, (getenv "Path") and exec-path only contains /usr/bin, but new version of macOS restricts the access of /usr/bin.

My solution is to create a symbolic link and add the path into the emacs environment and its exec path.

cd /usr/local/bin
ln -s ../gnupg-2.2/bin/gpg2 gpg

Inside .emacs

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
(setq exec-path (append exec-path '("/usr/local/bin")))
code4j
  • 4,208
  • 5
  • 34
  • 51