Skip to content

Instantly share code, notes, and snippets.

@llacom
Created February 4, 2021 09:49
Show Gist options
  • Save llacom/f391f41cbf4de91739b52bf8bb1a6d54 to your computer and use it in GitHub Desktop.
Save llacom/f391f41cbf4de91739b52bf8bb1a6d54 to your computer and use it in GitHub Desktop.
emacs/cider commands to spawn a babashka repl and connect to it
(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"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment