This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-10
Channels
- # announcements (16)
- # asami (7)
- # aws (5)
- # beginners (46)
- # calva (47)
- # clj-kondo (3)
- # cljdoc (23)
- # clojure (70)
- # clojure-germany (1)
- # clojurescript (6)
- # community-development (2)
- # datomic (3)
- # emacs (14)
- # exercism (5)
- # hyperfiddle (4)
- # jobs (1)
- # kaocha (9)
- # lsp (13)
- # malli (6)
- # membrane (11)
- # off-topic (22)
- # pedestal (4)
- # portal (19)
- # quil (3)
- # reagent (8)
- # remote-jobs (1)
- # shadow-cljs (48)
- # spacemacs (5)
what I'd like to have is basically a scratch buffer with an attached jvm and cider. Does somebody have a flow for this?
Like, a permanent scratch buffer? I use:
(after! clojure-mode (setq cider-allow-jack-in-without-project t))
(after! clojure-mode (setq cljr-suppress-no-project-warning t))
to be able to jack in from any file without warnings, but that's about it. In your case, you could also:
(setq initial-major-mode 'clojure-mode)
to have your scratch buffer automatically be in clojure-mode
, but from there you still need to jack-in manually.There are a few different ingredients, Corgi has a convenient jack-in-babashka
which creates a *babashka-repl*
https://github.com/lambdaisland/corgi-packages/blob/main/corgi-clojure/corgi-clojure.el#L192-L211
It then falls back to that babashka repl in any clojure buffer that doesn't have an explicitly connected REPL https://github.com/lambdaisland/corgi-packages/blob/main/corgi-clojure/corgi-clojure.el#L72-L88
then it's just a matter of doing this in your init.el
(when (executable-find "bb")
(corgi/cider-jack-in-babashka))
(with-current-buffer (get-buffer-create "*scratch-clj*")
(clojure-mode))
What is the advantage of using babashka-baked scratch buffer instead of built-in cider-scratch
?
the point of this *scratch-clj*
is that it's always there, regardless of which cider repl connections do or don't exist. And babashka is fast to start in small in memory footprint making it very convenient for this.
micro quality of life improvement I came up with recently, hope it helps someone else! Prevents quitting Emacs on non-empty scratch buffers. I never want to save a scratch buffer, however if there's stuff there, chances are it has info that I should move elsewhere before quitting
(defun kill-emacs-only-if-scratch-is-empty (f &rest args)
(if (equal ""
(with-current-buffer (get-buffer "*scratch*")
(buffer-string)))
(apply f args)
(message "*scratch* is not empty!")))
(advice-add 'kill-emacs ':around 'kill-emacs-only-if-scratch-is-empty)