I'm not sure if this is possible or if there's a workaround for it, but I want M-x erc
to set the password after I try to call it, but before I input the actual parameters.
What I originally had in my init.el was
(let ((erc-plist (car (auth-source-search :host "irc.freenode.net"))))
(setq erc-server "irc.freenode.net")
(setq erc-nick (plist-get erc-plist :user))
(setq erc-password (funcall (plist-get erc-plist :secret))))
But this runs on startup, which is less than ideal because I run Emacs as a systemd user unit, and it needs to decrypt authinfo.gpg
So I tried to create an advice like the following:
(defadvice erc (:before (&key (server (erc-compute-server))
(port (erc-compute-port))
(nick (erc-compute-nick))
password
(full-name (erc-compute-full-name))))
"Set up nick and password before running ERC."
(let ((erc-plist (car (auth-source-search :host "irc.freenode.net"))))
(setq erc-server "irc.freenode.net")
(setq erc-nick (plist-get erc-plist :user))
(setq erc-password (funcall (plist-get erc-plist :secret)))))
But the advice will only run after I input the parameters from ERC, so it's already too late.
I also use helm, so if it's possible to add some hook for helm to run a function right after I select erc from the menu, it would solve my problem.
erc
is an autoload function. If you only need to get authentication once you can call your password setup witheval-after-load
for packageerc.el
. Is there any reason that forces you to usedefadvice
instead ofadvice-add
? If you really need to call the password setup at each interactive call oferc
you must add an interactive-form to your advice that overrides the original interactive form. In the new interactive form you first do the password setup and afterwards do the original stuff, i.e.,(interactive (progn (...passowrd-setup...) (erc-select-read-args)))
.defadvice
, it was just one of the things I tried.