Emacs as my IDE: homecoming

Once upon time I wrote code using Turbo Pascal and Borland C. Then I discovered protected mode and heard of a compiler called DJGPP that could emit 32-bit code that could access more than 640k of memory. I had to have it. Unfortunately I was used to my text-based IDEs and had no idea how to use a compiler from the command-line. RHIDE and its near perfect imitation of the Borland interface won me over.

At some point that I don’t quite remember (probably when I went to CERN) I started using Linux and Emacs. Emacs was weird. None of the keystroke conventions of other programs worked. It did its own thing. It took a while but I got used to it and even modified my .emacs file, although never so much as to be in a foreign place on a new installation. I’d only really copy elisp from the internet. I ended up using Emacs to write pretty much any code, except for Java. I wrote that in Eclipse.

When I joined Cisco, everyone in my team was using Eclipse in a Linux VM running on Window to write C and C++. I joined the team and started resenting Eclipse more and more each day. At one point I managed to configure a Windows XP VM running Visual Studio that used up less RAM than Eclipse on Linux! But I had to give it to the IDE: it made many things easier when working on a shared codebase. I longed for Emacs but I didn’t want to give up the IDE features that I now relied on, in order of importance:

  1. Jump to definition.
  2. Autocompletion.
  3. On-the-fly syntax checking
  4. Finding a file in the project
  5. Macro expansion
  6. Rename refactoring

If only I could find a way of having this in Emacs… I knew there must be a way, but I also knew it wasn’t going to be easy. So I procrastinated for years. Until last year.

Last year I went into a mad flurry of optimising my productivity. I tried different Linux distros, desktop environments, the works. I changed a lot of the way that I work. My Linux distro went from Kubuntu to Arch Linux. My shell, from bash to zsh. My favourite language was C++, now it’s D. And my “IDE” is now Emacs.

I use auto-complete-clang and flycheck for items 2 and 3 above, and until a few days ago, cscope for item 1. But there were problems since the compiler flags used to build the project must be known for all of this to actually work. But my build system knows the compiler flags, so how do I get it to pass those flags on?

Well, this is an Emacs post so the answer is of course, to write a new elisp package which I called cmake-ide, because that’s what I always use for C and C++ development. But cscope was still annoying me with its fake matches. What if I could use clang for not only autocompletion and on-the-fly highlighting but also for finding definitions? Turns out I can with rtags! I integrated this into cmake-ide and now life is good.

I’m never leaving Emacs now. I have everything I had with Eclipse, and the features I missed even work better than they did there. I version control my .emacs.d directory. I write unit tests in elisp to make sure that my packages don’t break. And I’m more productive for it. Life is good.

Advertisements

4 thoughts on “Emacs as my IDE: homecoming

  1. Hey Atila, any further details on this – sounds like exactly what I want.

  2. […] is my editor of choice, I use it to write nearly everything. I have to write Python at work, which I’m ok with since […]

  3. […] also learned that I’m doing a lightning talk tomorrow on Emacs as a C++ IDE, which means that now I have to actually write that talk! I’ll have another blog up tomorrow […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: