Separate CIDER REPL Histories for Different Clojure Projects
CIDER provides a REPL history that persists across REPL sessions. You set this up by setting the (Emacs) variable
cider-repl-history-file to be the name of the file in which to store the history. CIDER will then read from the file when starting up a REPL and write to it when closing down a REPL.
That single variable is shared by all projects, which means you have one history that is shared by all projects. (FWIW, there is some jiggery-pokery that means if you have more than one REPL running at the same time you don't lose history as a result of one project blatting the write of another project.)
The single shared history is good if you are just playing around with stuff that isn't project-specific, but mostly I find it annoying — I want separate REPL histories for different Clojure projects.
For a while I hacked CIDER each time I upgraded it so that it created a separate file for each project. But then something changed in the CIDER code that made it harder to apply my hack and I stopped bothering.
So for a good while now I've had a single CIDER history shared across all projects.
But finally I've found a way to fix this, mentioned in a comment about Emacs .dir-locals on a CIDER issue about persistent REPL history. A little digging led me to the following solution…
Simply create a file called
.dir-locals.el in your home directory with this content:
((cider-repl-mode (cider-repl-history-file . ".cider-repl-history")))
This will create a directory-local variable for
cider-repl-mode, and each of your Clojure projects will have its own history file.
As another commenter on that CIDER issue said, Now, that sounds emacsy.