Mercurial > vim
annotate runtime/indent/go.vim @ 34146:23bb675796f0 v9.1.0034
patch 9.1.0034: Window scrolls unexpectedly when 'scrollbind' is set
Commit: https://github.com/vim/vim/commit/ac4cffc6d9d307778d8a2945adab70244470bbb8
Author: Christian Brabandt <cb@256bit.org>
Date: Tue Jan 16 17:22:38 2024 +0100
patch 9.1.0034: Window scrolls unexpectedly when 'scrollbind' is set
Problem: Window may unexpectedly scroll when 'scrollbind' is set
and setting a buffer-local option using setbufvar()
(Boris Staletic)
Solution: Save and restore the windows topline before opening the
popup window.
fixes: #13863
closes: #13869
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 16 Jan 2024 17:30:10 +0100 |
parents | 5c220cf30f1f |
children |
rev | line source |
---|---|
6153 | 1 " Vim indent file |
2 " Language: Go | |
3 " Maintainer: David Barnett (https://github.com/google/vim-ft-go) | |
11518 | 4 " Last Change: 2017 Jun 13 |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
11518
diff
changeset
|
5 " 2023 Aug 28 by Vim Project (undo_indent) |
6153 | 6 " |
7 " TODO: | |
8 " - function invocations split across lines | |
9 " - general line splits (line ends in an operator) | |
10 | |
11 if exists('b:did_indent') | |
12 finish | |
13 endif | |
14 let b:did_indent = 1 | |
15 | |
16 " C indentation is too far off useful, mainly due to Go's := operator. | |
17 " Let's just define our own. | |
18 setlocal nolisp | |
19 setlocal autoindent | |
20 setlocal indentexpr=GoIndent(v:lnum) | |
21 setlocal indentkeys+=<:>,0=},0=) | |
22 | |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
11518
diff
changeset
|
23 let b:undo_indent = "setl ai< inde< indk< lisp<" |
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
11518
diff
changeset
|
24 |
6153 | 25 if exists('*GoIndent') |
26 finish | |
27 endif | |
28 | |
29 function! GoIndent(lnum) | |
30 let l:prevlnum = prevnonblank(a:lnum-1) | |
31 if l:prevlnum == 0 | |
32 " top of file | |
33 return 0 | |
34 endif | |
35 | |
36 " grab the previous and current line, stripping comments. | |
37 let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '') | |
38 let l:thisl = substitute(getline(a:lnum), '//.*$', '', '') | |
39 let l:previ = indent(l:prevlnum) | |
40 | |
41 let l:ind = l:previ | |
42 | |
43 if l:prevl =~ '[({]\s*$' | |
44 " previous line opened a block | |
11518 | 45 let l:ind += shiftwidth() |
6153 | 46 endif |
47 if l:prevl =~# '^\s*\(case .*\|default\):$' | |
48 " previous line is part of a switch statement | |
11518 | 49 let l:ind += shiftwidth() |
6153 | 50 endif |
51 " TODO: handle if the previous line is a label. | |
52 | |
53 if l:thisl =~ '^\s*[)}]' | |
54 " this line closed a block | |
11518 | 55 let l:ind -= shiftwidth() |
6153 | 56 endif |
57 | |
58 " Colons are tricky. | |
59 " We want to outdent if it's part of a switch ("case foo:" or "default:"). | |
60 " We ignore trying to deal with jump labels because (a) they're rare, and | |
61 " (b) they're hard to disambiguate from a composite literal key. | |
62 if l:thisl =~# '^\s*\(case .*\|default\):$' | |
11518 | 63 let l:ind -= shiftwidth() |
6153 | 64 endif |
65 | |
66 return l:ind | |
67 endfunction | |
68 | |
69 " vim: sw=2 sts=2 et |