diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2019-12-07 17:39:31 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2019-12-07 17:39:31 +0100 |
commit | 4d8423c962e2b4172de48992bcfec965478f928b (patch) | |
tree | def9075bf938101360a834f872f1e131aabfeb3e /indent/vlang.vim | |
parent | e204a7223b4334ed1c556a4564a8048888b69fe8 (diff) | |
download | vim-polyglot-4.1.3.tar.gz vim-polyglot-4.1.3.zip |
Add v language, closes #437v4.1.3
Diffstat (limited to 'indent/vlang.vim')
-rw-r--r-- | indent/vlang.vim | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/indent/vlang.vim b/indent/vlang.vim new file mode 100644 index 00000000..58b441f9 --- /dev/null +++ b/indent/vlang.vim @@ -0,0 +1,69 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'v') == -1 + +" Based on the Go identation file. +" +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nolisp +setlocal autoindent +setlocal indentexpr=VlangIndent(v:lnum) +setlocal indentkeys+=<:>,0=},0=) + +if exists("*VlangIndent") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +function! VlangIndent(lnum) abort + let prevlnum = prevnonblank(a:lnum-1) + if prevlnum == 0 + return 0 + endif + + let prevl = substitute(getline(prevlnum), '//.*$', '', '') + let thisl = substitute(getline(a:lnum), '//.*$', '', '') + let previ = indent(prevlnum) + + let ind = previ + + if prevl =~ '[({]\s*$' + " previous line opened a block + let ind += shiftwidth() + endif + if prevl =~# '^\s*\(case .*\|default\):$' + " previous line is part of a switch statement + let ind += shiftwidth() + endif + + if thisl =~ '^\s*[)}]' + " this line closed a block + let ind -= shiftwidth() + endif + + " Colons are tricky. + " We want to outdent if it's part of a switch ("case foo:" or "default:"). + " We ignore trying to deal with jump labels because (a) they're rare, and + " (b) they're hard to disambiguate from a composite literal key. + if thisl =~# '^\s*\(case .*\|default\):$' + let ind -= shiftwidth() + endif + + return ind +endfunction + +" restore Vi compatibility settings +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: sw=2 ts=2 et + +endif |