annotate runtime/indent/hare.vim @ 31303:d2107f7b2155 v9.0.0985

patch 9.0.0985: when using kitty keyboard protocol function keys may not work Commit: https://github.com/vim/vim/commit/1a173409ae6a39d59ff99cf3d567c25e859f9ecd Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 2 12:28:47 2022 +0000 patch 9.0.0985: when using kitty keyboard protocol function keys may not work Problem: When using kitty keyboard protocol function keys may not work. (Kovid Goyal) Solution: Recognize CSI ending in [ABCDEFHPQRS] also when the termcap entries are not specified. (closes #11648)
author Bram Moolenaar <Bram@vim.org>
date Fri, 02 Dec 2022 13:30:04 +0100
parents 1e91e26ceebf
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30547
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: Hare
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Maintainer: Amelia Clarke <me@rsaihe.dev>
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 " Last Change: 2022 Sep 22
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 if exists("b:did_indent")
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 finish
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 let b:did_indent = 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 if !has("cindent") || !has("eval")
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 finish
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 setlocal cindent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " L0 -> don't deindent labels
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 " (s -> use one indent after a trailing (
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 " m1 -> if ) starts a line, indent it the same as its matching (
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 " ks -> add an extra indent to extra lines in an if expression or for expression
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 " j1 -> indent code inside {} one level when in parentheses
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " J1 -> see j1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 " *0 -> don't search for unclosed block comments
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 " #1 -> don't deindent lines that begin with #
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 setlocal cinoptions=L0,(s,m1,ks,j1,J1,*0,#1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " Controls which keys reindent the current line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 " 0{ -> { at beginning of line
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 " 0} -> } at beginning of line
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 " 0) -> ) at beginning of line
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 " 0] -> ] at beginning of line
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 " !^F -> <C-f> (not inserted)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 " o -> <CR> or `o` command
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 " O -> `O` command
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " e -> else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 " 0=case -> case
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 setlocal indentkeys=0{,0},0),0],!^F,o,O,e,0=case
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 setlocal cinwords=if,else,for,switch,match
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 setlocal indentexpr=GetHareIndent()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 function! FloorCindent(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 return cindent(a:lnum) / shiftwidth() * shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 function! GetHareIndent()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 let line = getline(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 let prevlnum = prevnonblank(v:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 let prevline = getline(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let prevprevline = getline(prevnonblank(prevlnum - 1))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 " This is all very hacky and imperfect, but it's tough to do much better when
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " working with regex-based indenting rules.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 " If the previous line ended with =, indent by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 if prevline =~# '\v\=\s*(//.*)?$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 return indent(prevlnum) + shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 " If the previous line ended in a semicolon and the line before that ended
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 " with =, deindent by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\s*(//.*)?$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return indent(prevlnum) - shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 " TODO: The following edge-case is still indented incorrectly:
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 " case =>
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 " if (foo) {
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 " bar;
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " };
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 " | // cursor is incorrectly deindented by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 "
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 " This only happens if the {} block is the first statement in the case body.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 " If `case` is typed, the case will also be incorrectly deindented by one
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 " shiftwidth. Are you having fun yet?
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 " Deindent cases.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 if line =~# '\v^\s*case'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 " If the previous line was also a case, don't do any special indenting.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 if prevline =~# '\v^\s*case'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 return indent(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 end
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 " If the previous line was a multiline case, deindent by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 if prevline =~# '\v\=\>\s*(//.*)?$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 return indent(prevlnum) - shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 " If the previous line started a block, deindent by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 " This handles the first case in a switch/match block.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 if prevline =~# '\v\{\s*(//.*)?$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 return FloorCindent(v:lnum) - shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 end
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 " If the previous line ended in a semicolon and the line before that wasn't
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 " a case, deindent by one shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 if prevline =~# '\v;\s*(//.*)?$' && prevprevline !~# '\v\=\>\s*(//.*)?$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 return FloorCindent(v:lnum) - shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 end
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 let l:indent = FloorCindent(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 " If a normal cindent would indent the same amount as the previous line,
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 " deindent by one shiftwidth. This fixes some issues with `case let` blocks.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 if l:indent == indent(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 return l:indent - shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 " Otherwise, do a normal cindent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 return l:indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 " Don't indent an extra shiftwidth for cases which span multiple lines.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 if prevline =~# '\v\=\>\s*(//.*)?$' && prevline !~# '\v^\s*case\W'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 return indent(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 " Indent the body of a case.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 " If the previous line ended in a semicolon and the line before that was a
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 " case, don't do any special indenting.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$' && line !~# '\v^\s*}'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 return indent(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 let l:indent = FloorCindent(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 " If the previous line was a case and a normal cindent wouldn't indent, indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 " an extra shiftwidth.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 if prevline =~# '\v\=\>\s*(//.*)?$' && l:indent == indent(prevlnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 return l:indent + shiftwidth()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 " If everything above is false, do a normal cindent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 return l:indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 " vim: tabstop=2 shiftwidth=2 expandtab