DEV Community

Cover image for Simple Emacs configuration for Clojure development
Matheus Moreira
Matheus Moreira

Posted on

Simple Emacs configuration for Clojure development

I suppose that most programmers have, together with their preferred IDE (such as Intellij IDEA, Eclipse and Visual Studio), a lighter code editor for smaller coding tasks. I remember using Notepad++, changing to Sublime Text at some point, than more recently to Visual Studio Code. My current "light" editor of choice is Emacs.

The main reason for choosing Emacs is that I wanted a great coding experience when developing in Clojure. I tried to use Intellij IDEA with Cursive but even though I am familiar with the IDE (I use it daily to write Java and Kotlin code), it doesn't feel right with Clojure, a heavy weight tool with a slim language... So I resorted to simpler code editors, but never found a setup that was appealing.

I don't think we can say that Emacs is "light" or "simple". It can be a beast... I tried many times to learn it but the learning curve can be discouraging. Only recently I read a post where the author gave a suggestion that is helping me learn Emacs step by step: M-x is your friend. :-) Learn a few basic keybindings and start using the editor, use M-x for actions you don't know the binding. With time you'll memorize bindings for actions that you repeteadly use.

That tip took care of the anxiety I had when using Emacs without knowing my way around it! Time to setup my Clojure development environment and start writing some serious code! Or not... Emacs is a black hole of packages, options, ways of organizing your configuration.

To simplify things I used the configuration suggested on the book Clojure for the Brave and True and tried Spacemacs with the Clojure layer. The problem is that I am the kind of guy that wants to know why things work the way they work, I wanted to be able to replicate parts of these setups and understand them.

After a lot of trials, errors and frustrations I finally came up with a initial setup that I am happy with! I think it is good enough for my taste and a small starting point for further customization, and that is why I decided to share it. Check out this gist!

A quick overview of what this configuration does:

  1. Adds Melpa as an additional packages source.
  2. Sets Dank Mono as default font. Change the :family attribute to your preferred font.
  3. Installs zenburn theme, super nice.
  4. Installs undo-tree, a package that gives visual clues of your changes history. Reading the docs I discovered that Emacs has a very powerful redo/undo system and undo-tree makes full use of it.
  5. Installs ivy, a completion system. I opted for ivy because it is cider and other packages recommend it.
  6. Installs smex, a package that improves the use of M-x.
  7. Installs projectile to help navigate between files in a project.
  8. Installs magit for Git interaction. You'll be able to do a lot with only two keybindings!
  9. Installs exec-path-from-shell, that is used to set Emacs path from your shell's path (I use it because my current OS is MacOS, I think it is not required for Windows).
  10. Installs flycheck and flycheck-clj-kondo. Flycheck-clj-kondo is a nice linting and analysis tool for Clojure, highly recommended.
  11. Installs company-mode, a package that is used for code completion.
  12. Installs clojure-mode, cider and clj-refactor, the main packages for Clojure development.
  13. Installs which-key. This makes using M-x much easier because it presents "next keys" options based on a prefix keybinding. E.g. You press C-c and it shows further keys that can complete the keybinding. Super nice!
  14. Performs other simple configurations (under editing, ui and misc). These came mainly from the Clojure from the Brave and True setup.

I recommend that you take some time and read at least a bit of each package's documentation. You'll better understand not only the configuration file but the capabilities that each tool provide. Let me know if this configuration is useful for you and if you have any suggestions on how to improve it.

Godspeed.

Cover photo by Ussama Azam on Unsplash.

Top comments (0)