Back To My…Emacs
Emacs. Love it or hate it, it is undeniably a monument of software engineering. At best it’s an amazingly customizable work environment that can be shaped to your every whim. At worst it’s a giant time-sink where productivity is skewered by endless “fiddling”.
Since switching to the Mac over a year and half ago, I’ve used TextMate as my non-Java editor. TextMate is great text editor. It’s relatively simple to extend, has a very active community and only takes a little investment before a user gets productive. But I’ll admit that in the last month or so my eyes started wandering from TextMate—I felt like maybe I was ready to go back to Emacs.
Perhaps it’s worth a little history first. Back in the Dark Ages of Java Development (anyone remember Gnu Server Pages?), I was a pretty hard-core XEmacs guy for my Java dev. At the time Java IDEs were painful exercises in waiting and crash-recovery. JBuilder, early NetBeans, Visual Cafe were all valiant attempts but terrible failures. So I rode with XEmacs until the IDEs caught up.
Then one day I met Eclipse. Unlike any other Java editing tool, Eclipse was much more than a text-editor. Rather than treating your code like text to be manipulated, Eclipse actually understood your code. This allows you to think in terms of manipulating Java syntax and symbols instead of simple text tokens and lines. For a static language like Java this is incredibly powerful since you can determine up-front all of the possible things you might want to write. This is why a full-on “intelli-sense” feature for dynamic languages is hard to do as well in static, compiled languages.
I spent the next five years learning just about every nook and cranny of Eclipse and would put my raw Java-writing skills up against anyone. Even now, I still use Eclipse for Java and I can’t imagine going back to a plain text-editor—even a souped-up hot-rod like Emacs. This says less about the deficiencies of any text editors as it does about the requirements for developing in Java. Writing Java without all of the code-completion and refactoring tools an IDE like Eclipse has would simply exceed my pain threshold. So while Eclipse has become quite bloated lately and, when coupled with tools like Maven, is an exercise machine-servitude, it will be a cold day in hell before I give it up for Java. (NB: I plan on giving up Java-dev first.)
Now I’m writing a lot more non-Java than I did a year ago. That’s what brought me to TextMate. The integration for Ruby, HTML, CSS, JavaScript and shell was outstanding. I bought the TextMate book and was on my way to editor ass-kicking.
Unlike my Java days, now I identify myself less with a single language. Back in the day I was a Java Programmer™ dad-gummit. It was The One Language To Rule Them All and it served me well. Do you remember those days? Yeah, that was also the time when certified Oracle dudes were writing their own checks. But as time went on, I noticed that those Oracle guys pretty much knew how to do one thing and if and when the Day of Database Reckoning ever came, these guys were gonna be left standing in the cold wondering what the hell happened. I think that day has come and those dudes are becoming the equivalent of COBOL programmers—relegated to propping up legacy systems and talking wistfully about “the good ol’ days”.
So it got me to thinking about what I needed to do to survive in this business. Clearly I was going to have to evolve. So I started looking around for some inspiration and came across Ruby. Right now it’s my favorite language, but it’s not the only game in town. Ruby borrows a lot of features from other languages and a lot of other Ruby-ists are also spending time with other languages like Haskell, Erlang, io, and Lisp just to get exposure to other ideas. Moving away from a single-language focus to broader interests has been an important part of moving from rookie to journeyman. Evolve or die, right?
So how does this relate to Emacs? Well, like a lot of folks, I’ve been interested in learning more about functional programming. The problem is, I simply haven’t had the time to crack open the Erlang book and bend my brain in new ways. Don’t get me wrong, it’s on the list, but it’s going to be a while before I get to it. So I was eager to dip my toe in FP without a major commitment. Enter ELisp.
Before I dropped out of college, my brief career in academic computer science was spent with Scheme. My time in school didn’t end well and so I’ve associated Scheme (and by extension, Lisp) with that particularly unpleasant time in my life. I’ve only recently overcome the shakes when I see car or cdr. But a little time and some professional success has healed old wounds. In my first go-round with Emacs, I was really just using it as a power-editor. The internals of Emacs pretty much escaped me and in my mind there was a pretty major barrier between an ELisp user and an ELisp writer.
This time I’ve made a concentrated effort to learn more about how Emacs works. I’ve been racing through the O’Reilly Emacs book and this time it makes sense. I don’t know what the hang-up was before, but this time it all seems so logical! The entire editor is simply a collection of ELisp functions and variables built on top of other functions and variables. It’s all self-documented and incredibly dynamic. Wanna try something out? Just put a little Lisp in your *scratch* buffer and evaluate that sucker. Hell, in Eclipse I’d have to download the freakin’ source and compile it or swim in XML writing an extension. That’s incredibly powerful—the barrier to “trying stuff out” is mind-bogglingly low.
So while I’ve definitely take a short-term hit by trading in TextMate for Emacs, but I’m reaching productivity-parity pretty quickly. A couple of modes/libraries I’ve found that I’ve really liked are:
- Steve Yegge’s JS2 mode
- Rinari, for Rails
- Org-mode
- Magit for Git integration
I plan on spending some quality time with some of the various snippets libraries too to port over some of the templates that TextMate uses. For something like Rails development, which is about the most idiomatic programming I can imagine, having short-hand snippets is a major productivity boost.
So why go through this? After all, switching editors can be like converting from Catholicism to Judaism for some. Well, I think I’m doing this because:
- I’ve already overcome the initial steep-learning curve of basic editing in Emacs
- I get a nice, no-commitment introduction to functional programming
- I get a great environment to learn new stuff in
- With a little effort and a willingness to learn, I can make this sucker to anything
- Emacs has quite a track-record. It’s close association with Unix is no accident.
- Emacs customization is easy to write and a snap to track in SCM
I can’t say that I’ll use Emacs for everything. I’m getting into Cocoa development too and it looks like doing that outside of XCode is a fool’s errand. But that’s okay. I don’t need a single tool to do everything for me, just a handful of tools that help me get a variety of things done. That said, I’m pretty sure I’ll be solving a lot more problems in Emacs than I ever did in any other single tool.
This entry (Permalink) was posted
on Monday, October 6th, 2008 at 8:36 pm and is filed under Software, Technology.
You can follow any responses to this entry through the RSS 2.0
feed.
You can leave a response
, or trackback
from your own site.


