summaryrefslogtreecommitdiffstats
path: root/Auxiliary/cmake-indent.vim
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-09-23 18:30:25 (GMT)
committerBrad King <brad.king@kitware.com>2013-10-15 14:46:54 (GMT)
commitb601e2350afa89e592c4a601b08f8c74728d1ae3 (patch)
tree24db537acd620a356e1daf25d9e2d050d50f382d /Auxiliary/cmake-indent.vim
parent07b80021aad97a4f4243e97576bae4670114a3ca (diff)
downloadCMake-b601e2350afa89e592c4a601b08f8c74728d1ae3.zip
CMake-b601e2350afa89e592c4a601b08f8c74728d1ae3.tar.gz
CMake-b601e2350afa89e592c4a601b08f8c74728d1ae3.tar.bz2
Rename Docs to Auxiliary
The directory contains auxiliary support files for integration with other tools, not documentation.
Diffstat (limited to 'Auxiliary/cmake-indent.vim')
-rw-r--r--Auxiliary/cmake-indent.vim93
1 files changed, 93 insertions, 0 deletions
diff --git a/Auxiliary/cmake-indent.vim b/Auxiliary/cmake-indent.vim
new file mode 100644
index 0000000..a26dd06
--- /dev/null
+++ b/Auxiliary/cmake-indent.vim
@@ -0,0 +1,93 @@
+" =============================================================================
+"
+" Program: CMake - Cross-Platform Makefile Generator
+" Module: $RCSfile$
+" Language: VIM
+" Date: $Date$
+" Version: $Revision$
+"
+" =============================================================================
+
+" Vim indent file
+" Language: CMake (ft=cmake)
+" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
+" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: $Date$
+" Version: $Revision$
+"
+" Licence: The CMake license applies to this file. See
+" http://www.cmake.org/HTML/Copyright.html
+" 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)
+setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
+
+" Only define the function once.
+if exists("*CMakeGetIndent")
+ finish
+endif
+
+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
+ let cmake_indent_blank_regex = '^\s*$'
+ 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 . '\)\?$'
+
+ 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*('
+
+ " Add
+ if previous_line =~? cmake_indent_comment_line " Handle comments
+ let ind = ind
+ else
+ if previous_line =~? cmake_indent_begin_regex
+ let ind = ind + &sw
+ endif
+ if previous_line =~? cmake_indent_open_regex
+ let ind = ind + &sw
+ endif
+ endif
+
+ " Subtract
+ if this_line =~? cmake_indent_end_regex
+ let ind = ind - &sw
+ endif
+ if previous_line =~? cmake_indent_close_regex
+ let ind = ind - &sw
+ endif
+
+ return ind
+endfun