File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 287287(defn- stair-indent
288288 " Calculate how many spaces the node at this location should be indented as a
289289 conditional block. Returns nil if the rule does not apply."
290- [zloc rule-key idx]
290+ [zloc rule-key idx list-indent-size ]
291291 (when (indent-matches? rule-key (zl/form-symbol-full zloc))
292292 (let [zloc-idx (index-of zloc)
293293 leading-forms (if (some-> zloc (nth-form idx) first-form-in-line?)
294294 0
295295 idx)
296- indent (inner-indent zloc rule-key 0 nil )]
296+ indent (if (zero? idx)
297+ (block-indent zloc rule-key idx list-indent-size (inc idx))
298+ (inner-indent zloc rule-key 0 nil ))]
297299 (if (even? (- zloc-idx leading-forms))
298300 (+ indent indent-size)
299301 indent))))
322324 (let [[_ idx] rule]
323325 (fn stair-indenter
324326 [zloc]
325- (stair-indent zloc rule-key idx)))))
327+ (stair-indent zloc rule-key idx list-indent-size )))))
326328
327329
328330(defn- unindent-line
Original file line number Diff line number Diff line change 6161 " (assoc {}\n :foo bar\n :foo2 bar2)" ))))
6262
6363
64+ (defn space
65+ " A string with n spaces"
66+ [n]
67+ (apply str (repeat n " " )))
68+
69+
6470(deftest stair-indentation
6571 (let [indents {'cond [[:stair 0 ]]
6672 'condp [[:stair 2 ]]
7076 indent/reindent-lines {:indents indents}
7177 " (cond\n a? a\n b? b)"
7278 " (cond\n a? a\n b? b)" ))
79+ (is (rule-reformatted?
80+ indent/reindent-lines {:indents indents}
81+ " (cond a? a\n b? b)"
82+ (str " (cond a? a\n " (space 6 ) " b? b)" )))
83+ (is (rule-reformatted?
84+ indent/reindent-lines {:indents indents}
85+ " (cond a?\n a\n b?\n b)"
86+ (str " (cond a?\n " (space 8 ) " a\n " (space 6 ) " b?\n " (space 8 ) " b)" )))
7387 (is (rule-reformatted?
7488 indent/reindent-lines {:indents indents}
7589 " (cond\n a?\n a\n b?\n b)"
You can’t perform that action at this time.
0 commit comments