robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f4acacdb53
master
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" ) 10finish 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" ) 20finish 21endif 22 23" Clean up a line of code by removing trailing '//' and '/* */' comments, and trimming 24" whitespace 25function ! s: Trim ( line ) 26return substitute ( substitute ( substitute ( a: line , '// .*' , '' , '' ), '/\* .* \*/' , '' , '' ), '^\s*\|\s*$' , '' , 'g' ) 27endfunction 28 29function ! s: GetQmlIndent () 30let num = v: lnum 31let line = s: Trim ( getline ( num )) 32 33let pnum = prevnonblank ( num - 1 ) 34if pnum == 0 35return 0 36endif 37let pline = s: Trim ( getline ( pnum )) 38 39let ind = indent ( pnum ) 40 41" bracket/brace/paren blocks 42if pline =~ '[{[(]$' 43let ind += shiftwidth () 44endif 45if line =~ '^[}\])]' 46let ind -= shiftwidth () 47endif 48 49" '/*' comments 50if pline =~ '^/\*.*\*/' 51" no indent for single-line form 52elseif pline =~ '^/\*' 53let ind += 1 54elseif pline =~ '^\*/' 55let ind -= 1 56endif 57 58return ind 59endfunction