Mercurial > vim
comparison runtime/indent/sqlanywhere.vim @ 856:8cd729851562 v7.0g
updated for version 7.0g
author | vimboss |
---|---|
date | Sun, 30 Apr 2006 18:54:39 +0000 |
parents | 7b21554be7a1 |
children | b9740fb41986 |
comparison
equal
deleted
inserted
replaced
855:d2a4f08396fe | 856:8cd729851562 |
---|---|
1 " Vim indent file | 1 " Vim indent file |
2 " Language: SQL | 2 " Language: SQL |
3 " Maintainer: David Fishburn <fishburn at ianywhere dot com> | 3 " Maintainer: David Fishburn <fishburn at ianywhere dot com> |
4 " Last Change: Wed Sep 14 2005 10:21:15 PM | 4 " Last Change: Wed Sep 14 2005 10:21:15 PM |
5 " Version: 1.4 | 5 " Version: 1.4 |
6 " Download: http://vim.sourceforge.net/script.php?script_id=495 | 6 " Download: http://vim.sourceforge.net/script.php?script_id=495 |
7 | 7 |
8 " Notes: | 8 " Notes: |
9 " Indenting keywords are based on Oracle and Sybase Adaptive Server | 9 " Indenting keywords are based on Oracle and Sybase Adaptive Server |
10 " Anywhere (ASA). Test indenting was done with ASA stored procedures and | 10 " Anywhere (ASA). Test indenting was done with ASA stored procedures and |
11 " fuctions and Oracle packages which contain stored procedures and | 11 " fuctions and Oracle packages which contain stored procedures and |
12 " functions. | 12 " functions. |
13 " This has not been tested against Microsoft SQL Server or | 13 " This has not been tested against Microsoft SQL Server or |
14 " Sybase Adaptive Server Enterprise (ASE) which use the Transact-SQL | 14 " Sybase Adaptive Server Enterprise (ASE) which use the Transact-SQL |
15 " syntax. That syntax does not have end tags for IF's, which makes | 15 " syntax. That syntax does not have end tags for IF's, which makes |
16 " indenting more difficult. | 16 " indenting more difficult. |
17 " | 17 " |
18 " Known Issues: | 18 " Known Issues: |
30 setlocal indentkeys-=0} | 30 setlocal indentkeys-=0} |
31 setlocal indentkeys-=: | 31 setlocal indentkeys-=: |
32 setlocal indentkeys-=0# | 32 setlocal indentkeys-=0# |
33 setlocal indentkeys-=e | 33 setlocal indentkeys-=e |
34 | 34 |
35 " This indicates formatting should take place when one of these | 35 " This indicates formatting should take place when one of these |
36 " expressions is used. These expressions would normally be something | 36 " expressions is used. These expressions would normally be something |
37 " you would type at the BEGINNING of a line | 37 " you would type at the BEGINNING of a line |
38 " SQL is generally case insensitive, so this files assumes that | 38 " SQL is generally case insensitive, so this files assumes that |
39 " These keywords are something that would trigger an indent LEFT, not | 39 " These keywords are something that would trigger an indent LEFT, not |
40 " an indent right, since the SQLBlockStart is used for those keywords | 40 " an indent right, since the SQLBlockStart is used for those keywords |
41 setlocal indentkeys+==~end,=~else,=~elseif,=~elsif,0=~when,0=) | 41 setlocal indentkeys+==~end,=~else,=~elseif,=~elsif,0=~when,0=) |
42 | 42 |
43 " GetSQLIndent is executed whenever one of the expressions | 43 " GetSQLIndent is executed whenever one of the expressions |
44 " in the indentkeys is typed | 44 " in the indentkeys is typed |
45 setlocal indentexpr=GetSQLIndent() | 45 setlocal indentexpr=GetSQLIndent() |
46 | 46 |
47 " Only define the functions once. | 47 " Only define the functions once. |
48 if exists("*GetSQLIndent") | 48 if exists("*GetSQLIndent") |
49 finish | 49 finish |
50 endif | 50 endif |
51 | 51 |
52 " List of all the statements that start a new block. | 52 " List of all the statements that start a new block. |
53 " These are typically words that start a line. | 53 " These are typically words that start a line. |
54 " IS is excluded, since it is difficult to determine when the | 54 " IS is excluded, since it is difficult to determine when the |
55 " ending block is (especially for procedures/functions). | 55 " ending block is (especially for procedures/functions). |
56 let s:SQLBlockStart = '^\s*\%('. | 56 let s:SQLBlockStart = '^\s*\%('. |
57 \ 'if\|else\|elseif\|elsif\|'. | 57 \ 'if\|else\|elseif\|elsif\|'. |
58 \ 'while\|loop\|do\|'. | 58 \ 'while\|loop\|do\|'. |
59 \ 'begin\|'. | 59 \ 'begin\|'. |
112 " No match found | 112 " No match found |
113 " echom 'CTIRP - no match found, ignoring' | 113 " echom 'CTIRP - no match found, ignoring' |
114 break | 114 break |
115 endif | 115 endif |
116 | 116 |
117 if matching_paran == lnum | 117 if matching_paran == lnum |
118 " This was not an unmatched parantenses, start the search again | 118 " This was not an unmatched parantenses, start the search again |
119 " again after this column | 119 " again after this column |
120 " echom 'CTIRP - same line match, ignoring' | 120 " echom 'CTIRP - same line match, ignoring' |
121 continue | 121 continue |
122 endif | 122 endif |
171 let ind = indent(matching_lnum) | 171 let ind = indent(matching_lnum) |
172 endif | 172 endif |
173 elseif a:keyword =~? 'when' | 173 elseif a:keyword =~? 'when' |
174 exec 'normal! ^' | 174 exec 'normal! ^' |
175 let matching_lnum = searchpair( | 175 let matching_lnum = searchpair( |
176 \ '\%(\<end\s\+\)\@<!\<case\>\|\<exception\>\|\<merge\>', | 176 \ '\%(\<end\s\+\)\@<!\<case\>\|\<exception\>\|\<merge\>', |
177 \ '', | 177 \ '', |
178 \ '\%(\%(\<when\s\+others\>\)\|\%(\<end\s\+case\>\)\)', | 178 \ '\%(\%(\<when\s\+others\>\)\|\%(\<end\s\+case\>\)\)', |
179 \ 'bW', | 179 \ 'bW', |
180 \ 'IsColComment(line("."), col(".")) == 1') | 180 \ 'IsColComment(line("."), col(".")) == 1') |
181 exec 'normal! $' | 181 exec 'normal! $' |
182 if matching_lnum > 0 && matching_lnum < a:curr_lnum | 182 if matching_lnum > 0 && matching_lnum < a:curr_lnum |
183 let ind = indent(matching_lnum) | 183 let ind = indent(matching_lnum) |
191 | 191 |
192 | 192 |
193 " Check if the line is a comment | 193 " Check if the line is a comment |
194 function IsLineComment(lnum) | 194 function IsLineComment(lnum) |
195 let rc = synIDattr( | 195 let rc = synIDattr( |
196 \ synID(a:lnum, | 196 \ synID(a:lnum, |
197 \ match(getline(a:lnum), '\S')+1, 0) | 197 \ match(getline(a:lnum), '\S')+1, 0) |
198 \ , "name") | 198 \ , "name") |
199 \ =~? "comment" | 199 \ =~? "comment" |
200 | 200 |
201 return rc | 201 return rc |
202 endfunction | 202 endfunction |
203 | 203 |
204 | 204 |
205 " Check if the column is a comment | 205 " Check if the column is a comment |
206 function IsColComment(lnum, cnum) | 206 function IsColComment(lnum, cnum) |
207 let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name") | 207 let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name") |
208 \ =~? "comment" | 208 \ =~? "comment" |
209 | 209 |
210 return rc | 210 return rc |
211 endfunction | 211 endfunction |
212 | 212 |
213 | 213 |
214 " Check if the column is a comment | 214 " Check if the column is a comment |
215 function ModuloIndent(ind) | 215 function ModuloIndent(ind) |
216 let ind = a:ind | 216 let ind = a:ind |
217 | 217 |
218 if ind > 0 | 218 if ind > 0 |
219 let modulo = ind % &shiftwidth | 219 let modulo = ind % &shiftwidth |
220 | 220 |
221 if modulo > 0 | 221 if modulo > 0 |
222 let ind = ind - modulo | 222 let ind = ind - modulo |
227 endfunction | 227 endfunction |
228 | 228 |
229 | 229 |
230 " Find correct indent of a new line based upon the previous line | 230 " Find correct indent of a new line based upon the previous line |
231 function GetSQLIndent() | 231 function GetSQLIndent() |
232 let lnum = v:lnum | 232 let lnum = v:lnum |
233 let ind = indent(lnum) | 233 let ind = indent(lnum) |
234 | 234 |
235 " If the current line is a comment, leave the indent as is | 235 " If the current line is a comment, leave the indent as is |
236 " Comment out this additional check since it affects the | 236 " Comment out this additional check since it affects the |
237 " indenting of =, and will not reindent comments as it should | 237 " indenting of =, and will not reindent comments as it should |
244 let prevlnum = prevnonblank(lnum - 1) | 244 let prevlnum = prevnonblank(lnum - 1) |
245 if prevlnum <= 0 | 245 if prevlnum <= 0 |
246 return ind | 246 return ind |
247 endif | 247 endif |
248 | 248 |
249 if IsLineComment(prevlnum) == 1 | 249 if IsLineComment(prevlnum) == 1 |
250 if getline(v:lnum) =~ '^\s*\*' | 250 if getline(v:lnum) =~ '^\s*\*' |
251 let ind = ModuloIndent(indent(prevlnum)) | 251 let ind = ModuloIndent(indent(prevlnum)) |
252 return ind + 1 | 252 return ind + 1 |
253 endif | 253 endif |
254 " If the previous line is a comment, then return -1 | 254 " If the previous line is a comment, then return -1 |
267 " " echom 'previous non blank - break: ' . prevline | 267 " " echom 'previous non blank - break: ' . prevline |
268 " break | 268 " break |
269 " endif | 269 " endif |
270 " endwhile | 270 " endwhile |
271 | 271 |
272 " echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum) | 272 " echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum) |
273 | 273 |
274 " This is the line you just hit return on, it is not the current line | 274 " This is the line you just hit return on, it is not the current line |
275 " which is new and empty | 275 " which is new and empty |
276 " Based on this line, we can determine how much to indent the new | 276 " Based on this line, we can determine how much to indent the new |
277 " line | 277 " line |
278 | 278 |
279 " Get default indent (from prev. line) | 279 " Get default indent (from prev. line) |
280 let ind = indent(prevlnum) | 280 let ind = indent(prevlnum) |
281 let prevline = getline(prevlnum) | 281 let prevline = getline(prevlnum) |
282 | 282 |
283 " Now check what's on the previous line to determine if the indent | 283 " Now check what's on the previous line to determine if the indent |
298 else | 298 else |
299 let num_unmatched_right = 0 | 299 let num_unmatched_right = 0 |
300 " let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) | 300 " let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) |
301 endif | 301 endif |
302 if num_unmatched_left > 0 | 302 if num_unmatched_left > 0 |
303 " There is a open left paranethesis | 303 " There is a open left paranethesis |
304 " increase indent | 304 " increase indent |
305 let ind = ind + ( &sw * num_unmatched_left ) | 305 let ind = ind + ( &sw * num_unmatched_left ) |
306 elseif num_unmatched_right > 0 | 306 elseif num_unmatched_right > 0 |
307 " if it is an unbalanced paranethesis only unindent if | 307 " if it is an unbalanced paranethesis only unindent if |
308 " it was part of a command (ie create table(..) ) | 308 " it was part of a command (ie create table(..) ) |
329 " This is a new blank line since we just typed a carriage return | 329 " This is a new blank line since we just typed a carriage return |
330 " Check current line; search for simplistic matching start-of-block | 330 " Check current line; search for simplistic matching start-of-block |
331 let line = getline(v:lnum) | 331 let line = getline(v:lnum) |
332 | 332 |
333 if line =~? '^\s*els' | 333 if line =~? '^\s*els' |
334 " Any line when you type else will automatically back up one | 334 " Any line when you type else will automatically back up one |
335 " ident level (ie else, elseif, elsif) | 335 " ident level (ie else, elseif, elsif) |
336 let ind = ind - &sw | 336 let ind = ind - &sw |
337 " echom 'curr - else - indent ' . ind | 337 " echom 'curr - else - indent ' . ind |
338 elseif line =~? '^\s*end\>' | 338 elseif line =~? '^\s*end\>' |
339 let ind = s:GetStmtStarterIndent('end', v:lnum) | 339 let ind = s:GetStmtStarterIndent('end', v:lnum) |
354 let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) | 354 let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) |
355 let ignore = s:CheckToIgnoreRightParan( v:lnum, num_unmatched_right ) | 355 let ignore = s:CheckToIgnoreRightParan( v:lnum, num_unmatched_right ) |
356 " If the line ends in a ), then reduce the indent | 356 " If the line ends in a ), then reduce the indent |
357 " This catches items like: | 357 " This catches items like: |
358 " CREATE TABLE T1( | 358 " CREATE TABLE T1( |
359 " c1 int, | 359 " c1 int, |
360 " c2 int | 360 " c2 int |
361 " ); | 361 " ); |
362 " But we do not want to unindent a line like: | 362 " But we do not want to unindent a line like: |
363 " IF ( c1 = 1 | 363 " IF ( c1 = 1 |
364 " AND c2 = 3 ) THEN | 364 " AND c2 = 3 ) THEN |
365 " let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) | 365 " let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) |
366 " if num_unmatched_right > 0 | 366 " if num_unmatched_right > 0 |
367 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')' | 367 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')' |
368 " let ind = ind - &sw | 368 " let ind = ind - &sw |