Rogue Detective Part 2 – Curses!

Last time, we covered the rather ridiculous choices that led up to my decision to write a roguelike from scratch. Now, we’ll cover the first steps in the creation of Rogue Detective, and indeed, most games I write.

After the standard step of creating a new repository for source control comes the creation of the first source file. This is usually the most daunting part of development: Opening up your editor and seeing a completely blank file that needs to be populated. Step one: Save this blank file as ‘’. Great, we’re half-way to finishing the game, but there’s no time for a break quite yet.

I already knew we’d be using the curses library, so a good first step would be to import it. Additionally, I wrote a barebones do-nothing main function and uses a curses utility function to call it. At this point, here’s the totality of what I had:

import curses

def main(stdscr):

if __name__ == '__main__':
    """Handles all the nasty stuff to do with curses set-up + tear-down"""

As part of the wrapper function, the main is called and passed a variable called stdscr. This is a curses Screen object. This is our canvas upon which we’ll draw our player character, NPCs; the world, basically. This will be passed to the object that controls the world, so it can also control the canvas. Calling the function via the wrapper serves a couple of purposes:

  1. The wrapper handles all curses set-up and tear-down, as mentioned in the docstring. It will initialise curses and set up various desirable cursor attributes such as disabling echo and enabling instant keyboard inputs. After the passed in function has ended, it shuts down curses gracefully.
  2. In case of an unhandled exception in the called function, the wrapper will catch it, shut down curses correctly, and then re-throw the exception. This prevents such a crash from destroying your terminal settings.

I went in to this particular stretch of work with the goal of having my character (an @ symbol) move around the screen controlled by the arrow keys. With the program successfully bootstrapped and in a ‘working state’, it was time to accomplish that goal.

I wanted to keep the main function as lightweight as possible, leaving it as only the entry point to the application and nothing more. I accomplished this by writing a Game class which the main would instantiate and then call a function of. In this case, the function is called mainLoop, and as you might expect, it is responsible for controlling the game loop itself. Before we get in to that, let’s examine the members of the Game class.

class Game:
    """The game logic itself. The loop and input handling are here."""
    def __init__(self, screen):
        """Create the screen, player, assets."""
        self.screen = screen
        self.running = True
        self.player = Player()

So all we have right now are variables for storing the aforementioned Screen instance, another for storing the state of the game (running, not running), and one containing a currently mysterious Player object. How about that mainLoop I mentioned?

    def mainLoop(self):
        """Run the game while a flag is set."""
        while (self.running):

As long as the game is running, we run all the logic for the game, draw the resulting position, then wait for player input.

    def logic(self):

No game logic exists at this point, so logic is an empty function.

    def draw(self):
        """ Draw it all, filling in the blanks as necessary """
        player = self.player
        self.screen.addstr(player.y, player.x,
                           player.character, curses.color_pair(1))
        self.screen.move(player.y, player.x)

draw actually does something useful. It clears the previous screen, grabs the Player object, draws it in the right place, and finally moves the cursor to the player’s position. That last step is one of the many niceties of a console-based roguelike: if we don’t put it directly on the player character, there are two problems:

  1. If we don’t uniquely colour the player character, the player (user, not game object) won’t be able to identify his character if multiple objects share the same symbol.
  2. If we don’t put the cursor on the player character, it has to go somewhere else. And where else would we even want to put it? It needs to go somewhere. Because of problem one, it makes sense to place it on the player character when possible.
    def handleInput(self):
        """ Wait for the player to press a key, then handle
            input appropriately."""
        character = self.screen.getch()
        if character == ord('q'):
            self.running = False
        elif character == ord('h'):
        elif character == ord('j'):
        elif character == ord('k'):
        elif character == ord('l'):

Given the turn-based nature of the game, there’s no need to do anything particularly clever like pump event queues or have time-out functions. We explicitly wait for the player to input a character via a Screen function, check the result against the list of characters we’re expecting, and perform the associated action if we get a match. In this case, we call one of the Player functions to move the character around the screen. You’ll also notice we pass in an enum. In Python, enums are usually just static class variables grouped in a class that becomes the enum’s name:

class Direction:
    """An enum for the possible movement directions"""
    UP = 1
    DOWN = 2
    LEFT = 3
    RIGHT = 4

In this case, nothing clever is going on: An enum of four elements in declared for the four directions of movement. Let’s cover the Player object now:

class Player(object):
    """The player object, containing data such as HP etc."""
    def __init__(self):
        """Initialise the player object"""
        self.x = 20
        self.y = 30
        self.character = '@'

At the point in development, the Player contains only information strictly required to render it: Its position on the screen (y, x) and the character we should use to represent it. This is used by the draw function in the above Game class. It has a single member function:

    def move(self, direction):
        """Move the player one unit in the specified direction"""
        if direction == Direction.UP:
            self.y -= 1
        elif direction == Direction.DOWN:
            self.y += 1
        elif direction == Direction.LEFT:
            self.x -= 1
        elif direction == Direction.RIGHT:
            self.x += 1

This gets called by the handleInput function, and moves the player in the given direction. I should probably mention that this code will let you move the player character out-of-bounds of the Screen object. This throws an exception and crashes the program. Additionally, you can’t move to the bottom-right most part of the screen, for a much more subtle reason: Curses will draw the @ symbol in the very last available space, but then attempt to move the cursor along to a location that doesn’t exist in the screen space. Both of these problems will be fixed later on.

At this point, we can revisit the main function and see how we incorporate this new Game object. There’s no surprises here:

def main(stdscr):
    """Initialises the Game object and basically gets out of the way"""
    stdscr.bkgd(' ', curses.color_pair(0))
    game = Game(stdscr)

We set the ‘background’ to be made up of blank characters. If we ever erase the screen, it is actually filled with the background character, as set by the bkgd function. We then instantiate and start the game.

That’s it! The actual code looks a little different for the first commit (there’s a superfluous class floating around, and some of the code has been changed here for clarity). How does it look? Well, take a look:


In the future, we won’t cover whole commits. Indeed, we won’t cover each commit, but rather the functional milestones of the project. Hopefully you’ve gained a little bit on insight in to how a Python curses project starts life. Next time, we’ll look at the implementation of walls and other standard obstacles you tend to see in roguelikes.

Rogue Detective Part 1 – A Defective Rogue

Rogue Detective started off as an attempt at the annual 7 Day Roguelike competition, wherein one aspires to create a full roguelike in a mere seven days. Entrants are allowed to use previous work, provided the final game is a new roguelike unto itself.

This year, the competition fell in one of the two weeks of my holiday from work. Being one of the many proud staycationers so prevalent in England, this meant I would have the full week to develop a game! I heard about the competition one day in advance of its start, which gave me a little bit of time to start mulling over a few ideas I had.

At the same time, I started considering at my options regarding development. I already knew what my editor would be: Emacs, of course! I figured if I was going to pull this off in a reasonable time frame, I’d need to use a language I was comfortable developing in. That meant a choice between C(++) and Python. Given how I’d recently worked on a Python game, the language was still fresh in my mind. Indeed, for speedy development I am in general more comfortable in Python.

Editor sorted, language sorted.. Now I needed to consider what libraries might exist out there to help me. I vaguely remembered NetHack using the curses library for terminal stuff, so the first thing I did was check for Python bindings. Sure enough, a Python library for curses existed. At this point, I hadn’t even considered a graphical roguelike. I knew I had no chance to produce something pretty, so I would stick to ascii. I started work on getting an @ symbol wandering the void. This is not the most thorough approach to library selection, but yeah! Limited time means limited research.

I hadn’t quite realised what I was undertaking: A complete roguelike from scratch, save for terminal character manipulation. Given only a week, surely the typical entrant would have to take the whole time to finish something even remotely playable, eschewing work and a social life?

Meanwhile, my friend Ariff was considering entering the same competition. The first thing he did was check for the already existing roguelike libraries that could help. Of course! Why wouldn’t something so obviously useful exist?

For Python, there already exists the libtcod library. Rather than build everything from scratch, libtcod provides users with useful functionality such as built-in dungeon generation, pathfinding, line of sight algorithms.. And to top it off, the whole thing is portable: Rather than build off a terminal-based library, it uses the SDL library. So while programs now have to run in a non-terminal, there’s very little messing about with getting games working on multiple platforms AND with full colour!

