annotate runtime/indent/go.vim @ 20502:f28a49da879d v8.2.0805

patch 8.2.0805: terminal key codes test fails on some systems Commit: https://github.com/vim/vim/commit/fe81389d606ae79415d208207295f41a4375c580 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 21 20:38:31 2020 +0200 patch 8.2.0805: terminal key codes test fails on some systems Problem: Terminal key codes test fails on some systems. Solution: Skip keypad 3 and 9. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6070)
author Bram Moolenaar <Bram@vim.org>
date Thu, 21 May 2020 20:45:03 +0200
parents 63b0b7b79b25
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: Go
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Maintainer: David Barnett (https://github.com/google/vim-ft-go)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6153
diff changeset
4 " Last Change: 2017 Jun 13
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 "
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 " TODO:
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 " - function invocations split across lines
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " - general line splits (line ends in an operator)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 if exists('b:did_indent')
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 finish
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 let b:did_indent = 1
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 " C indentation is too far off useful, mainly due to Go's := operator.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 " Let's just define our own.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 setlocal nolisp
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 setlocal autoindent
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 setlocal indentexpr=GoIndent(v:lnum)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 setlocal indentkeys+=<:>,0=},0=)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 if exists('*GoIndent')
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 finish
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 function! GoIndent(lnum)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 let l:prevlnum = prevnonblank(a:lnum-1)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 if l:prevlnum == 0
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 " top of file
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 return 0
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 " grab the previous and current line, stripping comments.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '')
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 let l:thisl = substitute(getline(a:lnum), '//.*$', '', '')
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 let l:previ = indent(l:prevlnum)
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 let l:ind = l:previ
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 if l:prevl =~ '[({]\s*$'
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 " previous line opened a block
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6153
diff changeset
42 let l:ind += shiftwidth()
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 if l:prevl =~# '^\s*\(case .*\|default\):$'
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 " previous line is part of a switch statement
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6153
diff changeset
46 let l:ind += shiftwidth()
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 " TODO: handle if the previous line is a label.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 if l:thisl =~ '^\s*[)}]'
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 " this line closed a block
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6153
diff changeset
52 let l:ind -= shiftwidth()
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 " Colons are tricky.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 " We want to outdent if it's part of a switch ("case foo:" or "default:").
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 " We ignore trying to deal with jump labels because (a) they're rare, and
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 " (b) they're hard to disambiguate from a composite literal key.
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 if l:thisl =~# '^\s*\(case .*\|default\):$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6153
diff changeset
60 let l:ind -= shiftwidth()
6153
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 endif
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 return l:ind
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 endfunction
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65
1e8ebf870720 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 " vim: sw=2 sts=2 et