diff options
Diffstat (limited to 'indent')
-rw-r--r-- | indent/dune.vim | 14 | ||||
-rw-r--r-- | indent/rust.vim | 66 | ||||
-rw-r--r-- | indent/scala.vim | 9 | ||||
-rw-r--r-- | indent/terraform.vim | 21 |
4 files changed, 91 insertions, 19 deletions
diff --git a/indent/dune.vim b/indent/dune.vim new file mode 100644 index 00000000..3f8e7e87 --- /dev/null +++ b/indent/dune.vim @@ -0,0 +1,14 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'ocaml') != -1 + finish +endif + +" Vim indent file +" Language: dune + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" dune format-dune-file uses 1 space to indent +set softtabstop=1 shiftwidth=1 expandtab diff --git a/indent/rust.vim b/indent/rust.vim index 5c43d2e2..ee7f6cf6 100644 --- a/indent/rust.vim +++ b/indent/rust.vim @@ -85,8 +85,17 @@ function! s:is_string_comment(lnum, col) endif endfunction -function GetRustIndent(lnum) +if exists('*shiftwidth') + function! s:shiftwidth() + return shiftwidth() + endfunc +else + function! s:shiftwidth() + return &shiftwidth + endfunc +endif +function GetRustIndent(lnum) " Starting assumption: cindent (called at the end) will do it right " normally. We just want to fix up a few cases. @@ -132,14 +141,65 @@ function GetRustIndent(lnum) let prevline = s:get_line_trimmed(prevlinenum) endwhile + " A standalone '{', '}', or 'where' + let l:standalone_open = line =~# '\V\^\s\*{\s\*\$' + let l:standalone_close = line =~# '\V\^\s\*}\s\*\$' + let l:standalone_where = line =~# '\V\^\s\*where\s\*\$' + if l:standalone_open || l:standalone_close || l:standalone_where + " ToDo: we can search for more items than 'fn' and 'if'. + let [l:found_line, l:col, l:submatch] = + \ searchpos('\<\(fn\)\|\(if\)\>', 'bnWp') + if l:found_line !=# 0 + " Now we count the number of '{' and '}' in between the match + " locations and the current line (there is probably a better + " way to compute this). + let l:i = l:found_line + let l:search_line = strpart(getline(l:i), l:col - 1) + let l:opens = 0 + let l:closes = 0 + while l:i < a:lnum + let l:search_line2 = substitute(l:search_line, '\V{', '', 'g') + let l:opens += strlen(l:search_line) - strlen(l:search_line2) + let l:search_line3 = substitute(l:search_line2, '\V}', '', 'g') + let l:closes += strlen(l:search_line2) - strlen(l:search_line3) + let l:i += 1 + let l:search_line = getline(l:i) + endwhile + if l:standalone_open || l:standalone_where + if l:opens ==# l:closes + return indent(l:found_line) + endif + else + " Expect to find just one more close than an open + if l:opens ==# l:closes + 1 + return indent(l:found_line) + endif + endif + endif + endif + + " A standalone 'where' adds a shift. + let l:standalone_prevline_where = prevline =~# '\V\^\s\*where\s\*\$' + if l:standalone_prevline_where + return indent(prevlinenum) + 4 + endif + " Handle where clauses nicely: subsequent values should line up nicely. if prevline[len(prevline) - 1] ==# "," \ && prevline =~# '^\s*where\s' return indent(prevlinenum) + 6 endif - if prevline[len(prevline) - 1] ==# "," - \ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{}]' + let l:last_prevline_character = prevline[len(prevline) - 1] + + " A line that ends with '.<expr>;' is probably an end of a long list + " of method operations. + if prevline =~# '\V\^\s\*.' && l:last_prevline_character ==# ';' + return indent(prevlinenum) - s:shiftwidth() + endif + + if l:last_prevline_character ==# "," + \ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{})]' \ && prevline !~# '^\s*fn\s' \ && prevline !~# '([^()]\+,$' \ && s:get_line_trimmed(a:lnum) !~# '^\s*\S\+\s*=>' diff --git a/indent/scala.vim b/indent/scala.vim index db52cf90..2fcb3378 100644 --- a/indent/scala.vim +++ b/indent/scala.vim @@ -21,7 +21,10 @@ if exists("*GetScalaIndent") finish endif -let s:defMatcher = '\%(\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\)*\<def\>' +let s:annotationMatcher = '@[A-Za-z._]\+\s\+' +let s:modifierMatcher = s:annotationMatcher . '\|\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\|final\s\+' +let s:defMatcher = '\%(' . s:modifierMatcher . '\)*\<def\>' +let s:valMatcher = '\%(' . s:modifierMatcher . '\|lazy\s\+\)*\<va[lr]\>' let s:funcNameMatcher = '\w\+' let s:typeSpecMatcher = '\%(\s*\[\_[^\]]*\]\)' let s:defArgMatcher = '\%((\_.\{-})\)' @@ -185,7 +188,7 @@ function! scala#NumberOfBraceGroups(line) endfunction function! scala#MatchesIncompleteDefValr(line) - if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*[=({]\s*$' + if a:line =~ '^\s*\%(' . s:defMatcher . '\|' . s:valMatcher . '\).*[=({]\s*$' return 1 else return 0 @@ -435,7 +438,7 @@ function! GetScalaIndent() " If 'val', 'var', 'def' end with =, this is a one-line block if (prevline =~ '^\s*\<\%(\%(}\?\s*else\s\+\)\?if\|for\|while\)\>.*[)=]\s*$' && scala#NumberOfBraceGroups(prevline) <= 1) \ || prevline =~ '^\s*' . s:defMatcher . '.*=\s*$' - \ || prevline =~ '^\s*\<va[lr]\>.*[=]\s*$' + \ || prevline =~ '^\s*' . s:valMatcher . '.*[=]\s*$' \ || prevline =~ '^\s*\%(}\s*\)\?\<else\>\s*$' \ || prevline =~ '=\s*$' call scala#ConditionalConfirm("4") diff --git a/indent/terraform.vim b/indent/terraform.vim index 2a0e5799..74b7808a 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -34,24 +34,19 @@ function! TerraformIndent(lnum) return 0 endif - " Previous non-blank line should continue the indent level + " Usual case is to continue at the same indent as the previous non-blank line. let prevlnum = prevnonblank(a:lnum-1) + let thisindent = indent(prevlnum) - " Previous line without comments should continue the indent level - let prevline = substitute(getline(prevlnum), '//.*$', '', '') - let previndent = indent(prevlnum) - let thisindent = previndent - - " Config block starting with [ { ( should increase the indent level - if prevline =~# '[\[{\(]\s*$' + " If that previous line is a non-comment ending in [ { (, increase the + " indent level. + let prevline = getline(prevlnum) + if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$' let thisindent += &shiftwidth endif - " Current line without comments should continue the indent level - let thisline = substitute(getline(a:lnum), '//.*$', '', '') - - " Config block ending with ) } ] should get the indentation - " level from the initial config block + " If the current line ends a block, decrease the indent level. + let thisline = getline(a:lnum) if thisline =~# '^\s*[\)}\]]' let thisindent -= &shiftwidth endif |