Skip to content

Commit c850dd3

Browse files
committed
Fix indent when line contains multi-byte codepoint
1 parent 7de2860 commit c850dd3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cljfmt/src/cljfmt/core.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@
191191
(recur p (cons (start-element (n/tag (z/node p))) worklist))
192192
(apply str worklist)))))
193193

194-
(defn- last-line-in-string [^String s]
194+
(defn- last-line-in-string ^String [^String s]
195195
(subs s (inc (.lastIndexOf s "\n"))))
196196

197197
(defn- margin [zloc]
198-
(-> zloc prior-line-string last-line-in-string count))
198+
(let [last-line (-> zloc prior-line-string last-line-in-string)]
199+
(.codePointCount last-line 0 (.length last-line))))
199200

200201
(defn- whitespace [width]
201202
(n/whitespace-node (apply str (repeat width " "))))

cljfmt/test/cljfmt/core_test.cljc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,3 +2009,20 @@
20092009
["(when 42 ;;;"
20102010
" :a)"]
20112011
{:indent-line-comments? true})))))
2012+
2013+
(deftest test-multibyte-codepoints
2014+
(is (reformats-to?
2015+
["(defn- x"
2016+
" [x style]"
2017+
" (case style"
2018+
" :normal x"
2019+
" :𝕨𝕚𝕝𝕕 (if (sequential? x)"
2020+
" :a"
2021+
" :b)))"]
2022+
["(defn- x"
2023+
" [x style]"
2024+
" (case style"
2025+
" :normal x"
2026+
" :𝕨𝕚𝕝𝕕 (if (sequential? x)"
2027+
" :a"
2028+
" :b)))"])))

0 commit comments

Comments
 (0)