@@ -73,24 +73,40 @@ call s:SConf('clojure_indent_rules', {
73
73
" Returns "1" if position "i_char" in "line_str" is preceded by an odd number
74
74
" of backslash characters (i.e. escaped).
75
75
function ! s: IsEscaped (line_str, i_char)
76
- return ! strlen (trim (a: line_str [: a: i_char - 1 ], ' \' , 2 )) % 2
76
+ let ln = a:line_str[: a:i_char - 1]
77
+ return (strlen (ln ) - strlen(trim(ln, '\', 2))) % 2
78
+ endfunction
79
+
80
+ " Variation of "s:IsEscaped" which can be used within "search(pair)pos".
81
+ function ! s: SkipIfEscaped ()
82
+ let pos = getcursorcharpos ()
83
+ return s: IsEscaped (getline (pos[1 ]), pos[2 ] - 1 )
77
84
endfunction
78
85
79
86
" Used during list function indentation. Returns the position of the first
80
87
" operand in the list on the first line of the form at "pos".
81
88
function ! s: FirstFnArgPos (pos)
82
- " TODO: ignore comments and handle escaped characters!
83
- let lnr = a: pos [0 ]
84
- let s: in_form_current_form = a: pos
85
- call cursor (lnr , a: pos [1 ] + 1 )
86
- return searchpos (' \m[ ,]\+\zs' , ' z' , lnr , 0 , function (' <SID>IsSubForm' ))
87
- endfunction
89
+ let [lnr , base_idx] = a: pos
90
+ let ln = getline(lnr)
91
+ call cursor ([lnr , base_idx + 1 ])
92
+
93
+ if ln [base_idx] =~# '["\\,[:space:]]' | return [0, 0] | endif
94
+
95
+ " Find first collection delimiter or char preceeding whitespace.
96
+ let pos = searchpos (' \([{\[(]\|.[[:space:],]\)' , ' cWz' , lnr )
97
+ if pos == [0 , 0 ] | return pos | endif
98
+
99
+ " If at collection delimiter, jump to end delimiter.
100
+ let ch = ln [pos[1] - 1]
101
+ if has_key (s: pairs , ch )
102
+ let pos = searchpairpos (' \V' . ch , ' ' , ' \V' . get (s: pairs , ch ), ' Wz' , function (' s:SkipIfEscaped' ), lnr )
103
+ " If end not on same line: no arg.
104
+ if pos == [0 , 0 ] | return pos | endif
105
+ endif
88
106
89
- " Used by "s:FirstFnArgPos" function to skip over subforms as the first value
90
- " in a list form.
91
- function ! s: IsSubForm ()
92
- let pos = searchpairpos (' \m[([{"]' , ' ' , ' \m[)\]}"]' , ' b' )
93
- return pos != [0 , 0 ] && pos != s: in_form_current_form
107
+ " Search forwards for first non-whitespace/comment char on line.
108
+ let pos = searchpos (' [^[:space:],]' , ' Wz' , lnr )
109
+ return ln [pos[1] - 1] ==# ';' ? [0, 0] : pos
94
110
endfunction
95
111
96
112
" Converts a cursor position into a characterwise cursor column position (to
0 commit comments