comparison runtime/indent/sqlanywhere.vim @ 3996:b3f3237a3d72

Update runtime files.
author Bram Moolenaar <bram@vim.org>
date Wed, 05 Dec 2012 19:01:43 +0100
parents dd6c2497c997
children e362db8b2d7b
comparison
equal deleted inserted replaced
3995:c2ea289a5b7f 3996:b3f3237a3d72
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 <dfishburn dot vim at gmail dot com>
4 " Last Change: Mon Apr 02 2007 9:13:47 AM 4 " Last Change: 2012 Dec 05
5 " Version: 1.5 5 " Version: 3.0
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
16 " indenting more difficult. 16 " indenting more difficult.
17 " 17 "
18 " Known Issues: 18 " Known Issues:
19 " The Oracle MERGE statement does not have an end tag associated with 19 " The Oracle MERGE statement does not have an end tag associated with
20 " it, this can leave the indent hanging to the right one too many. 20 " it, this can leave the indent hanging to the right one too many.
21 "
22 " History:
23 " 3.0 (Dec 2012)
24 " Added cpo check
25 "
26 " 2.0
27 " Added the FOR keyword to SQLBlockStart to handle (Alec Tica):
28 " for i in 1..100 loop
29 " |<-- I expect to have indentation here
30 " end loop;
31 "
21 32
22 " Only load this indent file when no other was loaded. 33 " Only load this indent file when no other was loaded.
23 if exists("b:did_indent") 34 if exists("b:did_indent")
24 finish 35 finish
25 endif 36 endif
26 let b:did_indent = 1 37 let b:did_indent = 1
27 let b:current_indent = "sqlanywhere" 38 let b:current_indent = "sqlanywhere"
39 let s:keepcpo= &cpo
40 set cpo&vim
28 41
29 setlocal indentkeys-=0{ 42 setlocal indentkeys-=0{
30 setlocal indentkeys-=0} 43 setlocal indentkeys-=0}
31 setlocal indentkeys-=: 44 setlocal indentkeys-=:
32 setlocal indentkeys-=0# 45 setlocal indentkeys-=0#
42 55
43 " GetSQLIndent is executed whenever one of the expressions 56 " GetSQLIndent is executed whenever one of the expressions
44 " in the indentkeys is typed 57 " in the indentkeys is typed
45 setlocal indentexpr=GetSQLIndent() 58 setlocal indentexpr=GetSQLIndent()
46 59
47 " Only define the functions once.
48 if exists("*GetSQLIndent")
49 finish
50 endif
51 let s:keepcpo= &cpo
52 set cpo&vim
53
54 " List of all the statements that start a new block. 60 " List of all the statements that start a new block.
55 " These are typically words that start a line. 61 " These are typically words that start a line.
56 " IS is excluded, since it is difficult to determine when the 62 " IS is excluded, since it is difficult to determine when the
57 " ending block is (especially for procedures/functions). 63 " ending block is (especially for procedures/functions).
58 let s:SQLBlockStart = '^\s*\%('. 64 let s:SQLBlockStart = '^\s*\%('.
59 \ 'if\|else\|elseif\|elsif\|'. 65 \ 'if\|else\|elseif\|elsif\|'.
60 \ 'while\|loop\|do\|'. 66 \ 'while\|loop\|do\|for\|'.
61 \ 'begin\|'. 67 \ 'begin\|'.
62 \ 'case\|when\|merge\|exception'. 68 \ 'case\|when\|merge\|exception'.
63 \ '\)\>' 69 \ '\)\>'
64 let s:SQLBlockEnd = '^\s*\(end\)\>' 70 let s:SQLBlockEnd = '^\s*\(end\)\>'
65 71
66 " The indent level is also based on unmatched paranethesis 72 " The indent level is also based on unmatched paranethesis
67 " If a line has an extra "(" increase the indent 73 " If a line has an extra "(" increase the indent
68 " If a line has an extra ")" decrease the indent 74 " If a line has an extra ")" decrease the indent
69 function s:CountUnbalancedParan( line, paran_to_check ) 75 function! s:CountUnbalancedParan( line, paran_to_check )
70 let l = a:line 76 let l = a:line
71 let lp = substitute(l, '[^(]', '', 'g') 77 let lp = substitute(l, '[^(]', '', 'g')
72 let l = a:line 78 let l = a:line
73 let rp = substitute(l, '[^)]', '', 'g') 79 let rp = substitute(l, '[^)]', '', 'g')
74 80
86 return 0 92 return 0
87 endif 93 endif
88 endfunction 94 endfunction
89 95
90 " Unindent commands based on previous indent level 96 " Unindent commands based on previous indent level
91 function s:CheckToIgnoreRightParan( prev_lnum, num_levels ) 97 function! s:CheckToIgnoreRightParan( prev_lnum, num_levels )
92 let lnum = a:prev_lnum 98 let lnum = a:prev_lnum
93 let line = getline(lnum) 99 let line = getline(lnum)
94 let ends = 0 100 let ends = 0
95 let num_right_paran = a:num_levels 101 let num_right_paran = a:num_levels
96 let ignore_paran = 0 102 let ignore_paran = 0
149 " EXCEPTION .. 155 " EXCEPTION ..
150 " WHEN ... 156 " WHEN ...
151 " something; 157 " something;
152 " WHEN ... 158 " WHEN ...
153 " Should return indent level of exception. 159 " Should return indent level of exception.
154 function s:GetStmtStarterIndent( keyword, curr_lnum ) 160 function! s:GetStmtStarterIndent( keyword, curr_lnum )
155 let lnum = a:curr_lnum 161 let lnum = a:curr_lnum
156 162
157 " Default - reduce indent by 1 163 " Default - reduce indent by 1
158 let ind = indent(a:curr_lnum) - &sw 164 let ind = indent(a:curr_lnum) - &sw
159 165
191 return ind 197 return ind
192 endfunction 198 endfunction
193 199
194 200
195 " Check if the line is a comment 201 " Check if the line is a comment
196 function s:IsLineComment(lnum) 202 function! s:IsLineComment(lnum)
197 let rc = synIDattr( 203 let rc = synIDattr(
198 \ synID(a:lnum, 204 \ synID(a:lnum,
199 \ match(getline(a:lnum), '\S')+1, 0) 205 \ match(getline(a:lnum), '\S')+1, 0)
200 \ , "name") 206 \ , "name")
201 \ =~? "comment" 207 \ =~? "comment"
203 return rc 209 return rc
204 endfunction 210 endfunction
205 211
206 212
207 " Check if the column is a comment 213 " Check if the column is a comment
208 function s:IsColComment(lnum, cnum) 214 function! s:IsColComment(lnum, cnum)
209 let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name") 215 let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name")
210 \ =~? "comment" 216 \ =~? "comment"
211 217
212 return rc 218 return rc
213 endfunction 219 endfunction
214 220
215 221
216 " Instead of returning a column position, return 222 " Instead of returning a column position, return
217 " an appropriate value as a factor of shiftwidth. 223 " an appropriate value as a factor of shiftwidth.
218 function s:ModuloIndent(ind) 224 function! s:ModuloIndent(ind)
219 let ind = a:ind 225 let ind = a:ind
220 226
221 if ind > 0 227 if ind > 0
222 let modulo = ind % &shiftwidth 228 let modulo = ind % &shiftwidth
223 229
229 return ind 235 return ind
230 endfunction 236 endfunction
231 237
232 238
233 " Find correct indent of a new line based upon the previous line 239 " Find correct indent of a new line based upon the previous line
234 function GetSQLIndent() 240 function! GetSQLIndent()
235 let lnum = v:lnum 241 let lnum = v:lnum
236 let ind = indent(lnum) 242 let ind = indent(lnum)
237 243
238 " If the current line is a comment, leave the indent as is 244 " If the current line is a comment, leave the indent as is
239 " Comment out this additional check since it affects the 245 " Comment out this additional check since it affects the
240 " indenting of =, and will not reindent comments as it should 246 " indenting of =, and will not reindent comments as it should
241 " if s:IsLineComment(lnum) == 1 247 " if s:IsLineComment(lnum) == 1
242 " return ind 248 " return ind
243 " endif 249 " endif
244 250
245 " while 1 251 " Get previous non-blank line
246 " Get previous non-blank line 252 let prevlnum = prevnonblank(lnum - 1)
247 let prevlnum = prevnonblank(lnum - 1) 253 if prevlnum <= 0
248 if prevlnum <= 0 254 return ind
249 return ind 255 endif
250 endif 256
251 257 if s:IsLineComment(prevlnum) == 1
252 if s:IsLineComment(prevlnum) == 1 258 if getline(v:lnum) =~ '^\s*\*'
253 if getline(v:lnum) =~ '^\s*\*' 259 let ind = s:ModuloIndent(indent(prevlnum))
254 let ind = s:ModuloIndent(indent(prevlnum)) 260 return ind + 1
255 return ind + 1 261 endif
256 endif 262 " If the previous line is a comment, then return -1
257 " If the previous line is a comment, then return -1 263 " to tell Vim to use the formatoptions setting to determine
258 " to tell Vim to use the formatoptions setting to determine 264 " the indent to use
259 " the indent to use 265 " But only if the next line is blank. This would be true if
260 " But only if the next line is blank. This would be true if 266 " the user is typing, but it would not be true if the user
261 " the user is typing, but it would not be true if the user 267 " is reindenting the file
262 " is reindenting the file 268 if getline(v:lnum) =~ '^\s*$'
263 if getline(v:lnum) =~ '^\s*$' 269 return -1
264 return -1 270 endif
265 endif 271 endif
266 endif
267
268 " let prevline = getline(prevlnum)
269 " if prevline !~ '^\s*$'
270 " " echom 'previous non blank - break: ' . prevline
271 " break
272 " endif
273 " endwhile
274 272
275 " echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum) 273 " echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum)
276 274
277 " This is the line you just hit return on, it is not the current line 275 " This is the line you just hit return on, it is not the current line
278 " which is new and empty 276 " which is new and empty
382 380
383 " echom 'final - indent ' . ind 381 " echom 'final - indent ' . ind
384 return s:ModuloIndent(ind) 382 return s:ModuloIndent(ind)
385 endfunction 383 endfunction
386 384
387 let &cpo = s:keepcpo 385 " Restore:
386 let &cpo= s:keepcpo
388 unlet s:keepcpo 387 unlet s:keepcpo
389 388 " vim: ts=4 fdm=marker sw=4
390 " vim:sw=4: