Skip to content

Commit 51f5dcb

Browse files
committed
More indentation code clean up and readability improvements
1 parent 342f35f commit 51f5dcb

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

Diff for: indent/clojure.vim

+17-32
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ function! s:GetStringIndent(delim_pos, regex)
5656
let m = mode()
5757
if m ==# 'i' || (m ==# 'n' && ! s:EqualsOperatorInEffect())
5858
" If in insert mode, or normal mode but "=" is not in effect.
59-
let rule = s:Conf('clojure_align_multiline_strings', 0)
60-
if rule == -1
61-
" Indent along left edge, like traditional Lisps.
62-
return 0
63-
elseif rule == 1
64-
" Indent in alignment with end of the string start delimiter.
65-
return a:delim_pos[1]
66-
else
67-
" Indent in alignment with string start delimiter.
68-
return a:delim_pos[1] - (a:regex ? 2 : 1)
59+
let alignment = s:Conf('clojure_align_multiline_strings', 0)
60+
" -1: Indent along left edge, like traditional Lisps.
61+
" 0: Indent in alignment with end of the string start delimiter.
62+
" 1: Indent in alignment with string start delimiter.
63+
if alignment == -1 | return 0
64+
elseif alignment == 1 | return a:delim_pos[1]
65+
else | return a:delim_pos[1] - (a:regex ? 2 : 1)
6966
endif
7067
else
7168
return -1 " Keep existing indent.
@@ -131,10 +128,10 @@ function! s:GetClojureIndent()
131128
if synname =~? 'string'
132129
" We already checked this above, so pass through this block.
133130
elseif synname =~? 'regex'
134-
call s:CheckPair('reg', '#\zs"', '"', function('<SID>NotRegexpDelimiter'))
131+
call s:CheckPair('rex', '#\zs"', '"', function('<SID>NotRegexpDelimiter'))
135132
else
136133
let IgnoredRegionFn = function('<SID>IgnoredRegion')
137-
if bufname() ==? '\.edn$'
134+
if bufname() =~? '\.edn$'
138135
" If EDN file, check list pair last.
139136
call s:CheckPair('map', '{', '}', IgnoredRegionFn)
140137
call s:CheckPair('vec', '\[', '\]', IgnoredRegionFn)
@@ -147,27 +144,15 @@ function! s:GetClojureIndent()
147144
endif
148145
endif
149146

150-
" Find closest matching higher form.
147+
" Calculate and return indent to use based on the matching form.
151148
let [formtype, coord] = s:best_match
152-
153-
if formtype ==# 'top'
154-
" At the top level, no indent.
155-
return 0
156-
elseif formtype ==# 'lst'
157-
" Inside a list.
158-
return s:GetListIndent(coord)
159-
elseif formtype ==# 'vec' || formtype ==# 'map'
160-
" Inside a vector, map or set.
161-
return coord[1]
162-
elseif formtype ==# 'str'
163-
" Inside a string.
164-
return s:GetStringIndent(coord, 0)
165-
elseif formtype ==# 'reg'
166-
" Inside a regular expression.
167-
return s:GetStringIndent(coord, 1)
168-
else
169-
" Keep existing indent.
170-
return -1
149+
if formtype ==# 'top' | return 0 " At top level, no indent.
150+
elseif formtype ==# 'lst' | return s:GetListIndent(coord)
151+
elseif formtype ==# 'vec' | return coord[1] " Vector
152+
elseif formtype ==# 'map' | return coord[1] " Map/set
153+
elseif formtype ==# 'str' | return s:GetStringIndent(coord, 0)
154+
elseif formtype ==# 'rex' | return s:GetStringIndent(coord, 1)
155+
else | return -1 " Keep existing indent.
171156
endif
172157
endfunction
173158

0 commit comments

Comments
 (0)