Monday 16 February 2009

The basics of... Emacs

[caption id="" align="alignleft" width="300" caption="Photo by snogglethorpe"]Photo by snogglethorpe[/caption]

All programmers need some way of getting the code from their head into the computer.  Nowadays, this means a development environment or text editor of some sort.  There are a range of these available for different platforms and languages and many of these are excellent.  In this article, we're going to tell you about one good choice, the extensible, customisable (and free) text editor GNU Emacs .

An editor for all weathers...
Perhaps the biggest practical strength of Emacs is that it supports programming in a lot of different languages.  C or Java.  Yup.  Matlab, R or IDL.  Certainly.  And the list goes on.  The support for any given language is typically good, and while for a given language Emacs might not have quite as many bells and whistles as a more language-specific development environment, you'll generally be able to do a lot of useful things and for a lot of different languages.


Learning the ropes
Any development environment or code editor is a tool.  And tools take time to learn how to use well.  A huge strength of Emacs is that it's pretty much the same tool for any task you'll use it for.  This means that (most of) the hot keys will be the same, cutting-and-pasting works the same and so on.  For a scientist-programmer, who ideally doesn't want to spend lots of time learning to use a range of different tools, being able to use one text editor to write code in many different languages is a very good time-saver.


Version how-many?!
At the time of writing, the current version number of Emacs is 22.3 (version 1 was created in 1976).  This means that Emacs is a very mature piece of software.  And this means that it's both a very usable piece of software, and also that it tends to be very reliable.  It's nice to not really have to worry about quirks of the software wasting your precious coding time.

Configure it yourself

Emacs is also configurable.  Massively so, if you've got the time.  The majority of the Emacs functionality is controlled by a built-in version of the LISP programming language, which means that the user can re-define and/or extend functionality by adding or modifying the LISP code.  While major changes are probably reserved for people who are very keen to get into LISP, we find that a handful of key configurations in a .emacs file is a very handy way of tailoring Emacs to do exactly what you want it to do.


XEmacs
We should also mention that pretty much everything we've said above also applies to XEmacs , which is an offshoot project from GNU Emacs.  We can't comment as extensively on XEmacs, as neither of us has used it a great deal, but we're pretty sure it's also very good and for much the same reasons.


In conclusion
Emacs might not be the single best choice for any given programming language, but it's a good, solid choice for many, many of them.  And this very flexibility is what makes it so great, because you only have to learn how to use it once, before using it in many different situations
.

4 comments:

  1. naaaa!!!

    vi rocks!!! only vi is for real nerds!! :)


    p.s. I could never understand why so many people use emacs without activating the anti-aliased fonts.

    ReplyDelete
  2. GNU Emacs is an Aladdin's cave of a program and it is unbelievably flexible and powerful. There's no software quite like it and though I don't actually do a lot of programming myself I think AUCTeX alone is reason enough to recommend it¹:

    http://img394.imageshack.us/img394/9664/screenshotemacsfv5.png

    Of course it /is/ hard to tame and master but it has excellent documentation (including reference cards) and if you put the time and effort in you'll not regret it.

    ¹ Some people have said the same of org-mode http://orgmode.org/

    ReplyDelete
  3. [...] The basics of… Emacs http://www.programming4scientists.com/2009/02/the-basics-of-emacs/ « előző | attilacsordas — 2009. 02. 24. [...]

    ReplyDelete
  4. gioby: ever write a large LaTeX document in vi and have it insert the formatted text and equations into your editor so you can make sure they're being entered in correctly? Also, TTF support is now in Emacs, but it is terribly slow. I'll stick with the bitmapped fonts for now.

    ReplyDelete