annotate runtime/indent/krl.vim @ 29338:f4f531986753 v9.0.0012

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