Chat it up in Emacs with IRC modes

914

Author: Michael Stutz

Sometimes it seems like the Emacs editor has features that only operating systems have. You can, for instance, run an Internet Relay Chat client to chat online right from inside of Emacs.

A handful of GPLed Emacs IRC clients are available today as add-on modes — and since GNU Emacs 22 was released last year, two of them come built right in. Here’s a look at all of them.

Rcirc

The first of the two IRC clients to come installed with the latest major release of Emacs is Rcirc, which you start by typing M-x irc.

It’s compact, written in a single file of less than 2,500 lines of code, and is described as a “default, simple IRC client.”

As bundled in Emacs 22, it comes set up with default values for IRC server and port (irc.freenode.net 6667), nickname (your login name), and channel (#rcirc). You can override these settings in your .emacs file or by starting Rcirc with the universal-argument command: C-u M-x rcirc, which then prompts you for the values of these variables.

Once Rcirc connects to the server, it names a new buffer after it, such as *irc.freenode.net*. Whenever you join a channel, Rcirc opens a new buffer for it as well, whose name has the format #channelname@server.

Rcirc has some handy features, such as tab completion for addressing nicks and automatic timestamps on incoming messages. Another nice feature is the ability to edit a message in a buffer of its own; this is nice if you’re composing a multi-line message or if you want to use the contents of the X selection as part of what you want to send. Just type C-c C-c and a new buffer opens; when you’re done editing the new buffer, type C-x C-s to close it and send its contents to the channel.

While you can type all the usual “/” IRC commands, they’re also bound to C-c keystrokes that are intuitive and easy to use, such as C-c C-j for /join and C-c C-w for /who.

The well-written but brief Info documentation includes a one-screen introduction to IRC, and gives some good hints for tweaking your setup. Reading through this shows how using Emacs as an environment for IRC is hard to top — this is where Emacs shines. For instance, it tells you how to use the Emacs flyspell-mode so that any typos you make are detected and corrected on the fly.

The thorough Emacs wiki site has more hints and add-ons for Rcirc, including ways to set a beep when your nick is mentioned in the channel or play sounds when you get a private message. Click on Figure 1 below for a closer look at the client.

ERC

Figure 1 – Rcirc
Figure 2 – ERC
Figure 3 – ZenIRC
Figure 4 – Circe

The other IRC client that’s now a part of Emacs, and has recently become an “official” GNU project, is ERC (Emacs Internet Relay Chat). It’s a large client with lots of features and a modular design. The default setup includes more than two dozen loadable modules that you can turn on (via the Emacs “Customize” facility) if you want their functionality, including the following:

  • autoaway automatically sets your away status
  • autojoin automatically joins channels
  • bbdb sets up ERC for use with the Insidious Big Brother
    Database
  • button turns URLs and nicknames into clickable buttons
  • pcomplete turns on programmable completion for
    nicknames and commands
  • fill turns on automatic fill for long lines
  • completion uses (non-programmable) completion for
    nicknames and commands
  • identd starts an identd server
  • irccontrols highlights IRC control characters
  • list outputs a list of channels in another buffer
  • log saves the chat buffer to a log
  • match highlights given keywords in the channel text
  • netsplit handles detection of netsplits
  • noncommands turns off display of non-IRC commands
  • notify lets you know when the online status changes on given users
  • page handles CTCP PAGE requests
  • readonly displays text as read-only
  • replace replaces given text in messages
  • ring turns on the input ring
  • scrolltobottom moves to the end of the buffer
  • services automatically identifies you to NickServ
  • smiley automatically converts text “smileys” into icons
  • sound plays sounds for CTCP SOUND requests
  • spelling checks the spelling of your text
  • stamp adds a timestamp to your text
  • track watches what happens in a channel and displays it in the mode line
  • truncate trims buffers to a given size
  • unmorse translates text written in Morse code

Start ERC by typing M-x erc. Like Rcirc, ERC is configured to start with a number of variables, including erc-user-nick (your nickname) and erc-user-full-name (your full name). The erc-compute-nick function seems pretty good at finding the proper default nickname.

The documentation is still a bit sparse considering how much there is to the software, but C-h b will show you the bindings. Like Rcirc, ERC features tab completion, and you can do just about everything with C-c commands. You can also mark “pals” and “fools” with the erc-add-pal and erc-add-fool commands, and their nicks will be appropriately highlighted in the channel buffer.

ZenIRC

Supported in Emacs 18 and up, ZenIRC lives up to its name with the most spartan design of all.

Once you’ve downloaded and installed the package, start it with M-x zenirc and it opens a new buffer named *zenirc*. It considers your IRC environment settings, so if you have the IRCSERVER variable set, it will attempt to connect to it (using your IRCNICK).

You can also set the server with the zenirc-server-alist variable (which lets you set a primary and secondary server), or individually with the zenirc-server-default, zenirc-port-default, and zenirc-nick-default variables. To give them as you start ZenIRC, start it in “select” mode by typing M-x zenirc-select.

Once you’re connected, anything you type in the buffer is sent to the channel; precede IRC commands with the usual “/” prefix. The usual list of IRC commands is supported, but ZenIRC comes with a few of its own, including /commandchar, which changes the / prefix to whatever character you give as an argument. The mode line contains your nick and the channel you’re currently in.

Whatever you type on the last line of the buffer is sent to the channel when you press Enter; you can navigate through the rest of the buffer with the usual Emacs commands, and if you hit Enter anywhere but on the last line, you’ll move the cursor back down to the end of the buffer. ZenIRC comes with only a few built-in commands. Typing : at the beginning of the last line, for instance, automatically begins a /msg command that’s addressed to the last person who messaged you, and typing ; automatically begins a /msg addressed to the last person you sent a msg to.

Circe

Circe is “Yet Another Client for IRC in Emacs.” To install it, first get the sources from its CVS repository:

$ mkdir ~/.elisp/; cd ~/.elisp/
$ cvs -z3 -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/circe co circe

Then, either add the following two lines to your .emacs file, or (to test it first) put them in the scratch buffer, highlight them, and run M-x eval-region:

(add-to-list 'load-path "~/.elisp/circe")
(autoload 'circe "circe" "Connect to an IRC server" t)

Start it up with M-x circe. Circe has its own set of variables, including circe-default-realname (your real name) and circe-default-nick (your nick).

All channels and private msg conversations are kept in buffers of their own. Of interest to developers is that Circe’s frontend interface is handled by a separate Lui (Linewise User Interface) mode, which you can use in other programs. Although Lui is still a work in progress, it already has all kinds of features, including timestamps, keyword highlighting, bindings such as M-n and M-p to cycle through the history of your previous input lines, and compatibility with XEmacs.

Conclusion

If you make any of these special modes your regular IRC client, you’ll be doing some configuration in your .emacs file, because they all have their own set of configuration variables, so you generally won’t just leave things to any IRC environment variables that you might have set in the shell.

All of the aforementioned Emacs IRC clients, with the exception of the ascetic ZenIRC, have an activity tracking feature, where you can have channel activity displayed in the mode line. And all of them use the usual Emacs bindings for navigation and editing, so if you’re even just a casual Emacs user you’ll want to try these modes and bring the editing power of Emacs to your IRC sessions. Or, as the description of ZenIRC on its Debian package page goes, “Make your IRC client able to act as editor, too. This is what modern net addicts were searching for.”