Fork me on GitHub

I am just a silent listener. But I think it is necessary to step out of darkness and to let you know that your work is appreciated a lot. I also think it is a very import step in the right direction to make clojure more accessible for beginners. :thumbsup:

❤️ 8

@lilactown I just found two bugs with the enclosing? function. One is that it doesn’t disregard brackets inside strings, a rather tricky problem to solve, I imagine. So:

(enclosing? "(\"(\")") => false
Another is that it croaks when there is balance at the edges of the range, but unbalance within, but only if it is different kinds of brackets that are balanced/unbalanced. Hmmm, I did not explain that very good… Look at this:
(enclosing? "[)]") => Error: IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Reduced  clojure.lang.RT.seqFrom (

(enclosing? "[]]") => false


I’ll try to see if I can see how the latter can be fixed, but I need to start with adding a workaround for when it happens so that I can send out an intermediate fix asap. If you (or anyone else) have some time to look at it, I would love the help. The string issue is somewhat less urgent, but I would be happy to get ideas on how to tackle it. We have both paredit and that AST, after all…


I have updated the repo with tests that expose the above errors:

Testing calva.fmt.util-test

ERROR in (enclosing?) (Error:NaN:NaN)
expected: (= true (sut/enclosing? "([)"))
  actual: #object[Error Error: [object Object] is not ISeqable]

FAIL in (enclosing?) (cljs-runtime/cljs/test.cljs:475:6)
expected: (= true (sut/enclosing? "(\"(\")"))
  actual: (not (= true false))


That repo is here: , if anyone wants to pack PRs.


Also filed two issues about it. Here’s the one about strings:


@pez have you considered applying for a Clojurists Together grant?


I know that for me such a grant doesn’t make sense, since I have a full time job and the grant isn’t big enough for me to afford taking a leave of absence.


@slipset This has been suggested at times. I am happy people think this project is so important. However, my work situation is such that right now is not a good time for applying.


I could probably afford it, sadly enough. 😃


But I think Clojurists Together would be interested in finding ways to support smaller projects with smaller grants.


I have fixed the enclosing problem with brackets in strings and improved the situation with unbalanced expressions inside enclosing list types (returns false instead of croaking). It’s a bit of a Schrödinger’s fragment anyway, I am not sure if it should answer true or false.


My new enclosing? function looks like so:

(defn enclosing? [text]
  (let [ast (cljify (paredit/parse text))
        children (:children ast)]
    (and (= 1 (count children))
         (= "list" (:type (first children))))))

  (enclosing? "[][]") => false
  (enclosing? "([][])") => true
  (enclosing? "([)") => false
  (enclosing? "[\"[\"]") => true
  (enclosing? "(\"[\")") => true
  (enclosing? "\"foo\"") => false )




Here’s a mystery. Calva Formatter formats the contents of some strings. (It shouldn’t!) I’ve tried with versions from months back and they all do it, so it is nothing new. Here’s an example:

Place the cursor right inside the first paren in the third string and press TAB (assuming default keybindings). It doesn’t happen in the first two strings.


It’s super late here, @marc-omorain, I’ll have a look at that PR tomorrow. 😃 Sounds good to use TS types to get some hold on the responses.


And, yes, I’d love to get that test view in place.