0

I try to join an IRC channel with ERC in my elisp script. If there is no active ERC process running I want to create one. So far I got this:

(progn
  (if (not (and (fboundp 'erc-buffer-list)
                (erc-buffer-list)))
      (call-interactively 'twitch-chat))
  (switch-to-buffer "irc.chat.twitch.tv:6667")
  (erc-join-channel "foo"))

twitch-chat looks like this

(defun twitch-chat ()
  "connect to twitch chat"
  (interactive)
  (erc :server "irc.chat.twitch.tv"
       :port "6667"
       :password "oauth:XXX"))

The problem is that (twitch-chat) returns immediately. I get the right behaviour if ERC is already running but it fails otherwise.

  • You're dealing with an asynchronous process, so you have to wait for it to finish. You can try using (add-hook 'erc-after-connect 'FOO) for a FOO which does what you want to do at that point. See C-h v erc-after-connect for more information. (n.b. erc has some hook vars names which do not have a normal suffix :/ erc-before-connect and erc-after-connect should really have a -functions suffix). In this case you should presumably just be using the in-built erc-autojoin functionality, though. – phils Feb 25 at 11:39

Your Answer

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

Browse other questions tagged or ask your own question.