robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3222f0ad00
master
1" Vim indent file 2" Language: Kuka Robot Language 3" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de> 4" Version: 3.0.0 5" Last Change: 15. Apr 2022 6" Credits: Based on indent/vim.vim 7 8" Only load this indent file when no other was loaded. 9if exists ( "b:did_indent" ) 10finish 11endif 12let b: did_indent = 1 13 14setlocal nolisp 15setlocal nocindent 16setlocal nosmartindent 17setlocal autoindent 18setlocal indentexpr = GetKrlIndent () 19setlocal indentkeys = !^F,o,O,=~end,0=~else,0=~case,0=~default,0=~until,0=~continue,=~part 20let b: undo_indent = "setlocal lisp< cindent< smartindent< autoindent< indentexpr< indentkeys<" 21 22if get ( g:, 'krlSpaceIndent' , 1 ) 23" Use spaces, not tabs, for indention, 2 is enough. 24" More or even tabs would waste valuable space on the teach pendant. 25setlocal softtabstop = 2 26setlocal shiftwidth = 2 27setlocal expandtab 28setlocal shiftround 29let b: undo_indent = b: undo_indent . " softtabstop< shiftwidth< expandtab< shiftround<" 30endif 31 32" Only define the function once. 33if exists ( "*GetKrlIndent" ) 34finish 35endif 36let s: keepcpo = & cpo 37set cpo & vim 38 39function GetKrlIndent () abort 40 41let currentLine = getline ( v: lnum ) 42if currentLine =~? '\v^;(\s*(end)?fold>)@!' && ! get ( g:, 'krlCommentIndent' , 0 ) 43" If current line has a ; in column 1 and is no fold, keep zero indent. 44" This may be useful if code is commented out at the first column. 45return 0 46endif 47 48" Find a non-blank line above the current line. 49let preNoneBlankLineNum = s: KrlPreNoneBlank ( v: lnum - 1 ) 50if preNoneBlankLineNum == 0 51" At the start of the file use zero indent. 52return 0 53endif 54 55let preNoneBlankLine = getline ( preNoneBlankLineNum ) 56let ind = indent ( preNoneBlankLineNum ) 57 58" Define add 'shiftwidth' pattern 59let addShiftwidthPattern = '\v^\s*(' 60if get ( g:, 'krlIndentBetweenDef' , 1 ) 61let addShiftwidthPattern ..= '(global\s+)?def(fct|dat)?\s+\$?\w' 62let addShiftwidthPattern ..= '|' 63endif 64let addShiftwidthPattern ..= 'if>|while>|for>|loop>' 65let addShiftwidthPattern ..= '|else>' 66let addShiftwidthPattern ..= '|case>|default>' 67let addShiftwidthPattern ..= '|repeat>' 68let addShiftwidthPattern ..= '|skip>|(ptp_)?spline>' 69let addShiftwidthPattern ..= '|time_block\s+(start|part)>' 70let addShiftwidthPattern ..= '|const_vel\s+start>' 71let addShiftwidthPattern ..= ')' 72 73" Define Subtract 'shiftwidth' pattern 74let subtractShiftwidthPattern = '\v^\s*(' 75if get ( g:, 'krlIndentBetweenDef' , 1 ) 76let subtractShiftwidthPattern ..= 'end(fct|dat)?>' 77let subtractShiftwidthPattern ..= '|' 78endif 79let subtractShiftwidthPattern ..= 'end(if|while|for|loop)>' 80let subtractShiftwidthPattern ..= '|else>' 81let subtractShiftwidthPattern ..= '|case>|default>|endswitch>' 82let subtractShiftwidthPattern ..= '|until>' 83let subtractShiftwidthPattern ..= '|end(skip|spline)>' 84let subtractShiftwidthPattern ..= '|time_block\s+(part|end)>' 85let subtractShiftwidthPattern ..= '|const_vel\s+end>' 86let subtractShiftwidthPattern ..= ')' 87 88" Add shiftwidth 89if preNoneBlankLine =~? addShiftwidthPattern 90let ind += & sw 91endif 92 93" Subtract shiftwidth 94if currentLine =~? subtractShiftwidthPattern 95let ind = ind - & sw 96endif 97 98" First case after a switch gets the indent of the switch. 99if currentLine =~? '\v^\s*case>' 100 \&& preNoneBlankLine =~? '\v^\s*switch>' 101let ind = ind + & sw 102endif 103 104" align continue with the following instruction 105if currentLine =~? '\v^\s*continue>' 106 \&& getline(v: lnum + 1 ) =~? subtractShiftwidthPattern 107let ind = ind - & sw 108endif 109 110return ind 111endfunction 112 113" This function works almost like prevnonblank() but handles &-headers, 114" comments and continue instructions like blank lines 115function s: KrlPreNoneBlank ( lnum ) abort 116 117let nPreNoneBlank = prevnonblank ( a: lnum ) 118 119while nPreNoneBlank > 0 && getline ( nPreNoneBlank ) =~? '\v^\s*(\&\w\+|;|continue>)' 120" Previous none blank line irrelevant. Look further aback. 121let nPreNoneBlank = prevnonblank ( nPreNoneBlank - 1 ) 122endwhile 123 124return nPreNoneBlank 125endfunction 126 127let & cpo = s: keepcpo 128unlet s: keepcpo 129 130" vim:sw=2 sts=2 et