annotate runtime/indent/cs.vim @ 28353:8bc8071928ed v8.2.4702

patch 8.2.4702: C++ scope labels are hard-coded Commit: https://github.com/vim/vim/commit/3506cf34c17c5eae6c2d1317db1fcd5a8493c288 Author: Tom Praschan <13141438+tom-anders@users.noreply.github.com> Date: Thu Apr 7 12:39:08 2022 +0100 patch 8.2.4702: C++ scope labels are hard-coded Problem: C++ scope labels are hard-coded. Solution: Add 'cinscopedecls' to define the labels. (Rom Praschan, closes #10109)
author Bram Moolenaar <Bram@vim.org>
date Thu, 07 Apr 2022 13:45:04 +0200
parents bc1a8d21c811
children c58baa6d6dda
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>
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
6 " Last Change: 2018-11-21
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
7 " Filenames: *.cs
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
8 " License: Vim (see :h license)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
9 " Repository: https://github.com/nickspoons/vim-cs
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
10 "
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Only load this indent file when no other was loaded.
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
13 if exists('b:did_indent')
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
14 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
18 let s:save_cpo = &cpoptions
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
19 set cpoptions&vim
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
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
22 setlocal indentexpr=GetCSIndent(v:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
23
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
24 function! s:IsCompilerDirective(line)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
25 return a:line =~? '^\s*#'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
26 endf
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
27
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
28 function! s:IsAttributeLine(line)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
29 return a:line =~? '^\s*\[[A-Za-z]' && a:line =~? '\]$'
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
30 endf
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
31
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
32 function! s:FindPreviousNonCompilerDirectiveLine(start_lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
33 for delta in range(0, a:start_lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
34 let lnum = a:start_lnum - delta
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
35 let line = getline(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
36 let is_directive = s:IsCompilerDirective(line)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
37 if !is_directive
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
38 return lnum
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
39 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
40 endfor
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
41 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
42 endf
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 7
diff changeset
43
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
44 function! GetCSIndent(lnum) abort
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
45 " Hit the start of the file, use zero indent.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
46 if a:lnum == 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
47 return 0
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
48 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
49
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
50 let this_line = getline(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
51
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
52 " Compiler directives use zero indent if so configured.
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
53 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
54 if is_first_col_macro
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
55 return cindent(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
56 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
57
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
58 let lnum = s:FindPreviousNonCompilerDirectiveLine(a:lnum - 1)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
59 let previous_code_line = getline(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
60 if s:IsAttributeLine(previous_code_line)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
61 let ind = indent(lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
62 return ind
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
63 else
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
64 return cindent(a:lnum)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
65 endif
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
66 endfunction
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
67
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
68 let b:undo_indent = 'setlocal indentexpr<'
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 &cpoptions = s:save_cpo
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
71 unlet s:save_cpo
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
72
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 233
diff changeset
73 " vim:et:sw=2:sts=2