Fork me on GitHub
#emacs
<
2022-04-10
>
Benjamin08:04:47

what I'd like to have is basically a scratch buffer with an attached jvm and cider. Does somebody have a flow for this?

Carlo10:04:21

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.

jumar11:04:30

There's cider-scratch or something like that

Benjamin11:04:05

true cider ships cider-scratch

apt13:04:49

If you don’t need a jvm, you could use a bb project

plexus07:04:25

I have a permanent *sratch-clj* buffer backed by babashka, it's great

plexus07:04:53

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

plexus07:04:41

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

plexus07:04:18

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))

jumar09:04:50

What is the advantage of using babashka-baked scratch buffer instead of built-in cider-scratch?

plexus09:04:04

no need to start a JVM?

plexus09:04:51

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.

jumar09:04:43

I see - I guess I don't usually have such a need 🙂

vemv16:04:00

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)

thanks 3