Endless Parentheses

Concise ramblings on Emacs productivity.

A small improvement to clj-refactor

I’ve said before that clj-refactor is a magical package, and you wouldn’t catch me bad-mouthing it in a million release cycles, but it’s impossible to please everybody.

One consistent annoyance I have with it, is that I always have to type Tab twice after invoking cljr-add-require-to-ns. That’s because I only ever use requires of the form [x.y :as y], so I always have to skip the first two “modes” offered by the snippet.

As I was teaching a friend about this command last week, he immediately asked me if you couldn’t just write some Elisp to do that for you. Of course, the answer is yes. And that’s exactly what I did — once I was done feeling embarrassed that I hadn’t thought of that before.

(advice-add 'cljr-add-require-to-ns :after
            (lambda (&rest _)

Note that this uses the new advice interface, which relies on Emacs 24.5. While this API in its entirety can be quite intimidating, you don’t need to learn it all in one go. You can go a long way (and make your life a lot easier) by just writing yourself a few :before and :after advices.

Just remember to be responsible. Advices let you run code in places where packages don’t expect code to be run. So don’t be surprised if something else breaks.

Tags: CIDER, clojure, programming, init.el, emacs

Say thanks on Gratipay
comments powered by Disqus