annotate runtime/indent/cs.vim @ 29533:34c1f4cd0c18

Update runtime files Commit: https://github.com/vim/vim/commit/2ecbe53f452e92e941aff623f6a0b72f80e43d07 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 29 21:36:21 2022 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Fri, 29 Jul 2022 22:45:04 +0200
parents c58baa6d6dda
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
2 " Language: C#
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
3 " Maintainer: Nick Jensen <nickspoon@gmail.com>
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
4 " Former Maintainers: Aquila Deus
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
5 " Johannes Zellner <johannes@zellner.org>
29104
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
6 " Last Change: 2020-03-26
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
7 " License: Vim (see :h license)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
8 " Repository: https://github.com/nickspoons/vim-cs
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
10 if exists('b:did_indent')
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
11 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
15 let s:save_cpo = &cpoptions
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
16 set cpoptions&vim
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
17
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
18
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
19 setlocal indentexpr=GetCSIndent(v:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
20
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
21 function! s:IsCompilerDirective(line)
29104
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
22 " Exclude #region and #endregion - these should be indented normally
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
23 return a:line =~# '^\s*#' && !s:IsRegionDirective(a:line)
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
24 endf
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
25
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
26 function! s:IsRegionDirective(line)
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
27 return a:line =~# '^\s*#\s*region' || a:line =~# '^\s*#\s*endregion'
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
28 endf
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
29
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
30 function! s:IsAttributeLine(line)
29104
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
31 return a:line =~# '^\s*\[[A-Za-z]' && a:line =~# '\]$'
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
32 endf
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
33
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
34 function! s:FindPreviousNonCompilerDirectiveLine(start_lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
35 for delta in range(0, a:start_lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
36 let lnum = a:start_lnum - delta
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
37 let line = getline(lnum)
29104
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
38 if !s:IsCompilerDirective(line) && !s:IsRegionDirective(line)
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
39 return lnum
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
40 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
41 endfor
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
42 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
43 endf
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 7
diff changeset
44
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
45 function! GetCSIndent(lnum) abort
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
46 " Hit the start of the file, use zero indent.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
47 if a:lnum == 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
48 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
49 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
50
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
51 let this_line = getline(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
52
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
53 " Compiler directives use zero indent if so configured.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
54 let is_first_col_macro = s:IsCompilerDirective(this_line) && stridx(&l:cinkeys, '0#') >= 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
55 if is_first_col_macro
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
56 return cindent(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
57 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
58
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
59 let lnum = s:FindPreviousNonCompilerDirectiveLine(a:lnum - 1)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
60 let previous_code_line = getline(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
61 if s:IsAttributeLine(previous_code_line)
29104
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
62 return indent(lnum)
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
63 elseif s:IsRegionDirective(this_line)
c58baa6d6dda Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
64 return cindent(lnum)
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
65 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
66 return cindent(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
67 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
68 endfunction
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
69
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
70 let b:undo_indent = 'setlocal indentexpr<'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
71
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
72 let &cpoptions = s:save_cpo
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
73 unlet s:save_cpo
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
74
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
75 " vim:et:sw=2:sts=2