annotate runtime/indent/sas.vim @ 12485:ab40ecb0fd73 v8.0.1122

patch 8.0.1122: vimtutor.bat doesn't work well with vim.bat commit https://github.com/vim/vim/commit/dde403c2d8f3dabe6fefa7b526958b49a8f2e6e9 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 17 21:43:00 2017 +0200 patch 8.0.1122: vimtutor.bat doesn't work well with vim.bat Problem: vimtutor.bat doesn't work well with vim.bat. Solution: Use "call vim". (Ken Takata, closes https://github.com/vim/vim/issues/2105)
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Sep 2017 21:45:04 +0200
parents d0a20101ecb2
children 4543777545a3
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>
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Version: 3.0.1
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " Last Change: Mar 13, 2017
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)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 let s:block_str = '\v<%(do>%([^;]+<%(to|over)>[^;]+)=|%(define|layout|method|select)>[^;]+|begingraph)\s*;'
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)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 let s:block_end = '\v<%(end|endlayout|endgraph)\s*;'
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)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 if prev_line =~ a:regex
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)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 if (prev_line =~ s:section_str && prev_line !~ s:section_run && prev_line !~ s:section_end) ||
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 \ (prev_line =~ s:block_str && prev_line !~ s:block_end) ||
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 \ (prev_line =~ s:macro_str && prev_line !~ s:macro_end)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 let ind = indent(prev_lnum) + &sts
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 elseif prev_line =~ s:section_run && prev_line !~ s:section_end
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 &&
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 \ getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' .
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 \ join(s:run_processing_procs, '|') . ')>'
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 let ind = indent(prev_lnum) + &sts
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)
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 if curr_line =~ s:program_end
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))
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 elseif curr_line =~ s:macro_end
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))
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 elseif curr_line =~ s:block_end && curr_line !~ s:block_str
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
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 let ind = ind - &sts
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 elseif curr_line =~ s:section_str || curr_line =~ s:section_run || curr_line =~ s:section_end
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
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 if getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' .
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
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 let ind = ind - &sts
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