11 Responses to “Back To My…Emacs”
October 6th, 2008 at 11:34 pm
Ok, emacs works well for my C project, Python project, but I always can not understand how to use it for Java Project, especially I am a Java programmer.
Do you have any suggestions to use emacs as Java develop tool? How to compile a class just with related classes , without compiling full project? What about web project? it’s more complex than common jar project.
Thanks!
October 7th, 2008 at 8:22 am
Right, I guess that’s kind of my point. Any non-trivial Java project requires a certain amount of “infrastructure” that exceeds what I’m willing to setup in Emacs. I’m sure it can be done, I’d just rather use other tools at that point.
Apparently there is some pretty good Ant integration for Java projects in compile-mode so that might work for you if you’re already an Ant-based project. I haven’t used it (I despise Ant) so I can’t speak for how well it works.
Good luck,
Alex
October 8th, 2008 at 3:34 am
Have you had a look at yasnippet? It’s got a pretty handy set of snippets for more than just ruby/rails and seems pretty easy to expand with new ones.
As for using Emacs for Java, maybe when Ola Bini’s Antlr-ELisp project is done…
October 8th, 2008 at 8:13 am
Andreas, thanks for the pointer. Before I saw your comment I did some poking around at the various snippet packages for Emacs and came across yasnippet—which is fantastic!
I also found a script hanging off of the Google Code page for yasnippet to convert TextMate snippets to yasnippet. It’s not 100%, but I can hand-tweak the rest.
I love the design of it too: just write template files in a directory with a name matching the template you want to type. Very nice.
October 11th, 2008 at 10:07 pm
Give nXML mode a whirl if you are editing HTML. Combined with yasnippet, it makes emacs a great HTML editor.
October 13th, 2008 at 9:47 pm
I think in the end the only thing that matters in the editor wars is that you’re extending Emacs in the exact same way that the original authors were when they were writing it.
If you have to use some tacked-on “plugin mechanism” to customize it, then you’re going to be limited by whatever the author of the plugin mechanism thought you would want to do with it. But if you’re using the exact same tools as the original authors were using, you can bet they put all their effort into making that a seamless, powerful experience, and that you’ll be able to access things on an entirely new level.
Incidentally, this is the only reason anyone uses Firefox even when Webkit is an obviously superior engine. Even with all the wretched mistakes they made with the extension system, you’re writing JS, which is what much of Firefox is written in.
October 29th, 2008 at 4:27 am
I’ve read a lot of blogs in which people say how emacs is great for coding C, C++, Ruby, etc.
Why it is not so great for coding Java?
October 29th, 2008 at 8:46 am
@Dima, it’s not that Emacs is necessarily bad at handling Java projects, just that I find the specialized IDEs for Java (e.g. Eclipse) so much more productive. Where a tool like Eclipse shines is the fact that it doesn’t treat code like a text file, but instead as an always-parsed syntax tree. With a statically-typed language like Java this allows you to do some powerful manipulation of your code. The refactoring tool in Eclipse is enough for me to forgo doing Java in Emacs.
This is largely a matter of taste though. I don’t have a problem keeping the idiosyncrasies of various tools in my head so I don’t need to be a one-tool-to-rule-them-all kind of guy.
I’ve invested quite a bit of time and effort in Eclipse such that I am simply more productive with that tool than I would be in any other for Java. However I find it pretty lacking as a general-purpose editor. When I started doing Ruby I tried using Eclipse and gave up after a few weeks.
As always, YMMV and one should always choose the right tool for the job.
October 30th, 2008 at 12:22 am
alex, isn’t C++ statically-typed? or C++ developers don’t need all these refactorings? I never write any C++-code what’s why I’m asking..
October 30th, 2008 at 9:10 am
I can’t speak authoritatively on C++ since I ran away from it screaming when I was first exposed to it. I would guess that an approach like the one Eclipse takes would work for C++. In fact, I know that there’s some C/C++ workbench for Eclipse.
It may not have caught because it doesn’t work well, or simply because of cultural inertia within the community. Most folks simply don’t change their toolset that often; and certainly not something as crucial as their editor.
November 1st, 2008 at 9:07 pm
I have used Eclipse/MyEclipseIDE for many years. I have used Emacs for over 30. I agree Eclipse* is a very good tool for Java. Mainly because of the refactorings, the ease of importing or referencing existing projects and the ability to view over-ridden methods in class hierarchies. However there are still some Java refactorings I need to use emacs to realize. Of course Emacs requires a module like http://www.xref.sk/xrefactory-java/main.html to do meaningful Java refactorings. But XRefactory works very well. I only wish that as a new java programmer I stuck with XRefactory instead of going to Eclipse
Leave a Reply