77" License: Vim (see :h license)
88" Repository: https://github.com/clojure-vim/clojure.vim
99
10- if exists (" b:did_indent" )
11- finish
12- endif
10+ if exists (" b:did_indent" ) | finish | endif
1311let b: did_indent = 1
1412
1513let s: save_cpo = &cpoptions
@@ -99,11 +97,11 @@ function! s:IsSubForm()
9997 return pos != [0 , 0 ] && pos != s: in_form_current_form
10098endfunction
10199
102- " Converts a cursor position into a characterwise cursor position (to handle
103- " multibyte characters).
104- function ! s: PosToCharPos (pos)
100+ " Converts a cursor position into a characterwise cursor column position (to
101+ " handle multibyte characters).
102+ function ! s: PosToCharCol (pos)
105103 call cursor (a: pos )
106- return getcursorcharpos ()[1 : 2 ]
104+ return getcursorcharpos ()[2 ]
107105endfunction
108106
109107" Repeatedly search for indentation significant Clojure tokens on a given line
@@ -230,11 +228,11 @@ function! s:StringIndent(delim_pos)
230228 " 0: Indent in alignment with end of the string start delimiter.
231229 " 1: Indent in alignment with string start delimiter.
232230 if alignment == -1 | return 0
233- elseif alignment == 1 | return s: PosToCharPos (a: delim_pos )[ 1 ]
231+ elseif alignment == 1 | return s: PosToCharCol (a: delim_pos )
234232 else
235233 let col = a: delim_pos [1 ]
236234 let is_regex = col > 1 && getline (a: delim_pos [0 ])[col - 2 ] == # ' #'
237- return s: PosToCharPos (a: delim_pos )[ 1 ] - (is_regex ? 2 : 1 )
235+ return s: PosToCharCol (a: delim_pos ) - (is_regex ? 2 : 1 )
238236 endif
239237 else
240238 return -1 " Keep existing indent.
@@ -245,7 +243,7 @@ function! s:ListIndent(delim_pos)
245243 " TODO: extend "s:InsideForm" to provide information about the
246244 " subforms being formatted to avoid second parsing step.
247245
248- let base_indent = s: PosToCharPos (a: delim_pos )[ 1 ]
246+ let base_indent = s: PosToCharCol (a: delim_pos )
249247 let ln = getline(a:delim_pos[0])
250248
251249 let sym_match = -1
@@ -294,7 +292,7 @@ function! s:ListIndent(delim_pos)
294292 let indent_style = s: Conf (' clojure_indent_style' , ' always-align' )
295293 if indent_style !=# ' always-indent'
296294 let pos = s: FirstFnArgPos (a: delim_pos )
297- if pos != [0 , 0 ] | return s: PosToCharPos (pos)[ 1 ] - 1 | endif
295+ if pos != [0 , 0 ] | return s: PosToCharCol (pos) - 1 | endif
298296 endif
299297
300298 " Fallback indentation for operands. When "clojure_indent_style" is
@@ -309,8 +307,8 @@ function! s:ClojureIndent()
309307 let [form, pos] = s: InsideForm (v: lnum )
310308 if form == # ' ^' | return 0 " At top-level, no indent.
311309 elseif form == # ' (' | return s: ListIndent (pos)
312- elseif form == # ' [' | return s: PosToCharPos (pos)[ 1 ]
313- elseif form == # ' {' | return s: PosToCharPos (pos)[ 1 ]
310+ elseif form == # ' [' | return s: PosToCharCol (pos)
311+ elseif form == # ' {' | return s: PosToCharCol (pos)
314312 elseif form == # ' "' | return s: StringIndent (pos)
315313 else | return -1 " Keep existing indent.
316314 endif
0 commit comments