Mercurial > vim
annotate runtime/indent/kotlin.vim @ 34645:172f30203d25 v9.1.0207
patch 9.1.0207: No autocommand when writing session file
Commit: https://github.com/vim/vim/commit/e5f2280381250801a28dcff9823e6f94e7b163fc
Author: Colin Kennedy <colinvfx@gmail.com>
Date: Tue Mar 26 18:20:16 2024 +0100
patch 9.1.0207: No autocommand when writing session file
Problem: No autocommand when writing session file
Solution: Add SessionWritePost autocommand
(Colin Kennedy)
fixes: ##14242
closes: #14288
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Colin Kennedy <colinvfx@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 26 Mar 2024 18:30:03 +0100 |
parents | c9c720360002 |
children |
rev | line source |
---|---|
33282
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Vim indent file |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 " Language: Kotlin |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 " Maintainer: Alexander Udalov |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 " URL: https://github.com/udalov/kotlin-vim |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 " Last Change: 7 November 2021 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 " 2023 Sep 17 by Vim Project (undo_indent) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 if exists('b:did_indent') |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 finish |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 let b:did_indent = 1 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 setlocal cinoptions& cinoptions+=j1,L0 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 setlocal indentexpr=GetKotlinIndent() |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 setlocal indentkeys=0},0),!^F,o,O,e,<CR> |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 setlocal autoindent " TODO ? |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 let b:undo_indent = "setlocal autoindent< cinoptions< indentexpr< indentkeys<" |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 " TODO teach it to count bracket balance, etc. |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 function! GetKotlinIndent() |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 if v:lnum == 0 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 return 0 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 let prev_num = prevnonblank(v:lnum - 1) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 let prev = getline(prev_num) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 let prev_indent = indent(prev_num) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 let cur = getline(v:lnum) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 if cur =~ '^\s*\*' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 return cindent(v:lnum) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 if prev =~ '^\s*\*/' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 let st = prev |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 while st > 1 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 if getline(st) =~ '^\s*/\*' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 break |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 let st = st - 1 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 endwhile |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 return indent(st) |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 let prev_open_paren = prev =~ '^.*(\s*$' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 let cur_close_paren = cur =~ '^\s*).*$' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 let prev_open_brace = prev =~ '^.*\({\|->\)\s*$' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 let cur_close_brace = cur =~ '^\s*}.*$' |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 if prev_open_paren && !cur_close_paren || prev_open_brace && !cur_close_brace |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 return prev_indent + shiftwidth() |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 if cur_close_paren && !prev_open_paren || cur_close_brace && !prev_open_brace |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 return prev_indent - shiftwidth() |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 endif |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 return prev_indent |
c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 endfunction |