Skip to content

Commit 342f35f

Browse files
committed
Initial work on list indentation
Still lots to do here, this is just the initial work.
1 parent 242dc9d commit 342f35f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: indent/clojure.vim

+15-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function! s:SyntaxMatch(pattern, line, col)
3030
endfunction
3131

3232
function! s:IgnoredRegion()
33-
return s:SyntaxMatch('\(string\|regex\|comment\|character\)', line('.'), col('.'))
33+
return s:SyntaxMatch('\%(string\|regex\|comment\|character\)', line('.'), col('.'))
3434
endfunction
3535

3636
function! s:NotStringDelimiter()
@@ -72,6 +72,19 @@ function! s:GetStringIndent(delim_pos, regex)
7272
endif
7373
endfunction
7474

75+
function! s:GetListIndent(delim_pos)
76+
" TODO Begin analysis and apply rules!
77+
let ln1 = getline(delim_pos[0])
78+
let sym = get(split(ln1[delim_pos[1]:], '[[:space:],;()\[\]{}@\\"^~`]', 1), 0, -1)
79+
if sym != -1 && ! empty(sym) && match(sym, '^[0-9:]') == -1
80+
" TODO: align indentation.
81+
return delim_pos[1] + 1 " 2 space indentation
82+
endif
83+
84+
" TODO: switch between 1 vs 2 space indentation.
85+
return delim_pos[1] " 1 space indentation
86+
endfunction
87+
7588
" Wrapper around "searchpairpos" that will automatically set "s:best_match" to
7689
" the closest pair match and optimises the "stopline" value for later
7790
" searches. This results in a significant performance gain by reducing the
@@ -142,9 +155,7 @@ function! s:GetClojureIndent()
142155
return 0
143156
elseif formtype ==# 'lst'
144157
" Inside a list.
145-
" TODO Begin analysis and apply rules!
146-
" echom getline(coord[0], v:lnum - 1)
147-
return coord[1] + 1
158+
return s:GetListIndent(coord)
148159
elseif formtype ==# 'vec' || formtype ==# 'map'
149160
" Inside a vector, map or set.
150161
return coord[1]

0 commit comments

Comments
 (0)