Introduce "generator expressions" to add_test()
[cmake.git] / Docs / cmake-indent.vim
blob6c5d3340f79bb98e4547603048b79e72f30db63c
1 " =============================================================================
2
3 "   Program:   CMake - Cross-Platform Makefile Generator
4 "   Module:    $RCSfile: cmake-indent.vim,v $
5 "   Language:  VIM
6 "   Date:      $Date: 2008-01-16 16:53:53 $
7 "   Version:   $Revision: 1.9 $
8
9 " =============================================================================
11 " Vim indent file
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")
23   finish
24 endif
25 let b:did_indent = 1
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")
32   finish
33 endif
35 fun! CMakeGetIndent(lnum)
36   let this_line = getline(a:lnum)
38   " Find a non-blank line above the current line.
39   let lnum = a:lnum
40   let lnum = prevnonblank(lnum - 1)
41   let previous_line = getline(lnum)
43   " Hit the start of the file, use zero indent.
44   if lnum == 0
45     return 0
46   endif
48   let ind = indent(lnum)
50   let or = '\|'
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 .
66                     \            ')\s*' .
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*('
72   " Add
73   if previous_line =~? cmake_indent_comment_line " Handle comments
74     let ind = ind
75   else
76     if previous_line =~? cmake_indent_begin_regex
77       let ind = ind + &sw
78     endif
79     if previous_line =~? cmake_indent_open_regex
80       let ind = ind + &sw
81     endif
82   endif
84   " Subtract
85   if this_line =~? cmake_indent_end_regex
86     let ind = ind - &sw
87   endif
88   if previous_line =~? cmake_indent_close_regex
89     let ind = ind - &sw
90   endif
92   return ind
93 endfun