annotate runtime/indent/sas.vim @ 18486:9d887cad7315

Added tag v8.1.2237 for changeset 63ee3c2b140fe1b4801389872a8e47aec19d028b
author Bram Moolenaar <Bram@vim.org>
date Thu, 31 Oct 2019 20:00:04 +0100
parents 4543777545a3
children 6dd88e45d47d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Vim indent file
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Language: SAS
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Maintainer: Zhen-Huan Hu <wildkeny@gmail.com>
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
4 " Version: 3.0.3
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
5 " Last Change: Jun 26, 2018
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 if exists("b:did_indent")
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 finish
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let b:did_indent = 1
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 setlocal indentexpr=GetSASIndent()
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 setlocal indentkeys+=;,=~data,=~proc,=~macro
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 if exists("*GetSASIndent")
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 finish
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let s:cpo_save = &cpo
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 set cpo&vim
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 " Regex that captures the start of a data/proc section
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 let s:section_str = '\v%(^|;)\s*%(data|proc)>'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 " Regex that captures the end of a run-processing section
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let s:section_run = '\v%(^|;)\s*run\s*;'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 " Regex that captures the end of a data/proc section
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let s:section_end = '\v%(^|;)\s*%(quit|enddata)\s*;'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 " Regex that captures the start of a control block (anything inside a section)
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
30 let s:block_str = '\v<%(do>%([^;]+<%(to|over|while)>[^;]+)=|%(compute|define\s+%(column|footer|header|style|table|tagset|crosstabs|statgraph)|edit|layout|method|select)>[^;]+|begingraph)\s*;'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " Regex that captures the end of a control block (anything inside a section)
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
32 let s:block_end = '\v<%(end|endcomp|endlayout|endgraph)\s*;'
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 " Regex that captures the start of a macro
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let s:macro_str = '\v%(^|;)\s*\%macro>'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " Regex that captures the end of a macro
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let s:macro_end = '\v%(^|;)\s*\%mend\s*;'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 " Regex that defines the end of the program
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let s:program_end = '\v%(^|;)\s*endsas\s*;'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " List of procs supporting run-processing
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 let s:run_processing_procs = [
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 \ 'catalog', 'chart', 'datasets', 'document', 'ds2', 'plot', 'sql',
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 \ 'gareabar', 'gbarline', 'gchart', 'gkpi', 'gmap', 'gplot', 'gradar', 'greplay', 'gslide', 'gtile',
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 \ 'anova', 'arima', 'catmod', 'factex', 'glm', 'model', 'optex', 'plan', 'reg',
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 \ 'iml',
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 \ ]
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 " Find the line number of previous keyword defined by the regex
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 function! s:PrevMatch(lnum, regex)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 let prev_lnum = prevnonblank(a:lnum - 1)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 while prev_lnum > 0
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let prev_line = getline(prev_lnum)
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
55 if prev_line =~? a:regex
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 break
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 else
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let prev_lnum = prevnonblank(prev_lnum - 1)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 endwhile
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 return prev_lnum
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 endfunction
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 " Main function
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 function! GetSASIndent()
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 let prev_lnum = prevnonblank(v:lnum - 1)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 if prev_lnum ==# 0
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 " Leave the indentation of the first line unchanged
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 return indent(1)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 else
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 let prev_line = getline(prev_lnum)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 " Previous non-blank line contains the start of a macro/section/block
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 " while not the end of a macro/section/block (at the same line)
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
74 if (prev_line =~? s:section_str && prev_line !~? s:section_run && prev_line !~? s:section_end) ||
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
75 \ (prev_line =~? s:block_str && prev_line !~? s:block_end) ||
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
76 \ (prev_line =~? s:macro_str && prev_line !~? s:macro_end)
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
77 let ind = indent(prev_lnum) + shiftwidth()
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
78 elseif prev_line =~? s:section_run && prev_line !~? s:section_end
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 let prev_section_end_lnum = max([
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 \ s:PrevMatch(v:lnum, s:section_end),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 \ s:PrevMatch(v:lnum, s:macro_end ),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 \ s:PrevMatch(v:lnum, s:program_end)])
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 " Check if the section supports run-processing
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 if prev_section_end_lnum < prev_section_str_lnum &&
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
86 \ getline(prev_section_str_lnum) =~? '\v%(^|;)\s*proc\s+%(' .
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 \ join(s:run_processing_procs, '|') . ')>'
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
88 let ind = indent(prev_lnum) + shiftwidth()
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 else
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 let ind = indent(prev_lnum)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 else
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 let ind = indent(prev_lnum)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 " Re-adjustments based on the inputs of the current line
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 let curr_line = getline(v:lnum)
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
98 if curr_line =~? s:program_end
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 " End of the program
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 " Same indentation as the first non-blank line
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 return indent(nextnonblank(1))
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
102 elseif curr_line =~? s:macro_end
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 " Current line is the end of a macro
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 " Match the indentation of the start of the macro
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 return indent(s:PrevMatch(v:lnum, s:macro_str))
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
106 elseif curr_line =~? s:block_end && curr_line !~? s:block_str
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 " Re-adjust if current line is the end of a block
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 " while not the beginning of a block (at the same line)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 " Returning the indent of previous block start directly
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 " would not work due to nesting
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
111 let ind = ind - shiftwidth()
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
112 elseif curr_line =~? s:section_str || curr_line =~? s:section_run || curr_line =~? s:section_end
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 " Re-adjust if current line is the start/end of a section
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 " since the end of a section could be inexplicit
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 " Check if the previous section supports run-processing
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
117 if getline(prev_section_str_lnum) =~? '\v%(^|;)\s*proc\s+%(' .
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 \ join(s:run_processing_procs, '|') . ')>'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 let prev_section_end_lnum = max([
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 \ s:PrevMatch(v:lnum, s:section_end),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 \ s:PrevMatch(v:lnum, s:macro_end ),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 \ s:PrevMatch(v:lnum, s:program_end)])
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 else
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 let prev_section_end_lnum = max([
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 \ s:PrevMatch(v:lnum, s:section_end),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 \ s:PrevMatch(v:lnum, s:section_run),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 \ s:PrevMatch(v:lnum, s:macro_end ),
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 \ s:PrevMatch(v:lnum, s:program_end)])
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 if prev_section_end_lnum < prev_section_str_lnum
14249
4543777545a3 Updated runtime and language files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
131 let ind = ind - shiftwidth()
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 endif
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 return ind
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 endfunction
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 let &cpo = s:cpo_save
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 unlet s:cpo_save