@@ -81,6 +81,11 @@ function! s:IsEscaped(line_str, i_char)
8181 return (strlen (ln ) - strlen(trim(ln, '\', 2))) % 2
8282endfunction
8383
84+ function ! s: PosToCharPos (pos)
85+ call cursor (a: pos )
86+ return getcursorcharpos ()[1 :2 ]
87+ endfunction
88+
8489" Repeatedly search for indentation significant Clojure tokens on a given line
8590" (in reverse order) building up a list of tokens and their positions.
8691" Ignores escaped tokens. Does not care about strings, which is handled by
@@ -195,11 +200,11 @@ function! s:StringIndent(delim_pos)
195200 " 0: Indent in alignment with end of the string start delimiter.
196201 " 1: Indent in alignment with string start delimiter.
197202 if alignment == -1 | return 0
198- elseif alignment == 1 | return a: delim_pos [1 ]
203+ elseif alignment == 1 | return s: PosToCharPos ( a: delim_pos) [1 ]
199204 else
200205 let col = a: delim_pos [1 ]
201206 let is_regex = col > 1 && getline (a: delim_pos [0 ])[col - 2 ] == # ' #'
202- return col - (is_regex ? 2 : 1 )
207+ return s: PosToCharPos ( a: delim_pos )[ 1 ] - (is_regex ? 2 : 1 )
203208 endif
204209 else
205210 return -1 " Keep existing indent.
@@ -210,15 +215,15 @@ function! s:ListIndent(delim_pos)
210215 " TODO: extend "s:InsideForm" to provide information about the
211216 " subforms being formatted to avoid second parsing step.
212217
213- call cursor (a: delim_pos )
218+ let base_indent = s: PosToCharPos (a: delim_pos )[ 1 ]
214219 let ln = getline(a:delim_pos[0])
215- let base_indent = a: delim_pos [1 ]
220+ let delim_col = a: delim_pos [1 ]
216221
217222 " 1. Macro/rule indentation
218223 " if starts with a symbol, extract it.
219224 " - Split namespace off symbol and #'/' syntax.
220225 " - Check against pattern rules and apply indent on match.
221- " - TODO: Look up in rules table and apply indent on match.
226+ " - Look up in rules table and apply indent on match.
222227 " else, not found, go to 2.
223228 "
224229 " TODO: handle complex indentation (e.g. letfn) and introduce
@@ -227,7 +232,7 @@ function! s:ListIndent(delim_pos)
227232 " other indentation options.
228233 "
229234 " TODO: replace `clojure_fuzzy_indent_patterns` with `clojure_indent_patterns`
230- let syms = split (ln [base_indent :], '[[:space:],;()\[\]{}@\\"^~`]', 1)
235+ let syms = split (ln [delim_col :], '[[:space:],;()\[\]{}@\\"^~`]', 1)
231236 if ! empty (syms)
232237 let sym = syms[0 ]
233238 " TODO: strip #' and ' from front of symbol.
@@ -258,11 +263,11 @@ function! s:ListIndent(delim_pos)
258263 " - Indent 1 or 2 spaces.
259264 let indent_style = s: Conf (' clojure_indent_style' , ' always-align' )
260265 if indent_style !=# ' always-indent'
261- let init_col = a: delim_pos [ 1 ] + 1
266+ let init_col = delim_col + 1
262267 call cursor (a: delim_pos [0 ], init_col)
263268
264269 " TODO: replace cursor translation with searching?
265- let ch = ln [base_indent ]
270+ let ch = ln [delim_col ]
266271 if ch == # ' (' || ch == # ' [' || ch == # ' {'
267272 normal ! % w
268273 elseif ch !=# ' ;' && ch !=# ' "'
@@ -286,8 +291,8 @@ function! s:ClojureIndent()
286291 let [form, pos] = s: InsideForm (v: lnum )
287292 if form == # ' ^' | return 0 " At top-level, no indent.
288293 elseif form == # ' (' | return s: ListIndent (pos)
289- elseif form == # ' [' | return pos[1 ]
290- elseif form == # ' {' | return pos[1 ]
294+ elseif form == # ' [' | return s: PosToCharPos ( pos) [1 ]
295+ elseif form == # ' {' | return s: PosToCharPos ( pos) [1 ]
291296 elseif form == # ' "' | return s: StringIndent (pos)
292297 else | return -1 " Keep existing indent.
293298 endif
0 commit comments