So it’s a no-brainer, right? Using this library, I’d be able to get to work on the meat of my game idea immediately! Maybe this wouldn’t be such an impossible task after all.

Of course, I’d already gotten an @ symbol walking around.. And it would be a shame to waste ‘all that work’.. Long story short, I made the questionable decision to continue with my own ‘from scratch’ engine. This was probably due to a mix of hubris and ignorance. Sufficed to say, I didn’t finish in seven days. It turns out that unless you’ve implemented things like path-finding and field of view before, they can be more than a little time consuming!

So the dream of a roguelike in seven days was dead on arrival. But this wouldn’t kill the dream of a roguelike in totality. Over the past month I’ve continued to work on my little game, and over the next few posts I’d like to go through some of the basics of roguelike development using my repository’s history to guide us. It will definitely not be a guide on the proper usage of source control (one branch for life!), but I think maybe it’ll be useful for me to solidify the process and maybe useful for people reading if they want some insights on how a newbie might write a roguelike.

Getting Virtual with Emacs (Part 3)

Last time, we talked about the two emacs extensions I use to emulate my most used features of Sublime Text. Even a cursory look at the manual would show way more features than I even thought about using, but by learning basic editing in emacs I’m already able to fully switch over to the Gnu editor.

This time I’m going to write about the cool stuff I’ve installed in emacs that you don’t see in the standard Sublime installation. Maybe Sublime has support for some of these functions, but not out of the box.


Magit allows you to control git from inside emacs. ‘But Matt,’ I hear you cry, ‘I can just leave emacs if I want to do git stuff! Why do I need this package?’ If I had to give you a a good reasons.. The whole thing is a pleasant user experience. Magit itself manifests as a new buffer splitting your window, listing the current status of the repository. Asking for a diff gives you the diff in another buffer; committing causes the commit message to open in a new buffer.. It’s very self-contained inside emacs. You don’t have to leave emacs for any part of the staging/committing/pushing, so you never have to break your flow. Even if you want to run an arbitrary git subcommand, Magit has you covered: The ! command while in the Magit buffer lets you specify subcommand you want.

But why alt-tab out to your terminal, then type ‘git commit -a’ only to be thrown back in to emacs for the commit message? Then you have to go back to the terminal to type ‘git push’.. What a chore. With Magit, I can just hit my Magit key binding (C-x C-a), then ‘c’ for commit, ‘-a’ for ‘add all unstaged files’, ‘c’ again, and I’m in a buffer where I can write my commit message. Write the message followed by C-c C-c to complete the commit. Then I just have to type ‘P’ twice to push, enter my SSH key-phrase, and that’s it.

Sure, Magit is definitely more of a convenience package than something that will supplement your coding skills, but it’s such a great convenience I can’t see why you wouldn’t want to use it!


This one is a little unfair, because Sublime has support for snippets, and I just never really used them. Anyway: Yasnippet by João Távora allows you to use snippets when coding. Snippets are blocks of (usually) often used code that you can assign a shorthand command for. These commands take the form of a sequence of characters typed in to the editor followed by a tab. For instance, when writing Python I could type ‘cls’ followed by a tab and cls would be replaced by:


Emacs highlights ‘class’, ready for me to type the new class’ name. Once typed, I press tab again and I’m done. Snippets can contain more than one field to modify. In that case, tab moves you to the next field.

That happens to be one of the snippets you get when you first grab yasnippets via the package manager. It’s very simple to write your own, and dare I say, easier than writing the equivalent template in Sublime. The snippet above is defined like this:


If we wanted to save ourselves even more writing and not have to worry about writing the usual init function, we could modify it like so:


Notice how I’ve referenced $1 in two places and added a second field for us to potentially modify for when the new class is a subclass. By referencing a field more than once, the field is mirrored in other places. Expanding the snippet now gives this:


Notice how I’ve typed ‘Woah’ and it has automagically appeared in other places! Pretty cool. There’s a lot of potential in snippets to unlock, and they can save you from large amounts of typing. They’re a great feature to have, and I can’t wait to think up some useful snippets to improve my workflow.


