This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-26
Channels
- # announcements (7)
- # aws (1)
- # babashka (15)
- # beginners (144)
- # calva (8)
- # chlorine-clover (15)
- # clara (4)
- # clojure (65)
- # clojure-europe (131)
- # clojure-france (1)
- # clojure-nl (6)
- # clojure-nlp (3)
- # clojure-spec (10)
- # clojure-uk (52)
- # clojuredesign-podcast (2)
- # clojurescript (28)
- # cryogen (1)
- # datomic (17)
- # events (2)
- # figwheel-main (2)
- # fulcro (8)
- # hugsql (2)
- # jackdaw (4)
- # jobs (1)
- # leiningen (8)
- # lumo (1)
- # malli (4)
- # off-topic (23)
- # parinfer (3)
- # pathom (3)
- # pedestal (5)
- # re-frame (9)
- # reagent (26)
- # reitit (13)
- # reveal (25)
- # shadow-cljs (45)
- # spacemacs (7)
- # sql (7)
- # tools-deps (40)
- # vrac (2)
- # xtdb (22)
I wrote a basic functions to spawn and connect to a babashka repl using CIDER
(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"))
I don't mind spawning a clojure repl outside of emacs, then connect to it from CIDER, but since babashka is for more short-lived scripts I find it useful not having to go to a terminal, run babashka, connect to ciderWow nice! I think that could be documented here: https://github.com/borkdude/babashka/blob/master/doc/repl.md
I think the "Started nREPL server at ..." should go to stderr. Would --process-filter still work in that case?
Yes, when you start a process on emacs, by default stdout and stderr are mixed together. I'll do a PR for repl.md, although I'll also look into contributing to CIDER to be able to jack-in directly into babashka, which would rend this obsolete.
@schpaencoder Probably not the answer you're looking for, but I usually use prn
, println
and *err*
if you want to print to stdout/stderr
@schpaencoder I use a function I add to every bb script. YMMV but it serves my needs. If I need to log contents of vars, maps, etc I use a format string.
#!/usr/bin/env bb
(ns app)
(defn logit [msg]
(spit "app.log" (str msg "\n") :append true))
(logit (format "%s %d" "log message" 5))
@michael819 Btw (spit "app.log" ... :append true)
does the same thing