Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
krl.vim131 linesDownload Raw Back to indent
1" Vim indent file2" Language: Kuka Robot Language3" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de>4" Version: 3.0.05" Last Change: 15. Apr 20226" Credits: Based on indent/vim.vim7 8" Only load this indent file when no other was loaded.9if exists("b:did_indent")10  finish11endif12let b:did_indent = 113 14setlocal nolisp15setlocal nocindent16setlocal nosmartindent17setlocal autoindent18setlocal indentexpr=GetKrlIndent()19setlocal indentkeys=!^F,o,O,=~end,0=~else,0=~case,0=~default,0=~until,0=~continue,=~part20let 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.25  setlocal softtabstop=226  setlocal shiftwidth=227  setlocal expandtab28  setlocal shiftround29  let b:undo_indent = b:undo_indent." softtabstop< shiftwidth< expandtab< shiftround<"30endif31 32" Only define the function once.33if exists("*GetKrlIndent")34  finish35endif36let s:keepcpo = &cpo37set cpo&vim38 39function GetKrlIndent() abort40 41  let currentLine = getline(v:lnum)42  if  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.45    return 046  endif47 48  " Find a non-blank line above the current line.49  let preNoneBlankLineNum = s:KrlPreNoneBlank(v:lnum - 1)50  if  preNoneBlankLineNum == 051    " At the start of the file use zero indent.52    return 053  endif54 55  let preNoneBlankLine = getline(preNoneBlankLineNum)56  let ind = indent(preNoneBlankLineNum)57 58  " Define add 'shiftwidth' pattern59  let addShiftwidthPattern =           '\v^\s*('60  if get(g:, 'krlIndentBetweenDef', 1)61    let addShiftwidthPattern ..=               '(global\s+)?def(fct|dat)?\s+\$?\w'62    let addShiftwidthPattern ..=               '|'63  endif64  let addShiftwidthPattern   ..=               'if>|while>|for>|loop>'65  let addShiftwidthPattern   ..=               '|else>'66  let addShiftwidthPattern   ..=               '|case>|default>'67  let addShiftwidthPattern   ..=               '|repeat>'68  let addShiftwidthPattern   ..=               '|skip>|(ptp_)?spline>'69  let addShiftwidthPattern   ..=               '|time_block\s+(start|part)>'70  let addShiftwidthPattern   ..=               '|const_vel\s+start>'71  let addShiftwidthPattern   ..=             ')'72 73  " Define Subtract 'shiftwidth' pattern74  let subtractShiftwidthPattern =      '\v^\s*('75  if get(g:, 'krlIndentBetweenDef', 1)76    let subtractShiftwidthPattern ..=          'end(fct|dat)?>'77    let subtractShiftwidthPattern ..=          '|'78  endif79  let subtractShiftwidthPattern   ..=          'end(if|while|for|loop)>'80  let subtractShiftwidthPattern   ..=          '|else>'81  let subtractShiftwidthPattern   ..=          '|case>|default>|endswitch>'82  let subtractShiftwidthPattern   ..=          '|until>'83  let subtractShiftwidthPattern   ..=          '|end(skip|spline)>'84  let subtractShiftwidthPattern   ..=          '|time_block\s+(part|end)>'85  let subtractShiftwidthPattern   ..=          '|const_vel\s+end>'86  let subtractShiftwidthPattern   ..=        ')'87 88  " Add shiftwidth89  if preNoneBlankLine =~? addShiftwidthPattern90    let ind += &sw91  endif92 93  " Subtract shiftwidth94  if currentLine =~? subtractShiftwidthPattern95    let ind = ind - &sw96  endif97 98  " First case after a switch gets the indent of the switch.99  if currentLine =~? '\v^\s*case>'  100        \&& preNoneBlankLine =~? '\v^\s*switch>'101    let ind = ind + &sw102  endif103 104  " align continue with the following instruction105  if currentLine =~? '\v^\s*continue>'  106        \&& getline(v:lnum + 1) =~? subtractShiftwidthPattern107    let ind = ind - &sw108  endif109 110  return ind111endfunction112 113" This function works almost like prevnonblank() but handles &-headers,114" comments and continue instructions like blank lines115function s:KrlPreNoneBlank(lnum) abort116 117  let nPreNoneBlank = prevnonblank(a:lnum)118 119  while nPreNoneBlank > 0 && getline(nPreNoneBlank) =~? '\v^\s*(\&\w\+|;|continue>)'120    " Previous none blank line irrelevant. Look further aback.121    let nPreNoneBlank = prevnonblank(nPreNoneBlank - 1)122  endwhile123 124  return nPreNoneBlank125endfunction126 127let &cpo = s:keepcpo128unlet s:keepcpo129 130" vim:sw=2 sts=2 et131 
codekingpro/portable-devtools · Team Ai