annotate runtime/indent/ld.vim @ 13679:7989c11f96d2

Added tag v8.0.1711 for changeset 39fcaaa973dbd18bc74aebb1c69b31219e757fe9
author Christian Brabandt <cb@256bit.org>
date Sat, 14 Apr 2018 17:15:06 +0200
parents d0a20101ecb2
children 9c221ad9634a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
1 " Vim indent file
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 1221
diff changeset
2 " Language: ld(1) script
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 1221
diff changeset
3 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 1221
diff changeset
4 " Latest Revision: 2006-12-20
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
5
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
7 finish
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
8 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
9 let b:did_indent = 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
10
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
11 setlocal indentexpr=GetLDIndent()
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
12 setlocal indentkeys=0{,0},!^F,o,O
1221
dc65bb5de20e updated for version 7.1b
vimboss
parents: 839
diff changeset
13 setlocal nosmartindent
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
14
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
15 if exists("*GetLDIndent")
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
16 finish
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
17 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
18
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
19 function s:prevnonblanknoncomment(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
20 let lnum = a:lnum
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
21 while lnum > 1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
22 let lnum = prevnonblank(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
23 let line = getline(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
24 if line =~ '\*/'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
25 while lnum > 1 && line !~ '/\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
26 let lnum -= 1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
27 endwhile
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
28 if line =~ '^\s*/\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
29 let lnum -= 1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
30 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
31 break
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
32 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
33 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
34 break
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
35 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
36 endwhile
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
37 return lnum
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
38 endfunction
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
39
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
40 function s:count_braces(lnum, count_open)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
41 let n_open = 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
42 let n_close = 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
43 let line = getline(a:lnum)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
44 let pattern = '[{}]'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
45 let i = match(line, pattern)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
46 while i != -1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
47 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
48 if line[i] == '{'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
49 let n_open += 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
50 elseif line[i] == '}'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
51 if n_open > 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
52 let n_open -= 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
53 else
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
54 let n_close += 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
55 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
56 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
57 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
58 let i = match(line, pattern, i + 1)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
59 endwhile
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
60 return a:count_open ? n_open : n_close
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
61 endfunction
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
62
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
63 function GetLDIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
64 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
65 if line =~ '^\s*\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
66 return cindent(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
67 elseif line =~ '^\s*}'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
68 return indent(v:lnum) - shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
69 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
70
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
71 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
72 if pnum == 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
73 return 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
74 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
75
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
76 let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
77
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
78 let pline = getline(pnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
79 if pline =~ '}\s*$'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
80 let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
81 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
82
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
83 return ind
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
84 endfunction