Skip to content

Commit 8279a89

Browse files
committed
Yet more string detection fixes and slight code clean up
1 parent e573da7 commit 8279a89

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

indent/clojure.vim

+22-21
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,25 @@ function! s:Conf(opt, default)
4545
return get(b:, a:opt, get(g:, a:opt, a:default))
4646
endfunction
4747

48-
function! s:ShouldAlignMultiLineStrings()
49-
" Possible Values: (default is 0)
50-
" -1: Indent of 0, along left edge, like traditional Lisps.
51-
" 0: Indent in alignment with string start delimiter.
52-
" 1: Indent in alignment with end of the string start delimiter.
53-
return s:Conf('clojure_align_multiline_strings', 0)
48+
function! s:EqualsOperatorInEffect()
49+
return v:operator ==# '=' && state('o') ==# 'o'
5450
endfunction
5551

5652
function! s:GetStringIndent(delim_pos, regex)
5753
" Mimic multi-line string indentation behaviour in VS Code and Emacs.
5854
let m = mode()
59-
if m ==# 'i' || (m ==# 'n' && ! (v:operator ==# '=' && state('o') ==# 'o'))
55+
if m ==# 'i' || (m ==# 'n' && ! s:EqualsOperatorInEffect())
6056
" If in insert mode, or (in normal mode and last operator is
6157
" not "=" and is not currently active.
62-
let rule = s:ShouldAlignMultiLineStrings()
58+
let rule = s:Conf('clojure_align_multiline_strings', 0)
6359
if rule == -1
64-
return 0 " No indent.
60+
" Indent along left edge, like traditional Lisps.
61+
return 0
6562
elseif rule == 1
66-
" Align with start of delimiter.
63+
" Indent in alignment with end of the string start delimiter.
6764
return a:delim_pos[1]
6865
else
69-
" Align with end of delimiter.
66+
" Indent in alignment with string start delimiter.
7067
return a:delim_pos[1] - (a:regex ? 2 : 1)
7168
endif
7269
else
@@ -86,27 +83,31 @@ function! s:CheckPair(name, start, end, SkipFn)
8683
endif
8784
endfunction
8885

89-
function! s:GetClojureIndent()
90-
" Move cursor to the first column of the line we want to indent.
91-
call cursor(v:lnum, 1)
92-
93-
if empty(getline(v:lnum))
86+
function! s:GetCurrentSynName(lnum)
87+
if empty(getline(a:lnum))
9488
" Improves the accuracy of string detection when a newline is
9589
" entered while in insert mode.
96-
let strline = v:lnum - 1
97-
let synname = s:GetSynIdName(strline, strlen(getline(strline)))
90+
let strline = a:lnum - 1
91+
return s:GetSynIdName(strline, strlen(getline(strline)))
9892
else
99-
let synname = s:GetSynIdName(v:lnum, 1)
93+
return s:GetSynIdName(a:lnum, 1)
10094
endif
95+
endfunction
96+
97+
function! s:GetClojureIndent()
98+
" Move cursor to the first column of the line we want to indent.
99+
call cursor(v:lnum, 1)
100+
101+
let synname = s:GetCurrentSynName(v:lnum)
101102

102103
let s:best_match = ['top', [0, 0]]
103104

104105
if synname =~? 'string'
106+
call s:CheckPair('str', '"', '"', function('<SID>NotStringDelimiter'))
105107
" Sometimes, string highlighting does not kick in correctly,
106108
" until after this first "s:CheckPair" call, so we have to
107109
" detect and attempt an automatic correction.
108-
call s:CheckPair('str', '"', '"', function('<SID>NotStringDelimiter'))
109-
let new_synname = s:GetSynIdName(v:lnum, 1)
110+
let new_synname = s:GetCurrentSynName(v:lnum)
110111
if new_synname !=# synname
111112
echoerr 'Misdetected string! Retrying...'
112113
let s:best_match = ['top', [0, 0]]

0 commit comments

Comments
 (0)