Mercurial > vim
comparison runtime/indent/sqlanywhere.vim @ 20753:661eb972cb22
Update runtime files
Commit: https://github.com/vim/vim/commit/acc224064033e5cea21ef7f1eefb356ca06ff11d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 7 21:07:18 2020 +0200
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 07 Jun 2020 21:15:04 +0200 |
parents | 63b0b7b79b25 |
children | 11b656e74444 |
comparison
equal
deleted
inserted
replaced
20752:47b5de84b7f7 | 20753:661eb972cb22 |
---|---|
1 " Vim indent file | 1 " Vim indent file |
2 " Language: SQL | 2 " Language: SQL |
3 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com> | 3 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com> |
4 " Last Change: 2017 Jun 13 | 4 " Last Change By Maintainer: 2017 Jun 13 |
5 " Last Change: by Stephen Wall, #5578, 2020 Jun 07 | |
5 " Version: 3.0 | 6 " Version: 3.0 |
6 " Download: http://vim.sourceforge.net/script.php?script_id=495 | 7 " Download: http://vim.sourceforge.net/script.php?script_id=495 |
7 | 8 |
8 " Notes: | 9 " Notes: |
9 " Indenting keywords are based on Oracle and Sybase Adaptive Server | 10 " Indenting keywords are based on Oracle and Sybase Adaptive Server |
65 " List of all the statements that start a new block. | 66 " List of all the statements that start a new block. |
66 " These are typically words that start a line. | 67 " These are typically words that start a line. |
67 " IS is excluded, since it is difficult to determine when the | 68 " IS is excluded, since it is difficult to determine when the |
68 " ending block is (especially for procedures/functions). | 69 " ending block is (especially for procedures/functions). |
69 let s:SQLBlockStart = '^\s*\%('. | 70 let s:SQLBlockStart = '^\s*\%('. |
70 \ 'if\|else\|elseif\|elsif\|'. | 71 \ 'if\>.*\<then\|'. |
71 \ 'while\|loop\|do\|for\|'. | 72 \ 'then\|else\>\|'. |
72 \ 'begin\|'. | 73 \ 'elseif\>.*\<then\|'. |
74 \ 'elsif\>.(\<then\|'. | |
75 \ 'while\>.*\<loop\|'. | |
76 \ 'for\>.*\<loop\|'. | |
77 \ 'foreach\>.*\<loop\|'. | |
78 \ 'loop\|do\|declare\|begin\|'. | |
73 \ 'case\|when\|merge\|exception'. | 79 \ 'case\|when\|merge\|exception'. |
74 \ '\)\>' | 80 \ '\)\>' |
75 let s:SQLBlockEnd = '^\s*\(end\)\>' | 81 let s:SQLBlockEnd = '^\s*\(end\)\>' |
76 | 82 |
77 " The indent level is also based on unmatched paranethesis | 83 " The indent level is also based on unmatched parentheses |
78 " If a line has an extra "(" increase the indent | 84 " If a line has an extra "(" increase the indent |
79 " If a line has an extra ")" decrease the indent | 85 " If a line has an extra ")" decrease the indent |
80 function! s:CountUnbalancedParan( line, paran_to_check ) | 86 function! s:CountUnbalancedParen( line, paren_to_check ) |
81 let l = a:line | 87 let l = a:line |
82 let lp = substitute(l, '[^(]', '', 'g') | 88 let lp = substitute(l, '[^(]', '', 'g') |
83 let l = a:line | 89 let l = a:line |
84 let rp = substitute(l, '[^)]', '', 'g') | 90 let rp = substitute(l, '[^)]', '', 'g') |
85 | 91 |
86 if a:paran_to_check =~ ')' | 92 if a:paren_to_check =~ ')' |
87 " echom 'CountUnbalancedParan ) returning: ' . | 93 " echom 'CountUnbalancedParen ) returning: ' . |
88 " \ (strlen(rp) - strlen(lp)) | 94 " \ (strlen(rp) - strlen(lp)) |
89 return (strlen(rp) - strlen(lp)) | 95 return (strlen(rp) - strlen(lp)) |
90 elseif a:paran_to_check =~ '(' | 96 elseif a:paren_to_check =~ '(' |
91 " echom 'CountUnbalancedParan ( returning: ' . | 97 " echom 'CountUnbalancedParen ( returning: ' . |
92 " \ (strlen(lp) - strlen(rp)) | 98 " \ (strlen(lp) - strlen(rp)) |
93 return (strlen(lp) - strlen(rp)) | 99 return (strlen(lp) - strlen(rp)) |
94 else | 100 else |
95 " echom 'CountUnbalancedParan unknown paran to check: ' . | 101 " echom 'CountUnbalancedParen unknown paren to check: ' . |
96 " \ a:paran_to_check | 102 " \ a:paren_to_check |
97 return 0 | 103 return 0 |
98 endif | 104 endif |
99 endfunction | 105 endfunction |
100 | 106 |
101 " Unindent commands based on previous indent level | 107 " Unindent commands based on previous indent level |
102 function! s:CheckToIgnoreRightParan( prev_lnum, num_levels ) | 108 function! s:CheckToIgnoreRightParen( prev_lnum, num_levels ) |
103 let lnum = a:prev_lnum | 109 let lnum = a:prev_lnum |
104 let line = getline(lnum) | 110 let line = getline(lnum) |
105 let ends = 0 | 111 let ends = 0 |
106 let num_right_paran = a:num_levels | 112 let num_right_paren = a:num_levels |
107 let ignore_paran = 0 | 113 let ignore_paren = 0 |
108 let vircol = 1 | 114 let vircol = 1 |
109 | 115 |
110 while num_right_paran > 0 | 116 while num_right_paren > 0 |
111 silent! exec 'norm! '.lnum."G\<bar>".vircol."\<bar>" | 117 silent! exec 'norm! '.lnum."G\<bar>".vircol."\<bar>" |
112 let right_paran = search( ')', 'W' ) | 118 let right_paren = search( ')', 'W' ) |
113 if right_paran != lnum | 119 if right_paren != lnum |
114 " This should not happen since there should be at least | 120 " This should not happen since there should be at least |
115 " num_right_paran matches for this line | 121 " num_right_paren matches for this line |
116 break | 122 break |
117 endif | 123 endif |
118 let vircol = virtcol(".") | 124 let vircol = virtcol(".") |
119 | 125 |
120 " if getline(".") =~ '^)' | 126 " if getline(".") =~ '^)' |
121 let matching_paran = searchpair('(', '', ')', 'bW', | 127 let matching_paren = searchpair('(', '', ')', 'bW', |
122 \ 's:IsColComment(line("."), col("."))') | 128 \ 's:IsColComment(line("."), col("."))') |
123 | 129 |
124 if matching_paran < 1 | 130 if matching_paren < 1 |
125 " No match found | 131 " No match found |
126 " echom 'CTIRP - no match found, ignoring' | 132 " echom 'CTIRP - no match found, ignoring' |
127 break | 133 break |
128 endif | 134 endif |
129 | 135 |
130 if matching_paran == lnum | 136 if matching_paren == lnum |
131 " This was not an unmatched parantenses, start the search again | 137 " This was not an unmatched parentheses, start the search again |
132 " again after this column | 138 " again after this column |
133 " echom 'CTIRP - same line match, ignoring' | 139 " echom 'CTIRP - same line match, ignoring' |
134 continue | 140 continue |
135 endif | 141 endif |
136 | 142 |
137 " echom 'CTIRP - match: ' . line(".") . ' ' . getline(".") | 143 " echom 'CTIRP - match: ' . line(".") . ' ' . getline(".") |
138 | 144 |
139 if getline(matching_paran) =~? '\(if\|while\)\>' | 145 if getline(matching_paren) =~? '\(if\|while\)\>' |
140 " echom 'CTIRP - if/while ignored: ' . line(".") . ' ' . getline(".") | 146 " echom 'CTIRP - if/while ignored: ' . line(".") . ' ' . getline(".") |
141 let ignore_paran = ignore_paran + 1 | 147 let ignore_paren = ignore_paren + 1 |
142 endif | 148 endif |
143 | 149 |
144 " One match found, decrease and check for further matches | 150 " One match found, decrease and check for further matches |
145 let num_right_paran = num_right_paran - 1 | 151 let num_right_paren = num_right_paren - 1 |
146 | 152 |
147 endwhile | 153 endwhile |
148 | 154 |
149 " Fallback - just move back one | 155 " Fallback - just move back one |
150 " return a:prev_indent - shiftwidth() | 156 " return a:prev_indent - shiftwidth() |
151 return ignore_paran | 157 return ignore_paren |
152 endfunction | 158 endfunction |
153 | 159 |
154 " Based on the keyword provided, loop through previous non empty | 160 " Based on the keyword provided, loop through previous non empty |
155 " non comment lines to find the statement that initated the keyword. | 161 " non comment lines to find the statement that initiated the keyword. |
156 " Return its indent level | 162 " Return its indent level |
157 " CASE .. | 163 " CASE .. |
158 " WHEN ... | 164 " WHEN ... |
159 " Should return indent level of CASE | 165 " Should return indent level of CASE |
160 " EXCEPTION .. | 166 " EXCEPTION .. |
293 " Move indent in | 299 " Move indent in |
294 let ind = ind + shiftwidth() | 300 let ind = ind + shiftwidth() |
295 " echom 'prevl - SQLBlockStart - indent ' . ind . ' line: ' . prevline | 301 " echom 'prevl - SQLBlockStart - indent ' . ind . ' line: ' . prevline |
296 elseif prevline =~ '[()]' | 302 elseif prevline =~ '[()]' |
297 if prevline =~ '(' | 303 if prevline =~ '(' |
298 let num_unmatched_left = s:CountUnbalancedParan( prevline, '(' ) | 304 let num_unmatched_left = s:CountUnbalancedParen( prevline, '(' ) |
299 else | 305 else |
300 let num_unmatched_left = 0 | 306 let num_unmatched_left = 0 |
301 endif | 307 endif |
302 if prevline =~ ')' | 308 if prevline =~ ')' |
303 let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) | 309 let num_unmatched_right = s:CountUnbalancedParen( prevline, ')' ) |
304 else | 310 else |
305 let num_unmatched_right = 0 | 311 let num_unmatched_right = 0 |
306 " let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) | 312 " let num_unmatched_right = s:CountUnbalancedParen( prevline, ')' ) |
307 endif | 313 endif |
308 if num_unmatched_left > 0 | 314 if num_unmatched_left > 0 |
309 " There is a open left paranethesis | 315 " There is a open left parenthesis |
310 " increase indent | 316 " increase indent |
311 let ind = ind + ( shiftwidth() * num_unmatched_left ) | 317 let ind = ind + ( shiftwidth() * num_unmatched_left ) |
312 elseif num_unmatched_right > 0 | 318 elseif num_unmatched_right > 0 |
313 " if it is an unbalanced paranethesis only unindent if | 319 " if it is an unbalanced parenthesis only unindent if |
314 " it was part of a command (ie create table(..) ) | 320 " it was part of a command (ie create table(..) ) |
315 " instead of part of an if (ie if (....) then) which should | 321 " instead of part of an if (ie if (....) then) which should |
316 " maintain the indent level | 322 " maintain the indent level |
317 let ignore = s:CheckToIgnoreRightParan( prevlnum, num_unmatched_right ) | 323 let ignore = s:CheckToIgnoreRightParen( prevlnum, num_unmatched_right ) |
318 " echom 'prevl - ) unbalanced - CTIRP - ignore: ' . ignore | 324 " echom 'prevl - ) unbalanced - CTIRP - ignore: ' . ignore |
319 | 325 |
320 if prevline =~ '^\s*)' | 326 if prevline =~ '^\s*)' |
321 let ignore = ignore + 1 | 327 let ignore = ignore + 1 |
322 " echom 'prevl - begins ) unbalanced ignore: ' . ignore | 328 " echom 'prevl - begins ) unbalanced ignore: ' . ignore |
355 " let ind = ind - shiftwidth() | 361 " let ind = ind - shiftwidth() |
356 " endif | 362 " endif |
357 " elseif line =~ '^\s*)\s*;\?\s*$' | 363 " elseif line =~ '^\s*)\s*;\?\s*$' |
358 " elseif line =~ '^\s*)' | 364 " elseif line =~ '^\s*)' |
359 elseif line =~ '^\s*)' | 365 elseif line =~ '^\s*)' |
360 let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) | 366 let num_unmatched_right = s:CountUnbalancedParen( line, ')' ) |
361 let ignore = s:CheckToIgnoreRightParan( v:lnum, num_unmatched_right ) | 367 let ignore = s:CheckToIgnoreRightParen( v:lnum, num_unmatched_right ) |
362 " If the line ends in a ), then reduce the indent | 368 " If the line ends in a ), then reduce the indent |
363 " This catches items like: | 369 " This catches items like: |
364 " CREATE TABLE T1( | 370 " CREATE TABLE T1( |
365 " c1 int, | 371 " c1 int, |
366 " c2 int | 372 " c2 int |
367 " ); | 373 " ); |
368 " But we do not want to unindent a line like: | 374 " But we do not want to unindent a line like: |
369 " IF ( c1 = 1 | 375 " IF ( c1 = 1 |
370 " AND c2 = 3 ) THEN | 376 " AND c2 = 3 ) THEN |
371 " let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) | 377 " let num_unmatched_right = s:CountUnbalancedParen( line, ')' ) |
372 " if num_unmatched_right > 0 | 378 " if num_unmatched_right > 0 |
373 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')' | 379 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')' |
374 " let ind = ind - shiftwidth() | 380 " let ind = ind - shiftwidth() |
375 if line =~ '^\s*)' | 381 if line =~ '^\s*)' |
376 " let ignore = ignore + 1 | 382 " let ignore = ignore + 1 |