Mercurial > vim
comparison runtime/indent/qml.vim @ 32942:f2143ef2e979 v9.0.1766
patch 9.0.1766: Runtime: Missing QML support
Problem: Runtime: Missing QML support
Solution: Add QML support to Vim
closes: #12810
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: ChaseKnowlden <haroldknowlden@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Aug 2023 21:59:22 +0200 |
parents | |
children | c781be83e11e |
comparison
equal
deleted
inserted
replaced
32941:83cd5e9a5f91 | 32942:f2143ef2e979 |
---|---|
1 " Vim indent file | |
2 " Language: QML | |
3 " Maintainer: Chase Knowlden <haroldknowlden@gmail.com> | |
4 " Last Change: 2023 Aug 16 | |
5 " | |
6 " Improved JavaScript indent script. | |
7 | |
8 " Indent script in place for this already? | |
9 if exists("b:did_indent") | |
10 finish | |
11 endif | |
12 let b:did_indent = 1 | |
13 let b:undo_indent = "setlocal indentexpr< indentkeys<" | |
14 | |
15 setlocal indentexpr=s:GetQmlIndent() | |
16 setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e,*<Return>,=*/ | |
17 | |
18 " Only define functions once per session | |
19 if exists("*s:GetQmlIndent") | |
20 finish | |
21 endif | |
22 | |
23 " Clean up a line of code by removing trailing '//' and '/* */' comments, and trimming | |
24 " whitespace | |
25 function! s:Trim(line) | |
26 return substitute(substitute(substitute(a:line, '// .*', '', ''), '/\* .* \*/', '', ''), '^\s*\|\s*$', '', 'g') | |
27 endfunction | |
28 | |
29 function! s:GetQmlIndent() | |
30 let num = v:lnum | |
31 let line = s:Trim(getline(num)) | |
32 | |
33 let pnum = prevnonblank(num - 1) | |
34 if pnum == 0 | |
35 return 0 | |
36 endif | |
37 let pline = s:Trim(getline(pnum)) | |
38 | |
39 let ind = indent(pnum) | |
40 | |
41 " bracket/brace/paren blocks | |
42 if pline =~ '[{[(]$' | |
43 let ind += &sw | |
44 endif | |
45 if line =~ '^[}\])]' | |
46 let ind -= &sw | |
47 endif | |
48 | |
49 " '/*' comments | |
50 if pline =~ '^/\*.*\*/' | |
51 " no indent for single-line form | |
52 elseif pline =~ '^/\*' | |
53 let ind += 1 | |
54 elseif pline =~ '^\*/' | |
55 let ind -= 1 | |
56 endif | |
57 | |
58 return ind | |
59 endfunction |