diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2003-06-19 18:37:58 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2003-06-19 18:37:58 (GMT) |
commit | 40fad5b2e830f8e1995b772563528aa578cc8b1e (patch) | |
tree | 399f2a0b3f0cd40d946e382fee3224a6dd120420 /Docs/cmake-indent.vim | |
parent | f5c2801931bc5f0aaa7d5d2f187d0cadbca36bdb (diff) | |
download | CMake-40fad5b2e830f8e1995b772563528aa578cc8b1e.zip CMake-40fad5b2e830f8e1995b772563528aa578cc8b1e.tar.gz CMake-40fad5b2e830f8e1995b772563528aa578cc8b1e.tar.bz2 |
Initial import: indentation file for vim
Diffstat (limited to 'Docs/cmake-indent.vim')
-rw-r--r-- | Docs/cmake-indent.vim | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Docs/cmake-indent.vim b/Docs/cmake-indent.vim new file mode 100644 index 0000000..8d8438a --- /dev/null +++ b/Docs/cmake-indent.vim @@ -0,0 +1,77 @@ +" Vim indent file +" Language: CMake (ft=cmake) +" Author: Andy Cedilnik <andy.cedilnik@kitware.com> +" URL: http://www.cmake.org +" Last Change: Sun Mar 23 15:41:55 EST 2003 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=CMakeGetIndent(v:lnum) + +" 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\)\s*(' + let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\)\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 |