One of the simplest packages on this list, ace-jump-mode by winterTTr is one of the most difficult to explain. Functionally, it’s a method of moving the cursor to the beginning of any word on the screen. The way you use it might seem weird at first, but it quickly becomes second nature. In this screenshot, my point is at the bottom of the screen but I want it to jump up to the creation of the Player object, because I just remembered I renamed that class.


Rather than move the point all that way (a whole 12 lines, so much effort), I can activate ace-jump-mode with my key-binding (Ctrl+C SPC), type the first letter of the word I want to jump to, and bam:


Ace-jump-mode now finds all instances of the chosen letter on the screen when it appears at the start of a word, and labels them with a letter of the alphabet. In this case, I want to jump to Player, so all I have to do is type ‘i’ and the point will jump to that location! I think it’s pretty neat in its simplicity, and saves some tedious point moving action you’d otherwise be doing.

That’s pretty much it! Before I finish this post, I’d like to take a little while to help out anyone having problems combining some of the packages discussed in these posts.

Jedi.el and multiple-cursors.el

These two packages get along quite well until you have multiple cursors active and decide to type a dot. Upon seeing a dot, Jedi.el decides to attempt to call auto-completion to help out with class methods and the like. However, multiple-cursors explicitly disables auto-complete mode because auto-complete doesn’t play well with it. The end result is that an error is thrown on typing dot, so only the first cursor actually types it. This is problematic, but I have a solution! In fact, I’ve submitted a pull request to the multiple-cursors.el repository that was recently merged. But for you people who don’t want to upgrade multiple-cursors to the latest pull or want to wait for a new release, here’s another solution that you can add to your .emacs after your normal multiple-cursors set-up:

