robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:50dbe16cd818f4acacdb53

master
1.3 KiB59 linesraw
1" Vim indent file
2" Language:     QML
3" Maintainer:   Chase Knowlden <haroldknowlden@gmail.com>
4" Last Change:  2024 Jan 24 by Vim Project
5"
6" Improved JavaScript indent script.
7
8" Indent script in place for this already?
9if exists("b:did_indent")
10  finish
11endif
12let b:did_indent = 1
13let b:undo_indent = "setlocal indentexpr< indentkeys<"
14
15setlocal indentexpr=s:GetQmlIndent()
16setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e,*<Return>,=*/
17
18" Only define functions once per session
19if exists("*s:GetQmlIndent")
20  finish
21endif
22
23" Clean up a line of code by removing trailing '//' and '/* */' comments, and trimming
24" whitespace
25function! s:Trim(line)
26  return substitute(substitute(substitute(a:line, '// .*', '', ''), '/\* .* \*/', '', ''), '^\s*\|\s*$', '', 'g')
27endfunction
28
29function! 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 += shiftwidth()
44  endif
45  if line =~ '^[}\])]'
46    let ind -= shiftwidth()
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
59endfunction