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))
                              (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.

  • 1
    The question is unclear. Please specify exactly what you are trying to do, preferably showing what (code) you already tried. – Drew May 31 '18 at 0:00
  • @Drew ok, edited with some more details. – YuriAlbuquerque May 31 '18 at 15:05
  • 2
    erc is an autoload function. If you only need to get authentication once you can call your password setup with eval-after-load for package erc.el. Is there any reason that forces you to use defadvice instead of advice-add? If you really need to call the password setup at each interactive call of erc 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))). – Tobias May 31 '18 at 20:52
  • It's still not clear (to me), what the question is. I don't see a question. – Drew May 31 '18 at 23:56
  • @Tobias no, I don't need to use defadvice, it was just one of the things I tried. – YuriAlbuquerque Jun 7 '18 at 15:36

You can create your own command to set all variables before starting ERC:

(defun my/erc-freenode ()
  (let ((erc-plist (car (auth-source-search :host "irc.freenode.net")))
        (erc-prompt-for-password nil))
    (setq erc-server "irc.freenode.net")
    (setq erc-nick (plist-get erc-plist :user))
    (setq erc-password (funcall (plist-get erc-plist :secret)))

Then, you have to type M-x my/erc-freenode to start ERC on Freenode.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.