| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:     CMake (ft=cmake) | 
					
						
							|  |  |  | " Author:       Andy Cedilnik <andy.cedilnik@kitware.com> | 
					
						
							| 
									
										
										
										
											2017-09-19 22:06:03 +02:00
										 |  |  | " Maintainer:   Dimitri Merejkowsky <d.merej@gmail.com> | 
					
						
							|  |  |  | " Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> | 
					
						
							| 
									
										
										
										
											2017-09-27 22:23:55 +02:00
										 |  |  | " Last Change:  2017 Sep 24 | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | " | 
					
						
							|  |  |  | " Licence:      The CMake license applies to this file. See | 
					
						
							| 
									
										
										
										
											2017-09-19 22:06:03 +02:00
										 |  |  | "               https://cmake.org/licensing | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | "               This implies that distribution with Vim is allowed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setlocal indentexpr=CMakeGetIndent(v:lnum) | 
					
						
							| 
									
										
										
										
											2010-06-05 17:43:32 +02:00
										 |  |  | setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE( | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Only define the function once. | 
					
						
							|  |  |  | if exists("*CMakeGetIndent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2012-05-18 21:49:28 +02:00
										 |  |  | let s:keepcpo= &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | fun! CMakeGetIndent(lnum) | 
					
						
							|  |  |  |   let this_line = getline(a:lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " Find a non-blank line above the current line. | 
					
						
							|  |  |  |   let lnum = a:lnum | 
					
						
							|  |  |  |   let lnum = prevnonblank(lnum - 1) | 
					
						
							|  |  |  |   let previous_line = getline(lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " Hit the start of the file, use zero indent. | 
					
						
							|  |  |  |   if lnum == 0 | 
					
						
							|  |  |  |     return 0 | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let ind = indent(lnum) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let or = '\|' | 
					
						
							|  |  |  |   " Regular expressions used by line indentation function. | 
					
						
							|  |  |  |   let cmake_regex_comment = '#.*' | 
					
						
							|  |  |  |   let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*' | 
					
						
							|  |  |  |   let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"' | 
					
						
							|  |  |  |   let cmake_regex_arguments = '\(' . cmake_regex_quoted . | 
					
						
							|  |  |  |                     \       or . '\$(' . cmake_regex_identifier . ')' . | 
					
						
							|  |  |  |                     \       or . '[^()\\#"]' . or . '\\.' . '\)*' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let cmake_indent_comment_line = '^\s*' . cmake_regex_comment | 
					
						
							| 
									
										
										
										
											2006-04-21 22:12:41 +00:00
										 |  |  |   let cmake_indent_blank_regex = '^\s*$' | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  |   let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier . | 
					
						
							|  |  |  |                     \           '\s*(' . cmake_regex_arguments . | 
					
						
							|  |  |  |                     \           '\(' . cmake_regex_comment . '\)\?$' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let cmake_indent_close_regex = '^' . cmake_regex_arguments . | 
					
						
							|  |  |  |                     \            ')\s*' . | 
					
						
							|  |  |  |                     \            '\(' . cmake_regex_comment . '\)\?$' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-05 17:43:32 +02:00
										 |  |  |   let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*(' | 
					
						
							|  |  |  |   let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*(' | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   " Add | 
					
						
							|  |  |  |   if previous_line =~? cmake_indent_comment_line " Handle comments | 
					
						
							|  |  |  |     let ind = ind | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     if previous_line =~? cmake_indent_begin_regex | 
					
						
							| 
									
										
										
										
											2017-09-27 22:23:55 +02:00
										 |  |  |       let ind = ind + shiftwidth() | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  |     endif | 
					
						
							|  |  |  |     if previous_line =~? cmake_indent_open_regex | 
					
						
							| 
									
										
										
										
											2017-09-27 22:23:55 +02:00
										 |  |  |       let ind = ind + shiftwidth() | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  |     endif | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " Subtract | 
					
						
							|  |  |  |   if this_line =~? cmake_indent_end_regex | 
					
						
							| 
									
										
										
										
											2017-09-27 22:23:55 +02:00
										 |  |  |     let ind = ind - shiftwidth() | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  |   if previous_line =~? cmake_indent_close_regex | 
					
						
							| 
									
										
										
										
											2017-09-27 22:23:55 +02:00
										 |  |  |     let ind = ind - shiftwidth() | 
					
						
							| 
									
										
										
										
											2006-04-18 21:55:01 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ind | 
					
						
							|  |  |  | endfun | 
					
						
							| 
									
										
										
										
											2012-05-18 21:49:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | let &cpo = s:keepcpo | 
					
						
							|  |  |  | unlet s:keepcpo |