(setq mc/unsupported-minor-modes '(auto-complete-mode flyspell-mode jedi-mode))

After adding this, you can type dots to your hearts content, even when using jedi.el! Enjoy.

Yasnippet and auto-complete.el

While not mentioned explicitly here or in the previous post, Jedi.el uses auto-complete.el for its auto-complete interface. Sometimes you’ll want snippets to appear in the auto-complete list. By default, auto-complete.el is coded to not include a yasnippet source. A source is just an abstraction that provides suggestions to auto-complete.el, with the actual method of finding said suggestions hidden inside the source itself. With a bit of tweaking, we can have snippets appear in all auto-complete suggestions regardless of mode by forcing the yasnippet source to be loaded in all modes. This is typically desirable behaviour, because if we have snippets for a mode, we usually want to use them! To do this, you need to add a hook to the auto-complete-mode in .emacs:

(defun ac-always-add-yasnippet-source ()
(add-to-list 'ac-sources 'ac-source-yasnippet))

(add-hook 'auto-complete-mode-hook 'ac-always-add-yasnippet-source)

Alternatively, you can add hooks on a per Major mode basis instead. For instance, you can add the same function as a hook to Python mode by replacing auto-complete-mode-hook by python-mode-hook.

That about wraps it up for this post. If I find a really cool emacs package that I have to shout about, I’ll be sure to mention it. Otherwise, next time we’ll be looking at Rogue Detective (working title), my really-kinda-lame-but-I-like-working-on-it Python roguelike developed in emacs!

Getting Virtual with Emacs (Part 2)

It’s been just over a month since I started properly developing in emacs, both at work and at home. I think it’s about time I wrote a little about my experiences.

First of all, while I’ve used vim daily at work, I don’t claim to be a vim power-user by any stretch of the imagination. Sure, I know how to navigate around quickly, and how to perform some basic editing, but I’m nowhere near the proficiency required to consider oneself a true user. For instance, I’m pretty terrible at VimGolf! When doing some heavy duty coding, I worked in Sublime Text 2. Even in Sublime, for me it was more about the syntax highlighting and pretty interface than it was about its cool features (with the exception of multiple selections). Like many beginner programmers, I haven’t yet took the time to learn my environment. Or any environment, for that matter! After watching some cool emacs videos, I decided I wanted to properly ‘learn’ emacs, and not just use it in the same way I use vim (in that case, why even try emacs?).

The question was: Could using emacs help my productivity? Sure, it wouldn’t help me think up or reason about code faster, but when an idea finally does pop in to my head, the last thing I want is for my editor to get in the way. In fact, an editor that could help me express my ideas faster than other editors would be a boon.

My first experience with emacs was with the in-editor tutorial. It teaches you how to move the point (cursor) and how to perform simple editing. The tutorial barely scratches the surface of emacs, but it does ease beginners into editing with emacs in a gentle, easy-to-follow fashion. After blowing through that and wondering what all the fuss was about, I would find the real power of emacs comes from its extensibility.

Emacs extensions

While emacs is a powerful editor in its own right, the huge amount of community support means that regardless of what language you’re using, someone has written an extension to make coding in it easier. If they haven’t (they have), rolling your own is just a case of applying your Lisp knowledge to the emacs equivalent, elisp. Don’t know Lisp? After spending enough time with emacs, you’ll at least have a good enough grounding in elisp to understand the odd bit of proper Lisp code, and enough knowledge of elisp to be writing your own little bits of code to enhance emacs. I realised that all the cool things in those videos I was watching were often showcasing packages (extensions) for emacs.

My first big programming project using emacs is a Python roguelike that I’ll talk about in future posts. Having written my previous Python project in Sublime Text, my first aim was to be able to do in emacs what I could do in Sublime. This turned out be simple, given how I’d barely given Sublime a proper workout in the first place. I wanted half-way clever auto-complete functionality, multiple selections, and a colour scheme that wouldn’t melt my eyes. After getting the basics out of the way, it would be time to explore the larger world of emacs.

As of emacs 24, emacs comes bundled with a package manager. It turns out there’s more than a couple of repositories for emacs packages, and it’s simple to add them to your emacs package list:


Once that’s sorted, you can bring up the package manager by using the ‘list-packages’ M-x command and browse the huge variety of packages available at your leisure:

Yes, 2048 has even invaded emacs

Yes, 2048 has even invaded emacs

Jedi.el – Python Auto-complete

In my Python setup, the Jedi.el package provides auto-completion. It’s a really clever piece of kit. Jedi.el will not only offer auto-complete suggestions based off the history of the file (giving auto-complete options for words already typed), but thanks to integration with a Python server called Jedi, Jedi.el will also have knowledge of your classes and function definitions. For instance, if you’re writing a method inside a class and type ‘self.':

Jedi.el Autocomplete

Jedi.el and Jedi will be able to figure out your class’s variables and functions and offer auto-complete suggestions. This is seriously useful. If you’re writing code and forget what arguments to pass to a function, you’re also in luck:

Jedi.el Function Signature

So yeah! Overall, Jedi.el is a really neat package. It has a few other features I haven’t tried out too much yet (‘goto definition’ for instance), but I’m looking forward to exploring this package a bit more. Installation was a bit more involved that most emacs packages, requiring some pip action to get the external Jedi server installed. But in fact, Jedi.el came out with a new version that makes installation simpler than before, so even that’s not really a valid criticism. Here’s how Jedi.el is set-up in my .emacs. In the latest version, the setup-keys variable isn’t required.


multiple-cursors.el – Multiple Selections

multiple-cursors.el is written by the wonderful Magnar Sveen of Emacs Rocks!. He’s produced a video about it that can explain it far better than I could hope to:

Installation is as easy as downloading the package via the package manager and inserting a few key-bindings in to your .emacs:

Multiple Cursors Setup

Sublime Text and Vim look-and-feel

I really like how Sublime Text’s default theme looks. I also love the simplicity of the Vim interface. Emacs, out-of-the-box, looks positively crowded compared to the very clean, empty Vim interface, as demonstrated by the last article:

EmacsTerminalFresh2To be fair, that picture is also from the terminal version of emacs, but the point stands. What on earth is that menu bar doing up there? And in the X terminal version, there’s a scroll bar and a tool bar? Vim doesn’t need these things, and neither do I! They simply had to go:

GettingRidOfTheChaffAnd what of my wonderful Sublime Text colours? It turns out, someone had already made an emacs theme with pretty much the exact same colours as in Sublime Text’s monokai theme! They imaginatively called it monokai. I installed it via the package manager, added

(load-theme 'monokai t)

to my .emacs, and whoosh!

MonokaiThat is one sexy looking emacs set-up. Yes, there’s a couple of mistakes in my .emacs, but I’ll survive. Another little thing enabled here is column numbering in the status bar.

Those of you with eagle eyes will spot little things in the .emacs like yasnippet, magit and ace-jump-mode. Those are some very, very cool add-ons. I’d like to write a bit about those next time. For those who are really impatient, both yasnippet and ace-jump-mode have been subjects of Emacs Rocks! videos.

Getting Virtual with Emacs (Part 1)

A Quick Introduction

We’re taking a short (okay, long) break from the Hullet Bells posts. It’s already been a couple of months since I last updated, mostly because progress has been slow. I keep having ideas on how to refactor the fledging script system, but never get around to actually implementing them. So that’s on hold for now. In the meantime, I’ve been messing about with a couple of other things. Today, I’d like to write about my experiences with Oracle VirtualBox and Arch Linux. This isn’t going to be a tutorial on installing Arch on VirtualBox by any means. If you want that, you’d do well to check out Josh Braun’s excellent guide. When the ArchLinux beginner’s guide was not enough, Josh’s advice helped grease the wheels.

Oracle VirtualBox (or simply VirtualBox) is a virtual machine (or VM). For those unfamiliar with VMs, the concept is simple: Rather than install a second operating system via the traditional fashion of re-partitioning your hard-drive and modifying the boot loader so you can dual-boot, you run your standard operating system and boot the new one as a program inside it. The underlying operating system is called the ‘host’, and second operating system is known as the ‘guest’.

I’m running Windows (the host OS) with Sublime Text and VirtualBox open. Inside VirtualBox is an Arch Linux instance (the guest OS), running Openbox, Emacs, and Supertux. Why would anyone do this? Well, there’s plenty of legitimate reasons. For instance, as a developer you might want to test software on multiple platforms without having to drudge through rebooting or using a different machine every time you want to try something new. Or maybe you have some old applications that only run in an older version of Windows, and you’d like to use those without dusting off your ancient Dell. These are fine reasons, and there are many more. My reason was a little stranger..

I wanted to learn Emacs

Why learn GNU Emacs? Well, why not? I’m already pretty familiar with Vim, although I’m by no means a wizard. After watching a few videos of people working with Emacs, I figured maybe it was time to give it a go. I would be one of the brave, the few, to see what life was like on both sides of the editor war.

‘But Matthew,’ I hear you cry. ‘You don’t need to install Linux just to use Emacs!’ And you would be completely right. While I was toying with the idea of installing Emacs for Windows, I remembered another thing I wanted to get to grips with: Linux. I’ve had several abortive attempts over the years, usually lasting anywhere between a week to a couple of months. The high entry cost of having to leave behind Windows and its myriad useful applications ended up being too much to bear. But the future is here, and now I can run Linux in my Windows, so I can Linux while I Windows. So I decided to give both of them a go. But first I’d need a Virtual Machine to run Linux on..

Virtually a Machine

After Googling for all of thirty seconds, I came the open-source VM VirtualBox. There is an alternative in VMware Player. I picked VirtualBox simply because I had to pick between the two. It turned out to be a great choice, with almost no problems encountered at all.


What’s that in the preview box?

The interface couldn’t be simpler. You can run as many virtual machines as your system can handle, and creating a new machine is as easy as clicking the New button and following the wizard. All you need to set up at first is the machine name, type (Linux, Windows, other), and version (Ubuntu, XP, OS/2, etc). Allocate it some amount of memory, specify some parameters about its virtual hard drive and bam! You’re done! Grab an ISO of your favourite Linux distribution, pop it in the virtual drive, boot up the machine..


And install it just like you normally would, with a few special additions/omissions for doing it in VirtualBox. Again, I’m not about to provide a big ol’ tutorial. That’s already been done, and it’s been done very well. Some of the nice features you get when working with a supported VirtualBox OS:

  • Shared clipboard!
  • Ability to seamlessly move the mouse and keyboard between operating systems without having to explicitly regain control from the guest!
  • Other stuff I haven’t yet discovered!

It’s super simple and a pleasure to work with, at least for my current requirements.

Arch Linux

Why Arch? Well, I’m a big fan of lightweight stuff. Arch comes with just enough to get you going, and a great package manager (pacman) to help you get the stuff that you want. If you’re bit of a Linux penguin, you may understand my surprise at the fact I had to download sudo! That’s right, that’s how lightweight it is. Installation and initial set-up took me about half a day in total. This is keeping in mind I’m not very familiar with Linux installation, especially after such a long period between efforts.

One of the things I really like about running a virtual machine is that you don’t really have to worry about irrevocably screwing up your physical box. Things like disk partitioning are usually terrifying exercises in double, triple-checking your numbers, especially on a system that already has an OS installed. So without those worries, I was able to play about a bit and step out of my normal comfort zone. After that, it’s just going through the motions of installing the guest OS, enabling the network, setting the clock..

Then it was time to install Emacs. I took a deep breath and typed

sudo pacman -Sy emacs

and it was done!

Emacs on the Terminal

I ran through the Emacs tutorial in about an hour. I was amazed at how different the whole experience was from Vim. The look and feel were completely different, for one thing. A menu bar? Wow, I hadn’t seen one of those on a terminal editor since Edit! And the editing wasn’t modal like Vim: None of this switching between Normal and Edit mode. Of course, there were also little surprises. Yank means ‘paste’ in Emacs, while it meant ‘copy’ in Vim. There’s zero one-key short-cuts for things: Want to go to the start of the line you’re on? Ctrl+A will do it in Emacs, while ‘0’ will do it in Vim. Want to copy that line? ‘yy’ will do that for you in Vim. But you’ll need to either ‘mark’ (select) the line in Emacs and ‘kill’ (copy) it without deletion, or delete the whole line and ‘yank’ it back in, with the end result of the line being on Emac’s equivalent of the clipboard. The key sequences for these look like:

#1: Ctrl+a (go to start of line), Ctrl+Space (Place marker), Ctrl+e (Go to end of line), Meta+w (‘Kill’ without deletion)
#2: Ctrl+Shift+Backspace (‘Kill’ the line and delete it), Ctrl+y (‘Yank’ the line back)

Woah. All the simple things suddenly seemed very difficult. In reality, you get used to the extra keystrokes quite quickly. And if it really bothers you, there’s Emacs extensions and modes out there for making Emacs behave more like Vim! Which brings up a good point: Emacs is extensible. Like, crazy extensible. Thanks to its built-in language Elisp (Emacs Lisp, a Lisp dialect), it wouldn’t be hard to implement a single key-chord command that would perform one of the above methods. Indeed, the same thing could be accomplished with a macro (a recorded set of key presses), a bit of functionality common to both Vim and Emacs. In any case, moving on..

Here’s how Emacs looks on the terminal:


Not super hot. I spent a lot of time trying to get custom themes working and looking good, but it’s not an easy task. Especially when Emacs only wants to work with 256 colours! After a lot of wasted time trying to get a full colour terminal (if you figure this out, let me know), I decided to just install Xorg.

Emacs in Openbox

Initially, I went with the safe choice: The Gnome Desktop Environment. I’d used it in the past, and it was pretty okay back then. But wow, does it take a long time to start-up? And you have to log-in, what a mess. I ditched that quickly and continued my adventure outside my comfort zone. I installed Openbox, a lightweight window manager. When I first booted it up, I didn’t realise it was loaded:


It’s very minimalist.

That’s it. That’s what Openbox looks like. A right click reveals a menu in which you can open up X programs normally. I’ll talk about Openbox a bit later, but first, here’s what Emacs looks like under X:


Ah, much better

Quite different, right? If the colour scheme looks familiar, it’s because it was inspired by Sublime Text‘s monokai theme. Installing the theme was easy. I had to configure the in-built (as of March 2013) Emacs package manager to use the Melpa and Marmalade package repositories, and then just downloaded the theme via that! A quick config change in my .emacs file, and there we go. The comfortable look of Sublime Text, the power of Emacs.

Next time, I’ll be posting about my experiences with emacs so far. I’ll highlight a couple of interesting features and extensions that I like, and maybe even convince some of you to give emacs a shot!