Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

Aggressive Auto-indentation

electric-indent-mode is enough to keep your code nicely aligned when all you do is type. However, once you start shifting blocks around, transposing lines, or slurping and barfing sexps, indentation is bound to go wrong.

Today’s lesson is my answer to mgoszcz2's question. Having the perfect auto-indent is easier than you might think. I've turned this post into a package. Emacsers, meet aggressive-indent.

So long as you have Melpa configured, you can install it with.

M-x package-install RET aggressive-indent

Then simply turn it on and you’ll never have unindented code again.

(global-aggressive-indent-mode)

This will activate aggressive-indent-mode on every non-text buffer. If you're a little shy, you can also turn it on only for specific major modes by using hooks.

(add-hook 'emacs-lisp-mode-hook #'aggressive-indent-mode)

Here’s some code to try it on. After you’ve evaluated the above, open a new “.el” file, paste the following code, and type something before the opening parentheses.

(this is a
      test)

Update <2014-10-20 Mon>

Announce new package!

Tags: indent, init.el, emacs,

comments powered by Disqus