Mercurial > hg > RemoteEditor > vim7
comparison runtime/indent/sqlanywhere.vim @ 34:e170173ecb68 current-release
before ack base protocol.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 26 Nov 2008 15:02:10 +0900 |
parents | 76efa0be13f1 |
children | 67300faee616 |
comparison
equal
deleted
inserted
replaced
33:7d0d8b831f5a | 34:e170173ecb68 |
---|---|
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: Mon Apr 02 2007 9:13:47 AM |
5 " Version: 1.4 | 5 " Version: 1.5 |
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 |
104 endif | 104 endif |
105 let vircol = virtcol(".") | 105 let vircol = virtcol(".") |
106 | 106 |
107 " if getline(".") =~ '^)' | 107 " if getline(".") =~ '^)' |
108 let matching_paran = searchpair('(', '', ')', 'bW', | 108 let matching_paran = searchpair('(', '', ')', 'bW', |
109 \ 'IsColComment(line("."), col("."))') | 109 \ 's:IsColComment(line("."), col("."))') |
110 | 110 |
111 if matching_paran < 1 | 111 if matching_paran < 1 |
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 |
163 \ '\%(\%(\<end\s\+\)\@<!\<case\>\)\|' . | 163 \ '\%(\%(\<end\s\+\)\@<!\<case\>\)\|' . |
164 \ '\%(\%(\<end\s\+\)\@<!\<for\>\)\|' . | 164 \ '\%(\%(\<end\s\+\)\@<!\<for\>\)\|' . |
165 \ '\%(\%(\<end\s\+\)\@<!\<if\>\)'. | 165 \ '\%(\%(\<end\s\+\)\@<!\<if\>\)'. |
166 \ '\)' | 166 \ '\)' |
167 let matching_lnum = searchpair(stmts, '', '\<end\>\zs', 'bW', | 167 let matching_lnum = searchpair(stmts, '', '\<end\>\zs', 'bW', |
168 \ 'IsColComment(line("."), col(".")) == 1') | 168 \ 's:IsColComment(line("."), col(".")) == 1') |
169 exec 'normal! $' | 169 exec 'normal! $' |
170 if matching_lnum > 0 && matching_lnum < a:curr_lnum | 170 if matching_lnum > 0 && matching_lnum < a:curr_lnum |
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' |
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 \ 's: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) |
184 else | 184 else |
185 let ind = indent(a:curr_lnum) | 185 let ind = indent(a:curr_lnum) |
189 return ind | 189 return ind |
190 endfunction | 190 endfunction |
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 s: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" |
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 s: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 " Instead of returning a column position, return |
215 function ModuloIndent(ind) | 215 " an appropriate value as a factor of shiftwidth. |
216 function s:ModuloIndent(ind) | |
216 let ind = a:ind | 217 let ind = a:ind |
217 | 218 |
218 if ind > 0 | 219 if ind > 0 |
219 let modulo = ind % &shiftwidth | 220 let modulo = ind % &shiftwidth |
220 | 221 |
233 let ind = indent(lnum) | 234 let ind = indent(lnum) |
234 | 235 |
235 " If the current line is a comment, leave the indent as is | 236 " If the current line is a comment, leave the indent as is |
236 " Comment out this additional check since it affects the | 237 " Comment out this additional check since it affects the |
237 " indenting of =, and will not reindent comments as it should | 238 " indenting of =, and will not reindent comments as it should |
238 " if IsLineComment(lnum) == 1 | 239 " if s:IsLineComment(lnum) == 1 |
239 " return ind | 240 " return ind |
240 " endif | 241 " endif |
241 | 242 |
242 " while 1 | 243 " while 1 |
243 " Get previous non-blank line | 244 " Get previous non-blank line |
244 let prevlnum = prevnonblank(lnum - 1) | 245 let prevlnum = prevnonblank(lnum - 1) |
245 if prevlnum <= 0 | 246 if prevlnum <= 0 |
246 return ind | 247 return ind |
247 endif | 248 endif |
248 | 249 |
249 if IsLineComment(prevlnum) == 1 | 250 if s:IsLineComment(prevlnum) == 1 |
250 if getline(v:lnum) =~ '^\s*\*' | 251 if getline(v:lnum) =~ '^\s*\*' |
251 let ind = ModuloIndent(indent(prevlnum)) | 252 let ind = s:ModuloIndent(indent(prevlnum)) |
252 return ind + 1 | 253 return ind + 1 |
253 endif | 254 endif |
254 " If the previous line is a comment, then return -1 | 255 " If the previous line is a comment, then return -1 |
255 " to tell Vim to use the formatoptions setting to determine | 256 " to tell Vim to use the formatoptions setting to determine |
256 " the indent to use | 257 " the indent to use |
376 endif | 377 endif |
377 " endif | 378 " endif |
378 endif | 379 endif |
379 | 380 |
380 " echom 'final - indent ' . ind | 381 " echom 'final - indent ' . ind |
381 return ModuloIndent(ind) | 382 return s:ModuloIndent(ind) |
382 endfunction | 383 endfunction |
383 | 384 |
384 " vim:sw=4:ff=unix: | 385 " vim:sw=4: |