Saturday, October 20, 2018

Spacemacs Cider Figwheel

Spacemacs Cider Figwheel
I had lots of weird issues getting my workflow going in spacemacs. Sometimes figwheel did not live update, sometimes I could not evaluate expressions in the editor. There are plenty of guides but many of them are old and some of them tell you to make changes you don’t need and then things break. Then I tried to fix what appeared broken only to make things worse.

I started over several times with new lein projects and worked through the tutorials. Everything clicked when I learned about the helper functions which are stored in the user.clj https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl .
It turns out the luminus template I was using works with emacs/cider without any changes, if you know the correct things to do.

Make a new project:

lein new luminus myproject +re-frame +postgres

Setup your database:

Add your dev database to postgres
psql
create database myproject_dev
create database myproject_test
then follow http://www.luminusweb.net/docs/database.html to setup your edn files and migrate

Spacemacs

Open a clj file. I like to open project.clj (but don’t change anything).

Now use:, ' to start cider. Wait… you can always switch buffers to SPC b b and choose the buffer with nrepl in the name however eventually you will see a buffer with cider in the name and that is the one you will use.

Or if you left you PC and went to grab a cup of coffee when you get back you should be able to use , s s to show the cider repl buffer.

Troubleshooting: The cider hotkeys should work when you have any .clj file open. Mine stopped working which was very confusing. To fix it I deleted my .emacs.d directory and .spacemacs and re-cloned spacemacs. In this repl you can migrate your database if it changed, start the https server and figwheel.

(start)
(start-fw) 
(cljs)
Now you can evaluate any expression in a cljs file using , e f and as you change and save your cljs files you will see it update in the browser in real time.
If you need to do some work on the backend you can execute :cljs/exit to get back to the clj prompt.

Find stuff

Emacs

Sometimes I see what args a function takes in the editor, but I have to know the name of the function. I am still not sure how to get emacs to do code completions.

List everything in a namespace

(keys (ns-publics 'namespace))
That little "'" in front of your namespace is very important. otherwise you get an error that looks like

xxxxxxx

User.clj

This file contains the commands you can run while you are in the user namespace.

This is a good place to look for new commands when you are working with different templates or to add the convenience you got use to.

No comments:

Post a Comment