clojure-europe 2025-10-14

W Good Morning (👋)

Good morning!

X Good Morning (Ray)

Did you know that Clojure has string interpolation these days?

😂 4

was that not always the case?

It's a joke (with some truth to it) that I stole from @andersmurphy

I think he wasn't cynical but really likes it

when you're not using whitespace in str it does look strangely close like string interpolation, except for the quotes

(str "string "(+ 1 2 3)" interpolation looks good")

works with spaces too

you could say for interpolation use double quotes 😛

lol, yeah I mean not using spaces in between arguments

indeed :) the right mindset :)

unescaped double quotes that is

Hmm, this is pretty awesome, why didn't I think about this sooner.

(defun split-string-at-point ()
  "Split the string at point into two quoted strings, keeping syntax correct."
  (interactive)
  (when (nth 3 (syntax-ppss))  ; are we inside a string?
    (insert "\"\"")
    (backward-char 1)))
Break the string into two parts at cursor, so you can type an expression

This works beautifully with str

Don't most editors have a split s-exp that works on strings already? In Calva it's ctrl+shift+s

ah yes, why is it called split-sexpr?

I see, it works for (...) -> (..)(..) too

(+ 1 2| 3) => (+ 1 2) ( 3)

"Hello, |World!" => "Hello, " "World!"

I mostly use it with strings 🙂

nice, thanks!

I didn't know you could do M+shift+s, to get M-S, you know, my emacs habits are pretty basic but this one will stay in my toolbox!

lol... using an emacs overlay I have something that looks like string templating..

🤣 2

you can try it if you want:

(defun clojure-hide-str-quotes ()
  "Visually hide quotes around Clojure str expressions like (+ 1 2 3)."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    ;; look for a pattern: "something"
    (while (re-search-forward "\"\\(([^)]*)\\)\"" nil t)
      (let ((start (match-beginning 0))
            (end (match-end 0))
            (expr (match-string 1)))
        ;; create overlay
        (let ((ov (make-overlay start end)))
          (overlay-put ov 'display (concat "{" expr "}"))
          (overlay-put ov 'face 'default)
          (overlay-put ov 'evaporate t))))))

it will mess up your editor experience though 😆

e.g. I can't get rid of the code part in the template anymore

(format "url: `\\${window.location.origin}/%s`," schema-name)
to enable JS string interpolation that we ship out from CLJ 🪢

I knew the feature existed but it's hilarious to me that this is the only time I've used it 😅

what feature?

The string templates in JS

ah yeah. I'm currently working on a str version in squint which is likely going to compile down to JS templates

👌🏼 1

Haha, yeah it was mostly a realisation that if you remove the spaces, you are less likely to miss a space (which is what always happened to me when using str) + as you said it basically looks like string interpolation, with automatic syntax highlights etc. I have a similar split string function in emacs. Or to be more precise if I insert a " without a preceding \ in a string it will insert "" and move the cursor into the middle so "|".

Definitely considering stealing the overlay you've come up with. 🤣