Chat Like the 90’s in Emacs with ERC

Yet another thing Emacs can do!

If you haven’t already heard, it’s possible to do yet another thing in Emacs that you might already be doing on a daily basis using some other set of programs. We’ve already seen on this channel that you can use Emacs for your e-mail, so it probably won’t come as a surprise that you can also use Emacs as a chat client!

In this episode show you the basics of using the IRC chat protocol with Emacs’ built-in client called ERC so that you can chat with other people from the comfort of your Emacs window!

What is IRC?

Internet Relay Chat, commonly known as IRC, is a protocol that enables real-time chat across a number of servers that are connected together to form something called an IRC network. You might have heard of Freenode, EFNet, DALnet, and many other popular IRC networks.

If you’re not familiar with IRC, you can think of it like a Slack or Discord server; you join a server on a particular IRC network and there are a bunch of channels that you can join to chat about a variety of topics. One difference though is that you must join the channels you want to participate in. You also don’t see the history of a channel when you join it like you do in Slack or Discord; I’ll show some ways to fix that in a future video.

The nice thing about IRC is that it’s an open protocol which means there are an incredible number of clients available for it on the Internet. What’s even better is that can join a server right now with no account creation necessary using packages that are already included with Emacs!

We’re going to take a look at one of them today: ERC.

What is ERC?

ERC is a featureful and extensible IRC client written in Emacs Lisp. It’s not the only IRC client that comes with Emacs (see rcirc) but it’s probably the one that you’ll want to use long-term if you stick with in-box clients.

Useful Features

  • Connect to multiple servers at once
  • Can complete the names of other users while typing
  • Highlighting for your name or other terms in messages
  • Channel tracking to show channel activity in the mode line
  • Show emojis in messages
  • Desktop notifications when mentioned or messaged (enabled as a module)
  • Easy to script it with new behavior!

One nice thing about it is that you don’t really even need to configure it to use it, you can run it right out of the box!

ERC Manual

Joining a server

Joining a server with ERC is very easy, you can just run M-x erc-tls to connect to a particular IRC server address and you’ll be prompted for your “nickname” (the name you will use on the server) and your password. You can skip the password prompt since you may not have an account yet!

You can also use M-x erc but I highly recommend connecting using M-x erc-tls if the server supports SSL/TLS to ensure that you make a secure connection to the server! This is very important for protecting the passwords you transmit to the server.

I recommend joining the Libera.Chat server at irc.libera.chat. Official chat rooms for many free and open source projects you know are there (#emacs, #guix, #sr.ht) and you can also join the #systemcrafters channel!

Let’s do that now!

Joining a channel

Once you’ve connected to a server, you can join a channel by typing the following command:

/join #systemcrafters

After you join the channel, a new buffer will appear in Emacs for that channel with the channel’s name as the buffer name. You can switch to this buffer at any time to read the chat or send messages. Let’s try typing a message to see if anyone responds!

You’ll probably notice that things look pretty minimal compared to more modern chat programs: no images, no profile icons, no emojis, etc. Some of these things can be added with extension modules, though!

Leaving a channel

If you ever want to leave a channel, you can use the /part command:

/part

You can also leave a specific channel by passing the channel name to /part.

Listing available channels

You can get a list of all the channels on your IRC server by typing the /list command:

/list

ERC will show a new buffer with a listing of all the available channels in the server. Since this is a normal Emacs buffer you can use your normal search key bindings to find channels with a particular string in the name or “topic.”

Finding more details about a user

You can get a little bit more information about a particular user with the /whois command:

/whois daviwil

This can return information like:

  • Their full name (if they provide it)
  • The IRC node they are connected to
  • The channels they are in
  • Their IP address or “cloak”

Sending someone a private message

You can send someone a private message a couple of different ways. The most convenient way is to use the /query command:

/query daviwil

This will open a new Emacs buffer for the private conversation between you and the recipient. You can type any message into this buffer and press RET to send the message. Replies from the user will also be written to the buffer.

You can also use the /msg command to send a one-time message without opening a new buffer:

/msg daviwil Hello there!

If the user responds, a query buffer will be opened!

Changing your Nickname

If you aren’t satisfied with the name you chose when you joined the server, you can use the /nick command to change your name:

/nick daviwil-x

Users across all the channels you’re in will now see you as the new name!

Quitting the IRC server

If you’d like to quit the server, use the /quit command. You can also add a message which will be seen by everyone in the chat rooms you’re currently in when you leave:

/quit See you all later!

Reconnecting to the server

If you want to reconnect to the IRC server, you can use the /reconnect command inside of a buffer for that server, like one of the chat windows:

/reconnect

NOTE: You might need to do this if you use a laptop and it wakes up from sleep! ERC doesn’t do a good job of reconnecting reliably for me in this case so I have to reconnect manually pretty often.

A basic ERC configuration

Here’s a basic ERC configuration you can use to get started:

(setq erc-server "irc.libera.chat"
      erc-nick "your-favorite-nick"    ; Change this!
      erc-user-full-name "Emacs User"  ; And this!
      erc-track-shorten-start 8
      erc-autojoin-channels-alist '(("irc.libera.chat" "#systemcrafters" "#emacs"))
      erc-kill-buffer-on-part t
            erc-auto-query 'bury)

This will set your user details, default server, and channels to join upon connecting. It will also control how some buffers get created or closed when you leave channels or receive messages from other users!

In future videos I’ll show some modules you can enable to improve your experience even further!

Want to try it out? Come chat with us!

System Crafters community member Shom wrote up some helpful tips on the wiki that you might find useful!

Chat with us

Also, if you’re a long-time IRC user, feel free to leave a note in the comments with some of your favorite IRC tips!

Subscribe to the System Crafters Newsletter!
Stay up to date with the latest System Crafters news and updates! Read the Newsletter page for more information.
Name (optional)
Email Address