7
|
1 " Vim indent file
|
15131
|
2 " Language: C#
|
|
3 " Maintainer: Nick Jensen <nickspoon@gmail.com>
|
|
4 " Former Maintainers: Aquila Deus
|
|
5 " Johannes Zellner <johannes@zellner.org>
|
|
6 " Last Change: 2018-11-21
|
|
7 " Filenames: *.cs
|
|
8 " License: Vim (see :h license)
|
|
9 " Repository: https://github.com/nickspoons/vim-cs
|
|
10 "
|
7
|
11
|
|
12 " Only load this indent file when no other was loaded.
|
15131
|
13 if exists('b:did_indent')
|
|
14 finish
|
7
|
15 endif
|
|
16 let b:did_indent = 1
|
|
17
|
15131
|
18 let s:save_cpo = &cpoptions
|
|
19 set cpoptions&vim
|
|
20
|
|
21
|
|
22 setlocal indentexpr=GetCSIndent(v:lnum)
|
|
23
|
|
24 function! s:IsCompilerDirective(line)
|
|
25 return a:line =~? '^\s*#'
|
|
26 endf
|
|
27
|
|
28 function! s:IsAttributeLine(line)
|
|
29 return a:line =~? '^\s*\[[A-Za-z]' && a:line =~? '\]$'
|
|
30 endf
|
|
31
|
|
32 function! s:FindPreviousNonCompilerDirectiveLine(start_lnum)
|
|
33 for delta in range(0, a:start_lnum)
|
|
34 let lnum = a:start_lnum - delta
|
|
35 let line = getline(lnum)
|
|
36 let is_directive = s:IsCompilerDirective(line)
|
|
37 if !is_directive
|
|
38 return lnum
|
|
39 endif
|
|
40 endfor
|
|
41 return 0
|
|
42 endf
|
233
|
43
|
15131
|
44 function! GetCSIndent(lnum) abort
|
|
45 " Hit the start of the file, use zero indent.
|
|
46 if a:lnum == 0
|
|
47 return 0
|
|
48 endif
|
|
49
|
|
50 let this_line = getline(a:lnum)
|
|
51
|
|
52 " Compiler directives use zero indent if so configured.
|
|
53 let is_first_col_macro = s:IsCompilerDirective(this_line) && stridx(&l:cinkeys, '0#') >= 0
|
|
54 if is_first_col_macro
|
|
55 return cindent(a:lnum)
|
|
56 endif
|
|
57
|
|
58 let lnum = s:FindPreviousNonCompilerDirectiveLine(a:lnum - 1)
|
|
59 let previous_code_line = getline(lnum)
|
|
60 if s:IsAttributeLine(previous_code_line)
|
|
61 let ind = indent(lnum)
|
|
62 return ind
|
|
63 else
|
|
64 return cindent(a:lnum)
|
|
65 endif
|
|
66 endfunction
|
|
67
|
|
68 let b:undo_indent = 'setlocal indentexpr<'
|
|
69
|
|
70 let &cpoptions = s:save_cpo
|
|
71 unlet s:save_cpo
|
|
72
|
|
73 " vim:et:sw=2:sts=2
|