This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-06
Channels
- # announcements (58)
- # babashka (43)
- # babashka-sci-dev (22)
- # beginners (8)
- # biff (8)
- # calva (62)
- # circleci (3)
- # clerk (6)
- # clj-kondo (27)
- # cljsrn (9)
- # clojure (61)
- # clojure-austin (4)
- # clojure-conj (3)
- # clojure-europe (11)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-norway (4)
- # clojure-spain (5)
- # clojure-uk (2)
- # clojurescript (51)
- # data-science (1)
- # datascript (4)
- # emacs (33)
- # events (14)
- # funcool (14)
- # gratitude (13)
- # introduce-yourself (1)
- # jobs (9)
- # lsp (58)
- # malli (23)
- # missionary (30)
- # nextjournal (9)
- # off-topic (35)
- # proletarian (2)
- # re-frame (5)
- # remote-jobs (7)
- # shadow-cljs (2)
- # spacemacs (7)
- # sql (26)
- # testing (12)
- # vim (1)
- # web-security (3)
- # xtdb (2)
Interesting this https://github.com/babashka/babashka/blob/10638685549205926489ac325721261c301819d4/src/babashka/impl/sigint_handler.clj#L15, when I do something simple in a shutdown hook (say (p/process "ls")
), things go fine, but if I try to run (p/process "docker compose down")
, then the bb task says
Error while executing task: dev
and the exit code is 130interesting that same happens with say
(clojure.java.shell/sh "sleep" "1")
but not with zero sleep
(clojure.java.shell/sh "sleep" "0")
would think getting the output of the process would block
maybe just have to be real quick inside the shutdownhook 🙂0% cat bb.edn
{:tasks
{shutdown-hook {:requires ([clojure.java.shell :refer [sh]])
:task (do
(.addShutdownHook (Runtime/getRuntime) (Thread. (fn []
(println "hook running")
(sh "sleep" "10")
(println "hook done"))))
(shell "clojure"))}}}
[email protected] ~/work/babashka-stuff
0% cat deps.edn
{:deps {nrepl/nrepl {:mvn/version "1.0.0"}
cider/cider-nrepl {:mvn/version "0.28.6"}
com.bhauman/rebel-readline {:mvn/version "0.1.4"}}
:main-opts ["-m" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"
"--interactive"
"--repl-fn" "rebel-readline.main/-main"]}
[email protected] ~/work/babashka-stuff
0% bb run shutdown-hook
Clojure 1.11.1
user=> ^D
hook running
^Chook done
[email protected] ~/work/babashka-stuff
0% echo $?
0
[email protected] ~/work/babashka-stuff
0% bb run shutdown-hook
Clojure 1.11.1
user=> ^Chook running
Error while executing task: shutdown-hook
^Chook done
[email protected] ~/work/babashka-stuff
0% echo $?
130
[email protected] ~/work/babashka-stuff
0% bb run shutdown-hook
Clojure 1.11.1
user=> ^D
hook running
hook done
[email protected] ~/work/babashka-stuff
0% echo $?
0
[email protected] ~/work/babashka-stuff
0% bb run shutdown-hook
Clojure 1.11.1
user=> ^Chook running
Error while executing task: shutdown-hook
hook done
[email protected] ~/work/babashka-stuff
0% echo $?
130
not quite same, but probably related to how rebel-readline behaves with sigint
in the above the first CTRL^C are without waiting for the sleep in the hook to end, then more patientThe fix:
{:tasks
{shutdown-hook {:requires ([clojure.java.shell :refer [sh]])
:task (do
(.addShutdownHook
(Runtime/getRuntime) (Thread. (fn []
(println "hook running")
(sh "sleep" "10")
(println "hook done"))))
(shell {:continue true} "clojure"))}}}
The command line is where programming cultures intersect :) https://twitter.com/charmcli/status/1622657411633885190
command line, the great bridge pipe
Babasjka / emacs question: In my setup I’d like to be editing babashka scripts (`http://script.bb`) in various directories. These scripts are stand-alone and have no edn or any accompanying files. In emacs / cider - I can’t seem to open a babashka repl because it’s not detecting a project. I’m trying to work out a command (so I can map my own key) to open the babashka repl, but I can’t figure out how to do this. Right now I’m trying:
(cider-jack-in '(:jack-in-cmd "/opt/homebrew/bin/bb nrepl-server"))
This doesn’t seem to work because the jack-in-cmd gets overridden when no project is detected. Anyone have any ideas here?
Yes, and this is what I have been doing - but I’m trying to avoid littering my filesystem with unnecessary EDNs. I’d like it to be just like when I use a shell script with no additional files.
When I start the repl in the terminal - that works, but it’s not integrated into emacs.
It’s more of a cider / emacs question really I think. But since it’s babashka, I started here.
Use cider-connect
to the nREPL server you start in the terminal. Don't use jack-in
if you don't have a project, I guess
I'm talking about an nREPL server. not about a console REPL where you type expressions in your terminal.
Yes - I can do that. I’m just trying to do it in emacs.
Those docs work, I’m just trying to figure out how to do it in emacs using the elisp cider functions.
But I can create a new function specifically for this - there is just a lot of functionality already there and I thought maybe I was missing something.
Right now, it appears that cider doesn’t really handle “no project detected” in a flexible way. It forces the default jack-in command at that point.
ah - maybe @U02CV2P4J6S knows more about this
kk - thanks for the quick chat, will dig further.
https://github.com/clojure-emacs/cider/pull/3286 providing jack in cmd doesn't work right now but I made a pull request that probably soon is merged. With this you can either use a param like you want to, or use a dir locals. For the moment you could checkout the branch or you could make a bb.edn with an empty map in every dir you want to start bb nrepl as a workaround @U0250GGJGAE
another workaround:
;; the equivalent of the proposed change
(advice-add
'cider--update-jack-in-cmd
:before-until
(defun cider-dont-update-jack-in-cmd-when-given (params)
(when (plist-get params :jack-in-cmd) params)))
;; now a nbb jack in command becomes:
(cider-jack-in '(:jack-in-cmd "nbb nrepl-server"))
I have this in my config (stolen from corgi) for a quick jack-in to a babashka file https://github.com/dakra/dmacs/blob/632864dacd60d61c948a657d703eddcb761cd9f7/init.org?plain=1#L5745-L5765
;; jack-in for babashka from corgi
;;
(defun cider-jack-in-babashka (&optional project-dir)
"Start a utility CIDER REPL backed by Babashka, not related to a specific project."
(interactive)
(let ((project-dir (or project-dir (project-root (project-current t)))))
(nrepl-start-server-process
project-dir
"bb --nrepl-server 0"
(lambda (server-buffer)
(cider-nrepl-connect
(list :repl-buffer server-buffer
:repl-type 'clj
:host (plist-get nrepl-endpoint :host)
:port (plist-get nrepl-endpoint :port)
:project-dir project-dir
:session-name "babashka"
:repl-init-function (lambda ()
(setq-local cljr-suppress-no-project-warning t
cljr-suppress-middleware-warnings t)
(rename-buffer "*babashka-repl*"))))))))
https://github.com/babashka/babashka/wiki/GNU-Emacs Apparently I made this entry 2021 already 😄
(If you are living on the latest master cider branch, e.g. with the straight package manager, there is also the yet-unreleased https://github.com/clojure-emacs/cider/blob/master/doc/modules/ROOT/pages/basics/up_and_running.adoc#Universal-jack-in command you might want consider. It uses emacs numerical arguments (M-1 M-x cider-jack-in-universal, M-2 ... etc) to quickly launch one of clojure cli, lein, bb or nbb nREPLs outside of a project)