Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d177b3b

Browse files
committed
Move string indent picker to a separate function
1 parent d73e408 commit d177b3b

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

‎indent/clojure.vim

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ function! s:ShouldAlignMultiLineStrings()
5353
return s:Conf('clojure_align_multiline_strings', 0)
5454
endfunction
5555

56+
function! s:GetStringIndent(delim_pos, regex)
57+
" Mimic multi-line string indentation behaviour in VS Code and Emacs.
58+
let m = mode()
59+
if m ==# 'i' || (m ==# 'n' && ! (v:operator ==# '=' && state('o') ==# 'o'))
60+
" If in insert mode, or (in normal mode and last operator is
61+
" not "=" and is not currently active.
62+
let rule = s:ShouldAlignMultiLineStrings()
63+
if rule == -1
64+
return 0 " No indent.
65+
elseif rule == 1
66+
" Align with start of delimiter.
67+
return a:delim_pos[1]
68+
else
69+
" Align with end of delimiter.
70+
return a:delim_pos[1] - (a:regex ? 2 : 1)
71+
endif
72+
else
73+
return -1 " Keep existing indent.
74+
endif
75+
endfunction
76+
5677
" Wrapper around "searchpairpos" that will automatically set "s:best_match" to
5778
" the closest pair match and optimises the "stopline" value for later
5879
" searches. This results in a significant performance gain by reducing the
@@ -104,25 +125,12 @@ function! s:GetClojureIndent()
104125
elseif formtype ==# 'vec' || formtype ==# 'map'
105126
" Inside a vector, map or set.
106127
return coord[1]
107-
elseif formtype ==# 'str' || formtype ==# 'reg'
108-
" Mimic multi-line string indentation behaviour in VS Code and
109-
" Emacs.
110-
let m = mode()
111-
if m ==# 'i' || (m ==# 'n' && ! (v:operator ==# '=' && state() =~# 'o'))
112-
" If in insert mode, or (in normal mode and last
113-
" operator is not "=" and is not currently active.
114-
let rule = s:ShouldAlignMultiLineStrings()
115-
if rule == -1
116-
" No indent.
117-
return 0
118-
elseif rule == 1
119-
" Align with start of delimiter.
120-
return coord[1]
121-
else
122-
" Align with end of delimiter.
123-
return coord[1] - (formtype ==# 'reg' ? 2 : 1)
124-
endif
125-
endif
128+
elseif formtype ==# 'str'
129+
" Inside a string.
130+
return s:GetStringIndent(coord, 0)
131+
elseif formtype ==# 'reg'
132+
" Inside a regular expression.
133+
return s:GetStringIndent(coord, 1)
126134
endif
127135

128136
" Keep existing indent.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /