Mercurial > vim
annotate runtime/indent/cmake.vim @ 14491:9df0fcbfebb2 v8.1.0259
patch 8.1.0259: no test for fixed quickfix issue
commit https://github.com/vim/vim/commit/3f347e4716c44cf6458be407e712e3d708d82580
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 9 21:19:20 2018 +0200
patch 8.1.0259: no test for fixed quickfix issue
Problem: No test for fixed quickfix issue.
Solution: Add a test. Clean up the code a bit. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 09 Aug 2018 21:30:05 +0200 |
parents | 34c8ec888122 |
children | 6dd88e45d47d |
rev | line source |
---|---|
836 | 1 " Vim indent file |
2 " Language: CMake (ft=cmake) | |
3 " Author: Andy Cedilnik <andy.cedilnik@kitware.com> | |
12499 | 4 " Maintainer: Dimitri Merejkowsky <d.merej@gmail.com> |
5 " Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> | |
12559 | 6 " Last Change: 2017 Sep 24 |
836 | 7 " |
8 " Licence: The CMake license applies to this file. See | |
12499 | 9 " https://cmake.org/licensing |
836 | 10 " This implies that distribution with Vim is allowed |
11 | |
12 if exists("b:did_indent") | |
13 finish | |
14 endif | |
15 let b:did_indent = 1 | |
16 | |
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 | 19 |
20 " Only define the function once. | |
21 if exists("*CMakeGetIndent") | |
22 finish | |
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 | 26 |
27 fun! CMakeGetIndent(lnum) | |
28 let this_line = getline(a:lnum) | |
29 | |
30 " Find a non-blank line above the current line. | |
31 let lnum = a:lnum | |
32 let lnum = prevnonblank(lnum - 1) | |
33 let previous_line = getline(lnum) | |
34 | |
35 " Hit the start of the file, use zero indent. | |
36 if lnum == 0 | |
37 return 0 | |
38 endif | |
39 | |
40 let ind = indent(lnum) | |
41 | |
42 let or = '\|' | |
43 " Regular expressions used by line indentation function. | |
44 let cmake_regex_comment = '#.*' | |
45 let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*' | |
46 let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"' | |
47 let cmake_regex_arguments = '\(' . cmake_regex_quoted . | |
48 \ or . '\$(' . cmake_regex_identifier . ')' . | |
49 \ or . '[^()\\#"]' . or . '\\.' . '\)*' | |
50 | |
51 let cmake_indent_comment_line = '^\s*' . cmake_regex_comment | |
839 | 52 let cmake_indent_blank_regex = '^\s*$' |
836 | 53 let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier . |
54 \ '\s*(' . cmake_regex_arguments . | |
55 \ '\(' . cmake_regex_comment . '\)\?$' | |
56 | |
57 let cmake_indent_close_regex = '^' . cmake_regex_arguments . | |
58 \ ')\s*' . | |
59 \ '\(' . cmake_regex_comment . '\)\?$' | |
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 | 63 |
64 " Add | |
65 if previous_line =~? cmake_indent_comment_line " Handle comments | |
66 let ind = ind | |
67 else | |
68 if previous_line =~? cmake_indent_begin_regex | |
12559 | 69 let ind = ind + shiftwidth() |
836 | 70 endif |
71 if previous_line =~? cmake_indent_open_regex | |
12559 | 72 let ind = ind + shiftwidth() |
836 | 73 endif |
74 endif | |
75 | |
76 " Subtract | |
77 if this_line =~? cmake_indent_end_regex | |
12559 | 78 let ind = ind - shiftwidth() |
836 | 79 endif |
80 if previous_line =~? cmake_indent_close_regex | |
12559 | 81 let ind = ind - shiftwidth() |
836 | 82 endif |
83 | |
84 return ind | |
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 |