annotate runtime/indent/sqlanywhere.vim @ 10955:a555c11b59a9

Added tag v8.0.0366 for changeset 8ff62b4cffaedc9575a7ba3901c9228d6c8ee24e
author Christian Brabandt <cb@256bit.org>
date Sat, 25 Feb 2017 15:45:04 +0100
parents e362db8b2d7b
children 63b0b7b79b25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
1 " Vim indent file
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
2 " Language: SQL
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
3 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
4073
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
4 " Last Change: 2012 Dec 06
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
5 " Version: 3.0
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
6 " Download: http://vim.sourceforge.net/script.php?script_id=495
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
7
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
8 " Notes:
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
9 " Indenting keywords are based on Oracle and Sybase Adaptive Server
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
10 " Anywhere (ASA). Test indenting was done with ASA stored procedures and
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
11 " fuctions and Oracle packages which contain stored procedures and
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
12 " functions.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
13 " This has not been tested against Microsoft SQL Server or
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
14 " Sybase Adaptive Server Enterprise (ASE) which use the Transact-SQL
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
15 " syntax. That syntax does not have end tags for IF's, which makes
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
16 " indenting more difficult.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
17 "
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
18 " Known Issues:
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
19 " The Oracle MERGE statement does not have an end tag associated with
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
20 " it, this can leave the indent hanging to the right one too many.
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
21 "
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
22 " History:
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
23 " 3.0 (Dec 2012)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
24 " Added cpo check
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
25 "
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
26 " 2.0
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
27 " Added the FOR keyword to SQLBlockStart to handle (Alec Tica):
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
28 " for i in 1..100 loop
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
29 " |<-- I expect to have indentation here
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
30 " end loop;
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
31 "
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
32
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
33 " Only load this indent file when no other was loaded.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
34 if exists("b:did_indent")
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
35 finish
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
36 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
37 let b:did_indent = 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
38 let b:current_indent = "sqlanywhere"
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
39
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
40 setlocal indentkeys-=0{
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
41 setlocal indentkeys-=0}
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
42 setlocal indentkeys-=:
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
43 setlocal indentkeys-=0#
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
44 setlocal indentkeys-=e
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
45
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
46 " This indicates formatting should take place when one of these
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
47 " expressions is used. These expressions would normally be something
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
48 " you would type at the BEGINNING of a line
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
49 " SQL is generally case insensitive, so this files assumes that
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
50 " These keywords are something that would trigger an indent LEFT, not
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
51 " an indent right, since the SQLBlockStart is used for those keywords
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
52 setlocal indentkeys+==~end,=~else,=~elseif,=~elsif,0=~when,0=)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
53
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
54 " GetSQLIndent is executed whenever one of the expressions
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
55 " in the indentkeys is typed
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
56 setlocal indentexpr=GetSQLIndent()
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
57
4073
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
58 " Only define the functions once.
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
59 if exists("*GetSQLIndent")
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
60 finish
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
61 endif
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
62 let s:keepcpo= &cpo
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
63 set cpo&vim
e362db8b2d7b Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3996
diff changeset
64
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
65 " List of all the statements that start a new block.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
66 " These are typically words that start a line.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
67 " IS is excluded, since it is difficult to determine when the
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
68 " ending block is (especially for procedures/functions).
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
69 let s:SQLBlockStart = '^\s*\%('.
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
70 \ 'if\|else\|elseif\|elsif\|'.
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
71 \ 'while\|loop\|do\|for\|'.
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
72 \ 'begin\|'.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
73 \ 'case\|when\|merge\|exception'.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
74 \ '\)\>'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
75 let s:SQLBlockEnd = '^\s*\(end\)\>'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
76
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
77 " The indent level is also based on unmatched paranethesis
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
78 " If a line has an extra "(" increase the indent
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
79 " If a line has an extra ")" decrease the indent
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
80 function! s:CountUnbalancedParan( line, paran_to_check )
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
81 let l = a:line
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
82 let lp = substitute(l, '[^(]', '', 'g')
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
83 let l = a:line
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
84 let rp = substitute(l, '[^)]', '', 'g')
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
85
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
86 if a:paran_to_check =~ ')'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
87 " echom 'CountUnbalancedParan ) returning: ' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
88 " \ (strlen(rp) - strlen(lp))
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
89 return (strlen(rp) - strlen(lp))
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
90 elseif a:paran_to_check =~ '('
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
91 " echom 'CountUnbalancedParan ( returning: ' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
92 " \ (strlen(lp) - strlen(rp))
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
93 return (strlen(lp) - strlen(rp))
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
94 else
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
95 " echom 'CountUnbalancedParan unknown paran to check: ' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
96 " \ a:paran_to_check
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
97 return 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
98 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
99 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
100
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
101 " Unindent commands based on previous indent level
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
102 function! s:CheckToIgnoreRightParan( prev_lnum, num_levels )
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
103 let lnum = a:prev_lnum
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
104 let line = getline(lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
105 let ends = 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
106 let num_right_paran = a:num_levels
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
107 let ignore_paran = 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
108 let vircol = 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
109
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
110 while num_right_paran > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
111 silent! exec 'norm! '.lnum."G\<bar>".vircol."\<bar>"
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
112 let right_paran = search( ')', 'W' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
113 if right_paran != lnum
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
114 " This should not happen since there should be at least
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
115 " num_right_paran matches for this line
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
116 break
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
117 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
118 let vircol = virtcol(".")
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
119
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
120 " if getline(".") =~ '^)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
121 let matching_paran = searchpair('(', '', ')', 'bW',
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
122 \ 's:IsColComment(line("."), col("."))')
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
123
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
124 if matching_paran < 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
125 " No match found
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
126 " echom 'CTIRP - no match found, ignoring'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
127 break
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
128 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
129
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
130 if matching_paran == lnum
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
131 " This was not an unmatched parantenses, start the search again
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
132 " again after this column
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
133 " echom 'CTIRP - same line match, ignoring'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
134 continue
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
135 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
136
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
137 " echom 'CTIRP - match: ' . line(".") . ' ' . getline(".")
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
138
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
139 if getline(matching_paran) =~? '\(if\|while\)\>'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
140 " echom 'CTIRP - if/while ignored: ' . line(".") . ' ' . getline(".")
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
141 let ignore_paran = ignore_paran + 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
142 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
143
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
144 " One match found, decrease and check for further matches
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
145 let num_right_paran = num_right_paran - 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
146
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
147 endwhile
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
148
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
149 " Fallback - just move back one
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
150 " return a:prev_indent - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
151 return ignore_paran
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
152 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
153
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
154 " Based on the keyword provided, loop through previous non empty
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
155 " non comment lines to find the statement that initated the keyword.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
156 " Return its indent level
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
157 " CASE ..
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
158 " WHEN ...
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
159 " Should return indent level of CASE
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
160 " EXCEPTION ..
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
161 " WHEN ...
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
162 " something;
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
163 " WHEN ...
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
164 " Should return indent level of exception.
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
165 function! s:GetStmtStarterIndent( keyword, curr_lnum )
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
166 let lnum = a:curr_lnum
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
167
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
168 " Default - reduce indent by 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
169 let ind = indent(a:curr_lnum) - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
170
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
171 if a:keyword =~? 'end'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
172 exec 'normal! ^'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
173 let stmts = '^\s*\%('.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
174 \ '\<begin\>\|' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
175 \ '\%(\%(\<end\s\+\)\@<!\<loop\>\)\|' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
176 \ '\%(\%(\<end\s\+\)\@<!\<case\>\)\|' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
177 \ '\%(\%(\<end\s\+\)\@<!\<for\>\)\|' .
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
178 \ '\%(\%(\<end\s\+\)\@<!\<if\>\)'.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
179 \ '\)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
180 let matching_lnum = searchpair(stmts, '', '\<end\>\zs', 'bW',
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
181 \ 's:IsColComment(line("."), col(".")) == 1')
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
182 exec 'normal! $'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
183 if matching_lnum > 0 && matching_lnum < a:curr_lnum
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
184 let ind = indent(matching_lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
185 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
186 elseif a:keyword =~? 'when'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
187 exec 'normal! ^'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
188 let matching_lnum = searchpair(
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
189 \ '\%(\<end\s\+\)\@<!\<case\>\|\<exception\>\|\<merge\>',
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
190 \ '',
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
191 \ '\%(\%(\<when\s\+others\>\)\|\%(\<end\s\+case\>\)\)',
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
192 \ 'bW',
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
193 \ 's:IsColComment(line("."), col(".")) == 1')
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
194 exec 'normal! $'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
195 if matching_lnum > 0 && matching_lnum < a:curr_lnum
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
196 let ind = indent(matching_lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
197 else
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
198 let ind = indent(a:curr_lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
199 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
200 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
201
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
202 return ind
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
203 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
204
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
205
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
206 " Check if the line is a comment
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
207 function! s:IsLineComment(lnum)
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
208 let rc = synIDattr(
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
209 \ synID(a:lnum,
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
210 \ match(getline(a:lnum), '\S')+1, 0)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
211 \ , "name")
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
212 \ =~? "comment"
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
213
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
214 return rc
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
215 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
216
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
217
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
218 " Check if the column is a comment
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
219 function! s:IsColComment(lnum, cnum)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
220 let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name")
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
221 \ =~? "comment"
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
222
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
223 return rc
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
224 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
225
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
226
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
227 " Instead of returning a column position, return
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
228 " an appropriate value as a factor of shiftwidth.
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
229 function! s:ModuloIndent(ind)
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
230 let ind = a:ind
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
231
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
232 if ind > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
233 let modulo = ind % &shiftwidth
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
234
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
235 if modulo > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
236 let ind = ind - modulo
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
237 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
238 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
239
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
240 return ind
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
241 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
242
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
243
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
244 " Find correct indent of a new line based upon the previous line
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
245 function! GetSQLIndent()
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
246 let lnum = v:lnum
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
247 let ind = indent(lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
248
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
249 " If the current line is a comment, leave the indent as is
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
250 " Comment out this additional check since it affects the
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
251 " indenting of =, and will not reindent comments as it should
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
252 " if s:IsLineComment(lnum) == 1
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
253 " return ind
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
254 " endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
255
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
256 " Get previous non-blank line
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
257 let prevlnum = prevnonblank(lnum - 1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
258 if prevlnum <= 0
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
259 return ind
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
260 endif
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
261
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
262 if s:IsLineComment(prevlnum) == 1
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
263 if getline(v:lnum) =~ '^\s*\*'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
264 let ind = s:ModuloIndent(indent(prevlnum))
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
265 return ind + 1
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
266 endif
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
267 " If the previous line is a comment, then return -1
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
268 " to tell Vim to use the formatoptions setting to determine
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
269 " the indent to use
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
270 " But only if the next line is blank. This would be true if
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
271 " the user is typing, but it would not be true if the user
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
272 " is reindenting the file
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
273 if getline(v:lnum) =~ '^\s*$'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
274 return -1
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
275 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
276 endif
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
277
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
278 " echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum)
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
279
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
280 " This is the line you just hit return on, it is not the current line
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
281 " which is new and empty
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
282 " Based on this line, we can determine how much to indent the new
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
283 " line
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
284
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
285 " Get default indent (from prev. line)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
286 let ind = indent(prevlnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
287 let prevline = getline(prevlnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
288
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
289 " Now check what's on the previous line to determine if the indent
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
290 " should be changed, for example IF, BEGIN, should increase the indent
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
291 " where END IF, END, should decrease the indent.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
292 if prevline =~? s:SQLBlockStart
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
293 " Move indent in
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
294 let ind = ind + &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
295 " echom 'prevl - SQLBlockStart - indent ' . ind . ' line: ' . prevline
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
296 elseif prevline =~ '[()]'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
297 if prevline =~ '('
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
298 let num_unmatched_left = s:CountUnbalancedParan( prevline, '(' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
299 else
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
300 let num_unmatched_left = 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
301 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
302 if prevline =~ ')'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
303 let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
304 else
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
305 let num_unmatched_right = 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
306 " let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
307 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
308 if num_unmatched_left > 0
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
309 " There is a open left paranethesis
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
310 " increase indent
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
311 let ind = ind + ( &sw * num_unmatched_left )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
312 elseif num_unmatched_right > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
313 " if it is an unbalanced paranethesis only unindent if
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
314 " it was part of a command (ie create table(..) )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
315 " instead of part of an if (ie if (....) then) which should
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
316 " maintain the indent level
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
317 let ignore = s:CheckToIgnoreRightParan( prevlnum, num_unmatched_right )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
318 " echom 'prevl - ) unbalanced - CTIRP - ignore: ' . ignore
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
319
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
320 if prevline =~ '^\s*)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
321 let ignore = ignore + 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
322 " echom 'prevl - begins ) unbalanced ignore: ' . ignore
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
323 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
324
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
325 if (num_unmatched_right - ignore) > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
326 let ind = ind - ( &sw * (num_unmatched_right - ignore) )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
327 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
328
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
329 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
330 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
331
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
332
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
333 " echom 'CURRENT INDENT: ' . ind . ' LINE: ' . getline(v:lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
334
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
335 " This is a new blank line since we just typed a carriage return
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
336 " Check current line; search for simplistic matching start-of-block
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
337 let line = getline(v:lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
338
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
339 if line =~? '^\s*els'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
340 " Any line when you type else will automatically back up one
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
341 " ident level (ie else, elseif, elsif)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
342 let ind = ind - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
343 " echom 'curr - else - indent ' . ind
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
344 elseif line =~? '^\s*end\>'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
345 let ind = s:GetStmtStarterIndent('end', v:lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
346 " General case for end
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
347 " let ind = ind - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
348 " echom 'curr - end - indent ' . ind
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
349 elseif line =~? '^\s*when\>'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
350 let ind = s:GetStmtStarterIndent('when', v:lnum)
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
351 " If the WHEN clause is used with a MERGE or EXCEPTION
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
352 " clause, do not change the indent level, since these
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
353 " statements do not have a corresponding END statement.
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
354 " if stmt_starter =~? 'case'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
355 " let ind = ind - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
356 " endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
357 " elseif line =~ '^\s*)\s*;\?\s*$'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
358 " elseif line =~ '^\s*)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
359 elseif line =~ '^\s*)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
360 let num_unmatched_right = s:CountUnbalancedParan( line, ')' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
361 let ignore = s:CheckToIgnoreRightParan( v:lnum, num_unmatched_right )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
362 " If the line ends in a ), then reduce the indent
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
363 " This catches items like:
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
364 " CREATE TABLE T1(
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
365 " c1 int,
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
366 " c2 int
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
367 " );
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
368 " But we do not want to unindent a line like:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 718
diff changeset
369 " IF ( c1 = 1
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
370 " AND c2 = 3 ) THEN
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
371 " let num_unmatched_right = s:CountUnbalancedParan( line, ')' )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
372 " if num_unmatched_right > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
373 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
374 " let ind = ind - &sw
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
375 if line =~ '^\s*)'
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
376 " let ignore = ignore + 1
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
377 " echom 'curr - begins ) unbalanced ignore: ' . ignore
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
378 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
379
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
380 if (num_unmatched_right - ignore) > 0
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
381 let ind = ind - ( &sw * (num_unmatched_right - ignore) )
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
382 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
383 " endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
384 endif
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
385
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
386 " echom 'final - indent ' . ind
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 856
diff changeset
387 return s:ModuloIndent(ind)
718
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
388 endfunction
7b21554be7a1 updated for version 7.0219
vimboss
parents:
diff changeset
389
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
390 " Restore:
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
391 let &cpo= s:keepcpo
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1619
diff changeset
392 unlet s:keepcpo
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
393 " vim: ts=4 fdm=marker sw=4