diff options
author | Bram Moolenaar <Bram@vim.org> | 2006-04-18 21:55:01 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2006-04-18 21:55:01 +0000 |
commit | c1e37901fc8486c9960d7290e521ba51e292e94b (patch) | |
tree | 5367e8f83d9d313dd73c0499fd310f57df5e605f /runtime/indent | |
parent | a93fa7ee7856b54d3778e613c7b7e4b76aaeb2af (diff) |
updated for version 7.0e02v7.0e02
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/cmake.vim | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/runtime/indent/cmake.vim b/runtime/indent/cmake.vim new file mode 100644 index 0000000000..e36937df5b --- /dev/null +++ b/runtime/indent/cmake.vim @@ -0,0 +1,92 @@ +" ============================================================================= +" +" 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: Andy Cedilnik <andy.cedilnik@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) + +" 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 |