annotate runtime/indent/cmake.vim @ 22209:825fb261b141

Added tag v8.2.1653 for changeset a607f02fd17a8b2c6814b1973c0f2433dfc54d15
author Bram Moolenaar <Bram@vim.org>
date Thu, 10 Sep 2020 19:30:06 +0200
parents 34c8ec888122
children 6dd88e45d47d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
1 " Vim indent file
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
2 " Language: CMake (ft=cmake)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
3 " Author: Andy Cedilnik <andy.cedilnik@kitware.com>
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
4 " Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
5 " Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
6 " Last Change: 2017 Sep 24
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
7 "
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
8 " Licence: The CMake license applies to this file. See
12499
d91cf2e26ef0 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
9 " https://cmake.org/licensing
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
10 " This implies that distribution with Vim is allowed
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
11
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
12 if exists("b:did_indent")
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
13 finish
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
14 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
15 let b:did_indent = 1
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
16
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
17 setlocal indentexpr=CMakeGetIndent(v:lnum)
2249
6d3d35ff2c2b Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
18 setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
19
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
20 " Only define the function once.
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
21 if exists("*CMakeGetIndent")
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
22 finish
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
23 endif
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2249
diff changeset
24 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2249
diff changeset
25 set cpo&vim
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
26
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
27 fun! CMakeGetIndent(lnum)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
28 let this_line = getline(a:lnum)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
29
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
30 " Find a non-blank line above the current line.
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
31 let lnum = a:lnum
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
32 let lnum = prevnonblank(lnum - 1)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
33 let previous_line = getline(lnum)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
34
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
35 " Hit the start of the file, use zero indent.
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
36 if lnum == 0
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
37 return 0
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
38 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
39
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
40 let ind = indent(lnum)
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
41
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
42 let or = '\|'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
43 " Regular expressions used by line indentation function.
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
44 let cmake_regex_comment = '#.*'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
45 let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
46 let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
47 let cmake_regex_arguments = '\(' . cmake_regex_quoted .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
48 \ or . '\$(' . cmake_regex_identifier . ')' .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
49 \ or . '[^()\\#"]' . or . '\\.' . '\)*'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
50
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
51 let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 836
diff changeset
52 let cmake_indent_blank_regex = '^\s*$'
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
53 let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
54 \ '\s*(' . cmake_regex_arguments .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
55 \ '\(' . cmake_regex_comment . '\)\?$'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
56
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
57 let cmake_indent_close_regex = '^' . cmake_regex_arguments .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
58 \ ')\s*' .
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
59 \ '\(' . cmake_regex_comment . '\)\?$'
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
60
2249
6d3d35ff2c2b Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
61 let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
6d3d35ff2c2b Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
62 let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
63
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
64 " Add
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
65 if previous_line =~? cmake_indent_comment_line " Handle comments
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
66 let ind = ind
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
67 else
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
68 if previous_line =~? cmake_indent_begin_regex
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
69 let ind = ind + shiftwidth()
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
70 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
71 if previous_line =~? cmake_indent_open_regex
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
72 let ind = ind + shiftwidth()
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
73 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
74 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
75
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
76 " Subtract
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
77 if this_line =~? cmake_indent_end_regex
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
78 let ind = ind - shiftwidth()
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
79 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
80 if previous_line =~? cmake_indent_close_regex
12559
34c8ec888122 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 12499
diff changeset
81 let ind = ind - shiftwidth()
836
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
82 endif
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
83
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
84 return ind
5a7843c57316 updated for version 7.0e02
vimboss
parents:
diff changeset
85 endfun
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2249
diff changeset
86
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2249
diff changeset
87 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2249
diff changeset
88 unlet s:keepcpo