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