1 " =============================================================================
3 " Program: CMake - Cross-Platform Makefile Generator
4 " Module: $RCSfile: cmake-indent.vim,v $
6 " Date: $Date: 2006/09/23 21:09:08 $
7 " Version: $Revision: 1.7 $
9 " =============================================================================
12 " Language: CMake (ft=cmake)
13 " Author: Andy Cedilnik <andy.cedilnik@kitware.com>
14 " Maintainer: Andy Cedilnik <andy.cedilnik@kitware.com>
15 " Last Change: $Date: 2006/09/23 21:09:08 $
16 " Version: $Revision: 1.7 $
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)
29 " Only define the function once.
30 if exists("*CMakeGetIndent")
34 fun! CMakeGetIndent(lnum)
35 let this_line = getline(a:lnum)
37 " Find a non-blank line above the current line.
39 let lnum = prevnonblank(lnum - 1)
40 let previous_line = getline(lnum)
42 " Hit the start of the file, use zero indent.
47 let ind = indent(lnum)
50 " Regular expressions used by line indentation function.
51 let cmake_regex_comment = '#.*'
52 let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
53 let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
54 let cmake_regex_arguments = '\(' . cmake_regex_quoted .
55 \ or . '\$(' . cmake_regex_identifier . ')' .
56 \ or . '[^()\\#"]' . or . '\\.' . '\)*'
58 let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
59 let cmake_indent_blank_regex = '^\s*$'
60 let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
61 \ '\s*(' . cmake_regex_arguments .
62 \ '\(' . cmake_regex_comment . '\)\?$'
64 let cmake_indent_close_regex = '^' . cmake_regex_arguments .
66 \ '\(' . cmake_regex_comment . '\)\?$'
68 let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\)\s*('
69 let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\)\s*('
72 if previous_line =~? cmake_indent_comment_line " Handle comments
75 if previous_line =~? cmake_indent_begin_regex
78 if previous_line =~? cmake_indent_open_regex
84 if this_line =~? cmake_indent_end_regex
87 if previous_line =~? cmake_indent_close_regex