File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 41
41
(nil? (z/up* zloc)))
42
42
43
43
(defn- top? [zloc]
44
- (and zloc ( not= ( z/node zloc) ( z/ root zloc)) ))
44
+ (some-> zloc z/up root? ))
45
45
46
- (defn- top [zloc]
46
+ (defn- root [zloc]
47
47
(if (root? zloc) zloc (recur (z/up zloc))))
48
48
49
49
(defn- clojure-whitespace? [zloc]
50
50
(z/whitespace? zloc))
51
51
52
52
(defn- surrounding-whitespace? [zloc]
53
- (and (top? ( z/up zloc))
53
+ (and (not ( top? zloc))
54
54
(surrounding? zloc clojure-whitespace?)))
55
55
56
56
(defn remove-surrounding-whitespace [form]
220
220
(= 'ns (z/sexpr zloc))))
221
221
222
222
(defn- ns-form? [zloc]
223
- (some-> zloc z/down ns-token?))
223
+ (and (top? zloc)
224
+ (= (z/tag zloc) :list )
225
+ (some-> zloc z/down ns-token?)))
224
226
225
227
(defn- indent-matches? [key sym]
226
228
(if (symbol? sym)
334
336
zloc)))
335
337
336
338
(defn- find-namespace [zloc]
337
- (some-> zloc top (z/find z/next ns-form?) z/down z/next z/sexpr))
339
+ (some-> zloc root (z/find z/next ns-form?) z/down z/next z/sexpr))
338
340
339
341
(defn indent
340
342
([form]
Original file line number Diff line number Diff line change 281
281
" (prn x)))" ]
282
282
{:indents {'thing.core/defrecord [[:inner 0 ]]}
283
283
#?@(:cljs [:alias-map {" t" " thing.core" }])})
284
- " applies custom indentation to namespaced defrecord" ))
284
+ " applies custom indentation to namespaced defrecord" )
285
+ (is (reformats-to?
286
+ [" (let [ns subs]"
287
+ " (ns \" string\" ))"
288
+ " "
289
+ " (ns thing.core)"
290
+ " "
291
+ " (defthing foo [x]"
292
+ " (+ x 1))" ]
293
+ [" (let [ns subs]"
294
+ " (ns \" string\" ))"
295
+ " "
296
+ " (ns thing.core)"
297
+ " "
298
+ " (defthing foo [x]"
299
+ " (+ x 1))" ]
300
+ {:indents {'thing.core/defthing [[:inner 0 ]]
301
+ 'let [[:inner 0 ]]}
302
+ #?@(:cljs [:alias-map {}])})
303
+ " recognises the current namespace as part of a qualifed indent spec, even if preceded by a local var named ns" )
304
+ (is (reformats-to?
305
+ [" (let [ns (range 10)]"
306
+ " (reduce + ns"
307
+ " ))" ]
308
+ [" (let [ns (range 10)]"
309
+ " (reduce + ns))" ]
310
+ " doesn't throw with local vars named ns bound to expressions" )))
285
311
286
312
(testing " function #() syntax"
287
313
(is (reformats-to?
You can’t perform that action at this time.
0 commit comments