Emacs


For more then 10 years I’m looking for the ideal text (and code) editor. I’ve started my journey with small, fast and probably forgotten text editor called Context. I was quite happy with it, but its development was stopped, which forced my to look for something else. At that moment, I’ve started to use Notepad++ which I still like and treat as useful, general purpose editor. Around the 2008 year Sublime Text appeared and I’ve soon started to use it. I’ve used version 1 to 3 and I think it’s very good text editor (I’m using it from time to time even now). During those years, I’ve also tried to use vim - for sure it’s an excellent text editor, but I have problem with using it. Maybe it’s because two modes and necessity of switching between them using command, maybe it’s because the way you configure it. I don’t really know, but I couldn’t switch to vim (still using it in rare cases in Linux OS).

Around a year ago, I’ve started reading about Clojure and in general about Lisp. Among the developers using Lisp and it’s dialects Emacs is the most popular text editor. The reason is simple, Emacs has be built in the Lisp interpreter (strictly speaking Emacs lisp) which is used to configure and extend it’s functionality. This convinced me to give it a try. First I was skeptical (I’ve used Emacs in one of my course, during studies), but after some time of using it (and understanding its philosophy), I think it’s the best text editor (or maybe an operating system ;) I’ve ever use.

In the next post of my Emacs series, I will describe how I’ve switched to Emacs. In this text I only focus on the reasons why Emacs shines in my opinion.

Modes

To understand Emacs, you need to realize that it is a multi modes editor. This means that for currently edited document you can have one major mode (like markdown mode, JavaScript mode and so one) and many minor modes (like autocomplete, snippets, spell checker and similar). All those modes define functions that can be either invoked by name (using M-x key) or using key shortcut (in Emacs named key binding). Those functions can be very different, from simple one, like move a cursor forward, to the advance one like convert markdown to HTML.

By default Emacs comes with wide range of preinstalled modes.

Customization and extensibility

As I mentioned before, all configuration in Emacs is done using elisp. This means that you have the power of real programming language at your disposal. You can configure basic options - that every text editor has (like: font, color schema, usage of tabs and so on), but you can change almost everything. You can define your own functions, that can be invoked or binded to keys combination. You can load minor modes depending on major mode (using hooks). You can show line numbers depending on mode. And many, many, more. This freedom is so big, that people write very elaborated addons (like git, email or irc clients) - called here packages. Starting from Emacs 24 those packages can be installed directly from Emacs using a simple package manager (a bit similar to JS npm or .Net NuGet).

Emacs lisp

The general philosophy of Emacs is to allow you to do as much as possible from editor. You can write code, read twitter, speak on IRC, use terminal and play ‘tetris’ without leaving Emacs. This is the reason why people call it an “operating system”. For me this is one of the greatest features of it. You don’t need to switch contexts (and windows) to do many typical task for the programmer.

For people, who can’t live without Vim way of working with text (navigate and write text in different modes) there are good emulators for Emacs.

All of this makes that you can fully customize the behavior and look of Emacs. If you can’t live without tabs, you can find package for it or maybe you want to have file navigator on the left side, no problem there is a package for it. I think you see the pattern right now.

Org mode

The org mode is the second reason why I fall in love with Emacs. What is it? This sentence: “Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system” from the main page summarize it the best.

I used several pages to track my time, Evernote and hackpad to store notes, Wunderlist to maintain my TODO items and sever other services. The end result was that I still had problems with finding what I need. From the moment when I started using org-mode all of this is gone. Now I store everything in a few org files that are synchronized with all my computers by Dropbox. Those files are simple, text files, so I don’t need to worry about loosing my work. This mode allows me (using agenda) to search or summarize all the items through out all those files.

Thanks to the power of the org-mode every item is properly highlighted and justified. You can mark item with tags, add status to it or even schedule to specific date. You can also add note to any point, link to external page or local file. I know only the basic features of this mode (still learning and discovering new stuff) but still I’m amazed.

If you install Emacs on your computer, you definitely should try org-mode!

Org mode

Editing code

I’ve described many Emacs possibility, but in the first place it’s of course superior code editor. On a daily basics I use it to edit JavaScript, Clojure and Emacs lisp. From time to time I edit some XML or json files. In all those usages it works great!

JavaScript

For editing JavaScript I use js2-mode. What I like in it is the proper auto-indentation of code, good syntax highlighting and built-in JS lint (it marks missing colons, not used variables and many others). All those features make that editing JS code is very pleasant experience.

Clojure

As I wrote before Clojure is a dialect of Lisp, so using Emacs to edit it is an obvious choice. But even this can be improved. By installing cider (and clojure-mode) mode you can change a text editor in fully featured IDE for editing Clojure. Lets list only main features of those modes:

  • proper code indention
  • using REPL from Emacs buffer
  • code evaluation inside code buffer (ala LightTable)
  • documentation lookup
  • debugger
  • value inspector
    and many many more…

I’ve used most IDE and code editors (NetBeans, IntelliJ, Cursive, LightTable) for working with Clojure and I have to say that, from my perspective, they can’t compete with this setup. If you do Clojure, you definitely should give it a try.

Drawbacks

Emacs has of course its own drawbacks. The obvious one is the learning curve when starting using it. The lack of knowledge of any kind of Lisp and strange key bindings can make it hard to use and configure at the first time.

From my perspective there is one more problem, Emacs has slow startup time. Especially if you have many packages installed, the opening it can take few seconds. To minimize this annoyance you should learn to work only with one instance of it. If you finish editing file, you shouldn’t close the program, but only the buffer.

Summary

Emacs isn’t for everybody. Some people can’t live without graphical GUI, others can’t stand its shortcut. But I highly recommend you give it a try. If you defeat initial problems you will find excellent text editor.


You may also like

Starting with Emacs

ClojureScript: JavaScript Interop

NDepend