Update runtime files
This commit is contained in:
@ -31,7 +31,7 @@ Always use ":setlocal" to set 'indentexpr'. This avoids it being carried over
|
||||
to other buffers.
|
||||
|
||||
To trigger the indenting after typing a word like "endif", add the word to the
|
||||
'cinkeys' option with "+=".
|
||||
'indentkeys' option with "+=".
|
||||
|
||||
You normally set 'indentexpr' to evaluate a function and then define that
|
||||
function. That function only needs to be defined once for as long as Vim is
|
||||
|
||||
130
runtime/indent/krl.vim
Normal file
130
runtime/indent/krl.vim
Normal file
@ -0,0 +1,130 @@
|
||||
" Vim indent file
|
||||
" Language: Kuka Robot Language
|
||||
" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de>
|
||||
" Version: 3.0.0
|
||||
" Last Change: 15. Apr 2022
|
||||
" Credits: Based on indent/vim.vim
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal nolisp
|
||||
setlocal nocindent
|
||||
setlocal nosmartindent
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetKrlIndent()
|
||||
setlocal indentkeys=!^F,o,O,=~end,0=~else,0=~case,0=~default,0=~until,0=~continue,=~part
|
||||
let b:undo_indent = "setlocal lisp< cindent< smartindent< autoindent< indentexpr< indentkeys<"
|
||||
|
||||
if get(g:,'krlSpaceIndent',1)
|
||||
" Use spaces, not tabs, for indention, 2 is enough.
|
||||
" More or even tabs would waste valuable space on the teach pendant.
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
setlocal expandtab
|
||||
setlocal shiftround
|
||||
let b:undo_indent = b:undo_indent." softtabstop< shiftwidth< expandtab< shiftround<"
|
||||
endif
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetKrlIndent")
|
||||
finish
|
||||
endif
|
||||
let s:keepcpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function GetKrlIndent() abort
|
||||
|
||||
let currentLine = getline(v:lnum)
|
||||
if currentLine =~? '\v^;(\s*(end)?fold>)@!' && !get(g:, 'krlCommentIndent', 0)
|
||||
" If current line has a ; in column 1 and is no fold, keep zero indent.
|
||||
" This may be usefull if code is commented out at the first column.
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Find a non-blank line above the current line.
|
||||
let preNoneBlankLineNum = s:KrlPreNoneBlank(v:lnum - 1)
|
||||
if preNoneBlankLineNum == 0
|
||||
" At the start of the file use zero indent.
|
||||
return 0
|
||||
endif
|
||||
|
||||
let preNoneBlankLine = getline(preNoneBlankLineNum)
|
||||
let ind = indent(preNoneBlankLineNum)
|
||||
|
||||
" Define add 'shiftwidth' pattern
|
||||
let addShiftwidthPattern = '\v^\s*('
|
||||
if get(g:, 'krlIndentBetweenDef', 1)
|
||||
let addShiftwidthPattern ..= '(global\s+)?def(fct|dat)?\s+\$?\w'
|
||||
let addShiftwidthPattern ..= '|'
|
||||
endif
|
||||
let addShiftwidthPattern ..= 'if>|while>|for>|loop>'
|
||||
let addShiftwidthPattern ..= '|else>'
|
||||
let addShiftwidthPattern ..= '|case>|default>'
|
||||
let addShiftwidthPattern ..= '|repeat>'
|
||||
let addShiftwidthPattern ..= '|skip>|(ptp_)?spline>'
|
||||
let addShiftwidthPattern ..= '|time_block\s+(start|part)>'
|
||||
let addShiftwidthPattern ..= '|const_vel\s+start>'
|
||||
let addShiftwidthPattern ..= ')'
|
||||
|
||||
" Define Subtract 'shiftwidth' pattern
|
||||
let subtractShiftwidthPattern = '\v^\s*('
|
||||
if get(g:, 'krlIndentBetweenDef', 1)
|
||||
let subtractShiftwidthPattern ..= 'end(fct|dat)?>'
|
||||
let subtractShiftwidthPattern ..= '|'
|
||||
endif
|
||||
let subtractShiftwidthPattern ..= 'end(if|while|for|loop)>'
|
||||
let subtractShiftwidthPattern ..= '|else>'
|
||||
let subtractShiftwidthPattern ..= '|case>|default>|endswitch>'
|
||||
let subtractShiftwidthPattern ..= '|until>'
|
||||
let subtractShiftwidthPattern ..= '|end(skip|spline)>'
|
||||
let subtractShiftwidthPattern ..= '|time_block\s+(part|end)>'
|
||||
let subtractShiftwidthPattern ..= '|const_vel\s+end>'
|
||||
let subtractShiftwidthPattern ..= ')'
|
||||
|
||||
" Add shiftwidth
|
||||
if preNoneBlankLine =~? addShiftwidthPattern
|
||||
let ind += &sw
|
||||
endif
|
||||
|
||||
" Subtract shiftwidth
|
||||
if currentLine =~? subtractShiftwidthPattern
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
|
||||
" First case after a switch gets the indent of the switch.
|
||||
if currentLine =~? '\v^\s*case>'
|
||||
\&& preNoneBlankLine =~? '\v^\s*switch>'
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
|
||||
" align continue with the following instruction
|
||||
if currentLine =~? '\v^\s*continue>'
|
||||
\&& getline(v:lnum + 1) =~? subtractShiftwidthPattern
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" This function works almost like prevnonblank() but handles &-headers,
|
||||
" comments and continue instructions like blank lines
|
||||
function s:KrlPreNoneBlank(lnum) abort
|
||||
|
||||
let nPreNoneBlank = prevnonblank(a:lnum)
|
||||
|
||||
while nPreNoneBlank > 0 && getline(nPreNoneBlank) =~? '\v^\s*(\&\w\+|;|continue>)'
|
||||
" Previouse none blank line irrelevant. Look further aback.
|
||||
let nPreNoneBlank = prevnonblank(nPreNoneBlank - 1)
|
||||
endwhile
|
||||
|
||||
return nPreNoneBlank
|
||||
endfunction
|
||||
|
||||
let &cpo = s:keepcpo
|
||||
unlet s:keepcpo
|
||||
|
||||
" vim:sw=2 sts=2 et
|
||||
148
runtime/indent/testdir/krl.in
Normal file
148
runtime/indent/testdir/krl.in
Normal file
@ -0,0 +1,148 @@
|
||||
; vim: set ft=krl :
|
||||
|
||||
; START_INDENT
|
||||
|
||||
def One()
|
||||
int i
|
||||
If i==1 then
|
||||
While i>=1
|
||||
For i=1 to 5 step 2
|
||||
Loop
|
||||
i = i+1
|
||||
EndLoop
|
||||
EndFor
|
||||
EndWhile
|
||||
Else
|
||||
Repeat
|
||||
Switch i
|
||||
Case 1
|
||||
Skip 123
|
||||
i = i+1
|
||||
EndSkip 123
|
||||
Spline with $acc=100, $vel.cp=3
|
||||
slin {x 100}
|
||||
scirc {x 110, y 110}, {x 120, y 90}
|
||||
slin {x 200} c_dis
|
||||
Time_Block Start
|
||||
slin {x 300} c_dis
|
||||
Time_Block Part = 22.2
|
||||
slin {y 400} c_dis
|
||||
Time_Block Part = 33.3
|
||||
Time_Block End = 10
|
||||
slin {y 200} c_dis
|
||||
Const_Vel Start +100 OnStart
|
||||
slin {y 300} c_dis
|
||||
slin {x 100}
|
||||
Const_Vel End -5.5
|
||||
slin {y 200} c_dis
|
||||
EndSpline
|
||||
Case 2,3
|
||||
PTP_Spline with $acc=100, $vel.ptp=100
|
||||
sptp {a1 0} c_ptp
|
||||
sptp {a1 90}
|
||||
EndSpline c_spl
|
||||
Default
|
||||
i = i+1
|
||||
EndSwitch
|
||||
Continue
|
||||
Until False
|
||||
EndIf
|
||||
end
|
||||
|
||||
DEF Two()
|
||||
int i
|
||||
END
|
||||
|
||||
global def Three()
|
||||
int i
|
||||
end
|
||||
|
||||
GLOBAL DEF Four()
|
||||
int i
|
||||
END
|
||||
|
||||
Global Def Five()
|
||||
int i
|
||||
End
|
||||
|
||||
deffct bool fOne()
|
||||
int i
|
||||
endfct
|
||||
|
||||
DEFFCT bool fTwo()
|
||||
int i
|
||||
ENDFCT
|
||||
|
||||
global deffct bool fThree()
|
||||
int i
|
||||
endfct
|
||||
|
||||
GLOBAL DEFFCT bool fFour()
|
||||
int i
|
||||
ENDFCT
|
||||
|
||||
Global DefFct bool fFive()
|
||||
int i
|
||||
EndFct
|
||||
|
||||
DefDat datfile()
|
||||
global int i=1
|
||||
; don't indent column 1 comments unless g:krlCommentIndent is set
|
||||
; global int o=2
|
||||
EndDat
|
||||
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlSpaceIndent = 0
|
||||
; INDENT_EXE set shiftwidth=4
|
||||
|
||||
def bla()
|
||||
int i
|
||||
end
|
||||
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlCommentIndent = 1
|
||||
def bla()
|
||||
; indent this first column comment because of g:krlCommentIndent=1
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlIndentBetweenDef = 0
|
||||
def bla()
|
||||
int i ; don't indent this line because of g:krlIndentBetweenDef=0
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_AT this-line
|
||||
def Some()
|
||||
int f
|
||||
if true then
|
||||
f = 1 ; this-line
|
||||
endif
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_NEXT next-line
|
||||
def Some()
|
||||
int i
|
||||
; next-line
|
||||
i = 1 ; should get indent of line 'int i' above
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_PREV prev-line
|
||||
def Some()
|
||||
int f
|
||||
if true then
|
||||
f = 1
|
||||
; prev-line
|
||||
endif
|
||||
end
|
||||
; END_INDENT
|
||||
148
runtime/indent/testdir/krl.ok
Normal file
148
runtime/indent/testdir/krl.ok
Normal file
@ -0,0 +1,148 @@
|
||||
; vim: set ft=krl :
|
||||
|
||||
; START_INDENT
|
||||
|
||||
def One()
|
||||
int i
|
||||
If i==1 then
|
||||
While i>=1
|
||||
For i=1 to 5 step 2
|
||||
Loop
|
||||
i = i+1
|
||||
EndLoop
|
||||
EndFor
|
||||
EndWhile
|
||||
Else
|
||||
Repeat
|
||||
Switch i
|
||||
Case 1
|
||||
Skip 123
|
||||
i = i+1
|
||||
EndSkip 123
|
||||
Spline with $acc=100, $vel.cp=3
|
||||
slin {x 100}
|
||||
scirc {x 110, y 110}, {x 120, y 90}
|
||||
slin {x 200} c_dis
|
||||
Time_Block Start
|
||||
slin {x 300} c_dis
|
||||
Time_Block Part = 22.2
|
||||
slin {y 400} c_dis
|
||||
Time_Block Part = 33.3
|
||||
Time_Block End = 10
|
||||
slin {y 200} c_dis
|
||||
Const_Vel Start +100 OnStart
|
||||
slin {y 300} c_dis
|
||||
slin {x 100}
|
||||
Const_Vel End -5.5
|
||||
slin {y 200} c_dis
|
||||
EndSpline
|
||||
Case 2,3
|
||||
PTP_Spline with $acc=100, $vel.ptp=100
|
||||
sptp {a1 0} c_ptp
|
||||
sptp {a1 90}
|
||||
EndSpline c_spl
|
||||
Default
|
||||
i = i+1
|
||||
EndSwitch
|
||||
Continue
|
||||
Until False
|
||||
EndIf
|
||||
end
|
||||
|
||||
DEF Two()
|
||||
int i
|
||||
END
|
||||
|
||||
global def Three()
|
||||
int i
|
||||
end
|
||||
|
||||
GLOBAL DEF Four()
|
||||
int i
|
||||
END
|
||||
|
||||
Global Def Five()
|
||||
int i
|
||||
End
|
||||
|
||||
deffct bool fOne()
|
||||
int i
|
||||
endfct
|
||||
|
||||
DEFFCT bool fTwo()
|
||||
int i
|
||||
ENDFCT
|
||||
|
||||
global deffct bool fThree()
|
||||
int i
|
||||
endfct
|
||||
|
||||
GLOBAL DEFFCT bool fFour()
|
||||
int i
|
||||
ENDFCT
|
||||
|
||||
Global DefFct bool fFive()
|
||||
int i
|
||||
EndFct
|
||||
|
||||
DefDat datfile()
|
||||
global int i=1
|
||||
; don't indent column 1 comments unless g:krlCommentIndent is set
|
||||
; global int o=2
|
||||
EndDat
|
||||
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlSpaceIndent = 0
|
||||
; INDENT_EXE set shiftwidth=4
|
||||
|
||||
def bla()
|
||||
int i
|
||||
end
|
||||
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlCommentIndent = 1
|
||||
def bla()
|
||||
; indent this first column comment because of g:krlCommentIndent=1
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_EXE let g:krlIndentBetweenDef = 0
|
||||
def bla()
|
||||
int i ; don't indent this line because of g:krlIndentBetweenDef=0
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_AT this-line
|
||||
def Some()
|
||||
int f
|
||||
if true then
|
||||
f = 1 ; this-line
|
||||
endif
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_NEXT next-line
|
||||
def Some()
|
||||
int i
|
||||
; next-line
|
||||
i = 1 ; should get indent of line 'int i' above
|
||||
end
|
||||
; END_INDENT
|
||||
|
||||
; START_INDENT
|
||||
; INDENT_PREV prev-line
|
||||
def Some()
|
||||
int f
|
||||
if true then
|
||||
f = 1
|
||||
; prev-line
|
||||
endif
|
||||
end
|
||||
; END_INDENT
|
||||
Reference in New Issue
Block a user