annotate runtime/indent/ld.vim @ 27046:ffff3ab24c59

Added tag v8.2.4051 for changeset d31bd86079751c6ca9fb65e456dfe6762606b5e9
author Bram Moolenaar <Bram@vim.org>
date Mon, 10 Jan 2022 12:30:05 +0100
parents 9c221ad9634a
children
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
2 " Language: ld(1) script
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
3 " Maintainer: Doug Kearns <dougkearns@gmail.com>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
5 " Last Change: 24 Sep 2021
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
6
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
7 if exists("b:did_indent")
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
8 finish
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
9 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
10 let b:did_indent = 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
11
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
12 setlocal indentexpr=GetLDIndent()
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
13 setlocal indentkeys=0{,0},!^F,o,O
1221
dc65bb5de20e updated for version 7.1b
vimboss
parents: 839
diff changeset
14 setlocal nosmartindent
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
15
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
16 let b:undo_indent = "setl inde< indk< si<"
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11160
diff changeset
17
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
18 if exists("*GetLDIndent")
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
19 finish
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
20 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
21
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
22 function s:prevnonblanknoncomment(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
23 let lnum = a:lnum
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
24 while lnum > 1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
25 let lnum = prevnonblank(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
26 let line = getline(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
27 if line =~ '\*/'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
28 while lnum > 1 && line !~ '/\*'
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 endwhile
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
31 if line =~ '^\s*/\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
32 let lnum -= 1
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 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
37 break
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
38 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
39 endwhile
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
40 return lnum
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
41 endfunction
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
42
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
43 function s:count_braces(lnum, count_open)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
44 let n_open = 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
45 let n_close = 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
46 let line = getline(a:lnum)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
47 let pattern = '[{}]'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
48 let i = match(line, pattern)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
49 while i != -1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
50 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
51 if line[i] == '{'
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 elseif line[i] == '}'
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
54 if n_open > 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
55 let n_open -= 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
56 else
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
57 let n_close += 1
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
58 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
59 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
60 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
61 let i = match(line, pattern, i + 1)
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
62 endwhile
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
63 return a:count_open ? n_open : n_close
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
64 endfunction
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
65
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
66 function GetLDIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
67 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
68 if line =~ '^\s*\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
69 return cindent(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
70 elseif line =~ '^\s*}'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
71 return indent(v:lnum) - shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
72 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
73
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
74 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
75 if pnum == 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
76 return 0
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
77 endif
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
78
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
79 let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
80
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
81 let pline = getline(pnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
82 if pline =~ '}\s*$'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
83 let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
84 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
85
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
86 return ind
374
575dacb554d8 updated for version 7.0096
vimboss
parents:
diff changeset
87 endfunction