Thursday, May 1, 2014

Emacs, clojure/cider mode: boring autofocus...

Today, – labor day – I've fine tuned my Emacs setup which hasn't evolved for a while. Digging into emacs24 packages, testing rainbow-delimiters, customizing company-mode, etc. As a Clojure beginner, I'm discovering joy of programming lisp-languages within my favorite $EDITOR as well.

Then I've played with CIDER, a Clojure IDE and REPL for Emacs. As expected you can benefit form REPL model directly, plus many additional features, such as stacktraces analysis. One of my favorite feature is to get shortcut (C-c C-d in my case) to display the documentation of an input function.


The problem was that CIDER always decided to automatically move the focus to the attached buffer. This leads into boring keyboard combinations to switch back to the original buffer, even smart shortcuts such as C-<up> won't satisfy myself. There are configuration options to annihilate this behavior when throwing an error or the REPL prompts, but I didn't find anything when accessing the documentation.

And here comes the patch! If you're annoyed by this behavior, feel free to patch your setup:

diff --git a/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el b/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
index 8f4b8cb..8bcccbf 100644
--- a/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
+++ b/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
@@ -1153,7 +1153,7 @@ if there is no symbol at point, or if QUERY is non-nil."
 (defun cider-doc-handler (symbol)
   "Create a handler to lookup documentation for SYMBOL."
   (let ((form (format "(clojure.repl/doc %s)" symbol))
-        (doc-buffer (cider-popup-buffer cider-doc-buffer t)))
+        (doc-buffer (cider-popup-buffer cider-doc-buffer nil)))
     (cider-tooling-eval form
                         (cider-popup-eval-out-handler doc-buffer)
                         nrepl-buffer-ns)))

Of course, you may create your own variable to customize focus strategy, but I've never seen a very long documentation which could justify moving focus to another buffer.