Fix focus behavior in CIDER mode for Emacs

Adrien Mogenet
2 min readMar 12, 2017

Today 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 $EDITORas 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 and signature of an input function.

Any reason to change buffer’s focus when displaying documentation?

The problem is that CIDER always decides 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> don’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 to avoid this 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.

--

--

Adrien Mogenet

AI & Engineering | I help people and organizations make impactful decisions.