This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (14)
- # aws (1)
- # babashka (23)
- # beginners (442)
- # calva (50)
- # chlorine-clover (1)
- # cider (32)
- # clojure (124)
- # clojure-europe (35)
- # clojure-france (5)
- # clojure-gamedev (5)
- # clojure-nl (2)
- # clojure-portugal (3)
- # clojure-uk (4)
- # clojurescript (56)
- # conjure (5)
- # cursive (24)
- # datalevin (1)
- # datomic (57)
- # fulcro (35)
- # helix (15)
- # holy-lambda (8)
- # introduce-yourself (1)
- # jobs (5)
- # kaocha (1)
- # lsp (99)
- # malli (10)
- # music (1)
- # off-topic (22)
- # pathom (38)
- # podcasts (10)
- # polylith (10)
- # reitit (1)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (18)
- # spacemacs (6)
- # tools-build (22)
- # vim (66)
- # xtdb (22)
Maybe it's useful for some.
I wrote a simple
cider-jack-in-babashkafunction that's handy when you want to have a repl quick:
(defun cider-jack-in-babashka () (interactive) (let* ((default-directory (project-root (project-current t))) (port (+ 1024 (random 5000))) (params `(:host "localhost" :port ,port :project-dir ,default-directory))) (start-process-shell-command "babashka-nrepl" "*babashka-nrepl*" (concat "bb nrepl-server " (number-to-string port))) (sleep-for 0.5) (cider-connect-clj params)))
This seems useful to contribute to the http://book.babashka.org nREPL section
Should I make a PR or you want to just add it? Also, if someone has a better idea to find a free port and check when the babashka process is really running please say 🙂 random port and just sleeping for 0.5 seconds doesn't sound ideal but was enough for me personally.
@UFAP0C8KU If the server writes the port you can just wait a bit a read it from the
.nrepl_port file (or however it was named).
Or you can just extract it from the server output, as we do for the Clojure nREPL server.
Thanks. I think parsing it from the output is a good idea. Then I don't need the sleep kludge as the server should be ready when I'm able to read the port.
@U04V15CAJ is there a simple way to start babashka on the command line to always start on a free port (e.g. if 1667 is already in use, just use 1668 etc)? I don't really want to use a
bb.ednas described in https://book.babashka.org/#_nrepl
@UFAP0C8KU yes, use port
I have one similar:
(defun my-babashka-connect--process-filter (proc string) "Run cider-connect once babashka nrepl server is ready." (when (string-match "Started nREPL server at .+:\\([0-9]+\\)" string) (cider-connect-clj (list :host "localhost" :port (match-string 1 string)))) ;; Default behavior: write to process buffer (internal-default-process-filter proc string)) (defun my-babashka-connect () "Start babashka on a random port." (interactive) (let ((port (+ 1230 (cl-random 300)))) (set-process-filter (start-process "babashka" "*babashka*" "bb" "--nrepl-server" (number-to-string port)) 'my-babashka-connect--process-filter))) (defun my-babashka-quit () "Quit cider and kill babashka process." (interactive) (cider-quit) (kill-process (get-process "babashka")) (message "babashka is kill"))
We could also post this on the babashka wiki if there not a single right approach (the wiki is open for anyone to post)
@U7S5E44DB nice, that looks like something I would have ended up with anyway. Just that port number can be
0 now instead of random.
And an improvement would maybe to remap
cider-quit to your babashka quit function.
For cider itself there is already an open issue https://github.com/clojure-emacs/cider/issues/2947 But if I read it correctly the plan is to not add a special babashka jack-in function
My point was that I was hoping we could detect that something is a babashka project and use the existing jack-in function which simply runs bababashka's nREPL server then.
Seems like a better user experience than one more function that people will have to know about, but I don't have any fundamental issues with a dedicated babashka command.
yeah agree with Bozhidar, we could detect if the project contains
bb.edn IIRC we do a similar thing for Shadow Cljs
Jep, I agree. One jack-in command where someone can choose the repl backend(?) is probably more user-friendly.
But lets start with putting a simple command in the babashka wiki or http://book.babashka.org This is basically the version from @U7S5E44DB but with port 0, the default directory is set to the project root and it should work over tramp (untested):
(defun cider-jack-in-babashka () "Start an babashka nREPL server for the current project and connect to it." (interactive) (let* ((default-directory (project-root (project-current t))) (process-filter (lambda (proc string) "Run cider-connect once babashka nrepl server is ready." (when (string-match "Started nREPL server at .+:\\([0-9]+\\)" string) (cider-connect-clj (list :host "localhost" :port (match-string 1 string) :project-dir default-directory))) ;; Default behavior: write to process buffer (internal-default-process-filter proc string)))) (set-process-filter (start-file-process "babashka" "*babashka*" "bb" "--nrepl-server" "0") process-filter)))
Perhaps start with wiki so we can tweak the code easier, and we can link in the book to the wiki
https://github.com/babashka/babashka/wiki/ Shall we add an emacs page there?
@U0C8489U6 the thing with
bb.edn is that it's not always there. And the main reason I even wrote this snippet was that often I simply wanted a quick repl to experiment in my project. Now I can just create a buffer
M-x cider-jack-in-babashka and I have a working nrepl session in my editor in milliseconds preloaded with lots of useful libs to manipulate all kinds of files etc 🙂
@UFAP0C8KU I see yeah that makes sense for random stuff. I am actually using both in project and random...however for the latter use case I have this in my conf and connect directly:
(cider-known-endpoints '(("localhost" "1667") ;; babashka ("localhost" "5555") ;; common ))
Could probably use more text but here's a start: https://github.com/babashka/babashka/wiki/GNU-Emacs
FYI - I plan to cut CIDER 1.2 in a week or two, so now's a good time to test the current
master. It seems to be in a good shape overall, but a bit of extra testing never hurts. 🙂
I just saw https://github.com/babashka/neil/blob/main/neil#L2
and made https://github.com/clojure-emacs/clojure-mode/pull/604 so that's not necessary anymore. I would say
bb is unique enough for us to always add to
interpreter-mode-alist when the user has clojure-mode installed.