1 " =============================================================================
3 " Program: CMake - Cross-Platform Makefile Generator
4 " Module: $RCSfile: cmake-indent.vim,v $
6 " Date: $Date: 2008-01-16 16:53:53 $
7 " Version: $Revision: 1.9 $
9 " =============================================================================
12 " Language: CMake (ft=cmake)
13 " Author: Andy Cedilnik <andy.cedilnik@kitware.com>
14 " Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
15 " Last Change: $Date: 2008-01-16 16:53:53 $
16 " Version: $Revision: 1.9 $
18 " Licence: The CMake license applies to this file. See
19 " http://www.cmake.org/HTML/Copyright.html
20 " This implies that distribution with Vim is allowed
22 if exists("b:did_indent")
27 setlocal indentexpr=CMakeGetIndent(v:lnum)
28 setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
30 " Only define the function once.
31 if exists("*CMakeGetIndent")
35 fun! CMakeGetIndent(lnum)
36 let this_line = getline(a:lnum)
38 " Find a non-blank line above the current line.
40 let lnum = prevnonblank(lnum - 1)
41 let previous_line = getline(lnum)
43 " Hit the start of the file, use zero indent.
48 let ind = indent(lnum)
51 " Regular expressions used by line indentation function.
52 let cmake_regex_comment = '#.*'
53 let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
54 let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
55 let cmake_regex_arguments = '\(' . cmake_regex_quoted .
56 \ or . '\$(' . cmake_regex_identifier . ')' .
57 \ or . '[^()\\#"]' . or . '\\.' . '\)*'
59 let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
60 let cmake_indent_blank_regex = '^\s*$'
61 let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
62 \ '\s*(' . cmake_regex_arguments .
63 \ '\(' . cmake_regex_comment . '\)\?$'
65 let cmake_indent_close_regex = '^' . cmake_regex_arguments .
67 \ '\(' . cmake_regex_comment . '\)\?$'
69 let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
70 let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
73 if previous_line =~? cmake_indent_comment_line " Handle comments
76 if previous_line =~? cmake_indent_begin_regex
79 if previous_line =~? cmake_indent_open_regex
85 if this_line =~? cmake_indent_end_regex
88 if previous_line =~? cmake_indent_close_regex