| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | "   Vim indent file | 
					
						
							|  |  |  | "   Language:	    Objective-C | 
					
						
							|  |  |  | "   Maintainer:	    Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> | 
					
						
							| 
									
										
										
										
											2022-04-08 17:45:08 +01:00
										 |  |  | "   Last Change:    2022 Apr 06 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Only load this indent file when no other was loaded. | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |     finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | setlocal cindent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Set the function to do the work. | 
					
						
							|  |  |  | setlocal indentexpr=GetObjCIndent() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 21:55:11 +02:00
										 |  |  | " To make a colon (:) suggest an indentation other than a goto/switch label, | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | setlocal indentkeys-=: | 
					
						
							|  |  |  | setlocal indentkeys+=<:> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-08 17:45:08 +01:00
										 |  |  | let b:undo_indent = "setl cin< inde< indk<" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Only define the function once. | 
					
						
							|  |  |  | if exists("*GetObjCIndent") | 
					
						
							|  |  |  |     finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function s:GetWidth(line, regexp) | 
					
						
							|  |  |  |     let end = matchend(a:line, a:regexp) | 
					
						
							|  |  |  |     let width = 0 | 
					
						
							|  |  |  |     let i = 0 | 
					
						
							|  |  |  |     while i < end | 
					
						
							|  |  |  | 	if a:line[i] != "\t" | 
					
						
							|  |  |  | 	    let width = width + 1 | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	    let width = width + &ts - (width % &ts) | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 	let i = i + 1 | 
					
						
							|  |  |  |     endwhile | 
					
						
							|  |  |  |     return width | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function s:LeadingWhiteSpace(line) | 
					
						
							|  |  |  |     let end = strlen(a:line) | 
					
						
							|  |  |  |     let width = 0 | 
					
						
							|  |  |  |     let i = 0 | 
					
						
							|  |  |  |     while i < end | 
					
						
							|  |  |  | 	let char = a:line[i] | 
					
						
							|  |  |  | 	if char != " " && char != "\t" | 
					
						
							|  |  |  | 	    break | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 	if char != "\t" | 
					
						
							|  |  |  | 	    let width = width + 1 | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	    let width = width + &ts - (width % &ts) | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 	let i = i + 1 | 
					
						
							|  |  |  |     endwhile | 
					
						
							|  |  |  |     return width | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetObjCIndent() | 
					
						
							|  |  |  |     let theIndent = cindent(v:lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let prev_line = getline(v:lnum - 1) | 
					
						
							|  |  |  |     let cur_line = getline(v:lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if prev_line !~# ":" || cur_line !~# ":" | 
					
						
							|  |  |  | 	return theIndent | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if prev_line !~# ";" | 
					
						
							|  |  |  | 	let prev_colon_pos = s:GetWidth(prev_line, ":") | 
					
						
							|  |  |  | 	let delta = s:GetWidth(cur_line, ":") - s:LeadingWhiteSpace(cur_line) | 
					
						
							|  |  |  | 	let theIndent = prev_colon_pos - delta | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return theIndent | 
					
						
							|  |  |  | endfunction |