| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb) | 
					
						
							|  |  |  | " Author:	Johannes Zellner <johannes@zellner.org> | 
					
						
							| 
									
										
										
										
											2004-06-20 12:51:53 +00:00
										 |  |  | " Last Change:	Fri, 18 Jun 2004 07:22:42 CEST | 
					
						
							| 
									
										
										
										
											2010-07-28 12:52:27 +02:00
										 |  |  | "		Small update 2010 Jul 28 by Maxim Kim | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |     finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 20:58:01 +00:00
										 |  |  | setlocal autoindent | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | setlocal indentexpr=VbGetIndent(v:lnum) | 
					
						
							|  |  |  | setlocal indentkeys& | 
					
						
							| 
									
										
										
										
											2004-06-20 12:51:53 +00:00
										 |  |  | setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:> | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 20:58:01 +00:00
										 |  |  | let b:undo_indent = "set ai< indentexpr< indentkeys<" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Only define the function once. | 
					
						
							|  |  |  | if exists("*VbGetIndent") | 
					
						
							|  |  |  |     finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fun! VbGetIndent(lnum) | 
					
						
							|  |  |  |     " labels and preprocessor get zero indent immediately | 
					
						
							|  |  |  |     let this_line = getline(a:lnum) | 
					
						
							|  |  |  |     let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)' | 
					
						
							|  |  |  |     if this_line =~? LABELS_OR_PREPROC | 
					
						
							|  |  |  | 	return 0 | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Find a non-blank line above the current line. | 
					
						
							|  |  |  |     " Skip over labels and preprocessor directives. | 
					
						
							|  |  |  |     let lnum = a:lnum | 
					
						
							|  |  |  |     while lnum > 0 | 
					
						
							|  |  |  | 	let lnum = prevnonblank(lnum - 1) | 
					
						
							|  |  |  | 	let previous_line = getline(lnum) | 
					
						
							|  |  |  | 	if previous_line !~? LABELS_OR_PREPROC | 
					
						
							|  |  |  | 	    break | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  |     endwhile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Hit the start of the file, use zero indent. | 
					
						
							|  |  |  |     if lnum == 0 | 
					
						
							|  |  |  | 	return 0 | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let ind = indent(lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Add | 
					
						
							| 
									
										
										
										
											2010-07-29 20:43:36 +02:00
										 |  |  |     if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|enum\|with\)\>' | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | 	let ind = ind + shiftwidth() | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Subtract | 
					
						
							|  |  |  |     if this_line =~? '^\s*\<end\>\s\+\<select\>' | 
					
						
							|  |  |  | 	if previous_line !~? '^\s*\<select\>' | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | 	    let ind = ind - 2 * shiftwidth() | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	    " this case is for an empty 'select' -- 'end select' | 
					
						
							|  |  |  | 	    " (w/o any case statements) like: | 
					
						
							|  |  |  | 	    " | 
					
						
							|  |  |  | 	    " select case readwrite | 
					
						
							|  |  |  | 	    " end select | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | 	    let ind = ind - shiftwidth() | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	endif | 
					
						
							| 
									
										
										
										
											2010-07-28 12:52:27 +02:00
										 |  |  |     elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>' | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | 	let ind = ind - shiftwidth() | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     elseif this_line =~? '^\s*\<\(case\|default\)\>' | 
					
						
							|  |  |  | 	if previous_line !~? '^\s*\<select\>' | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | 	    let ind = ind - shiftwidth() | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	endif | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ind | 
					
						
							|  |  |  | endfun | 
					
						
							| 
									
										
										
										
											2010-07-28 12:52:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | " vim:sw=4 |