2003-06-19 23:05:07 +04:00
|
|
|
" =============================================================================
|
2012-08-13 21:42:58 +04:00
|
|
|
"
|
2003-06-19 23:05:07 +04:00
|
|
|
" Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
" Module: $RCSfile$
|
2006-04-18 18:32:28 +04:00
|
|
|
" Language: VIM
|
2003-06-19 23:05:07 +04:00
|
|
|
" Date: $Date$
|
|
|
|
" Version: $Revision$
|
2012-08-13 21:42:58 +04:00
|
|
|
"
|
2003-06-19 23:05:07 +04:00
|
|
|
" =============================================================================
|
|
|
|
|
2003-06-19 22:37:58 +04:00
|
|
|
" Vim indent file
|
2006-04-13 05:24:15 +04:00
|
|
|
" Language: CMake (ft=cmake)
|
|
|
|
" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
|
2008-01-16 19:53:53 +03:00
|
|
|
" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
|
2006-04-13 05:24:15 +04:00
|
|
|
" Last Change: $Date$
|
|
|
|
" Version: $Revision$
|
2006-04-18 18:32:28 +04:00
|
|
|
"
|
|
|
|
" Licence: The CMake license applies to this file. See
|
|
|
|
" http://www.cmake.org/HTML/Copyright.html
|
|
|
|
" This implies that distribution with Vim is allowed
|
2003-06-19 22:37:58 +04:00
|
|
|
|
|
|
|
if exists("b:did_indent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal indentexpr=CMakeGetIndent(v:lnum)
|
2008-01-15 03:20:42 +03:00
|
|
|
setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
|
2003-06-19 22:37:58 +04:00
|
|
|
|
|
|
|
" 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
|
2006-04-22 00:33:35 +04:00
|
|
|
let cmake_indent_blank_regex = '^\s*$'
|
2003-06-19 22:37:58 +04:00
|
|
|
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 . '\)\?$'
|
|
|
|
|
2008-01-16 19:53:53 +03:00
|
|
|
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*('
|
2003-06-19 22:37:58 +04:00
|
|
|
|
|
|
|
" 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
|