Mercurial > vim
view runtime/indent/go.vim @ 34190:4f8b57f8b07a v9.1.0046
patch 9.1.0046: :drop does not re-use empty buffer
Commit: https://github.com/vim/vim/commit/f96dc8d07f752ddd96d1447d85278a85255a1462
Author: Rocco Mao <dapeng.mao@qq.com>
Date: Tue Jan 23 21:27:19 2024 +0100
patch 9.1.0046: :drop does not re-use empty buffer
Problem: :drop does not re-use empty buffer
(Rocco Mao)
Solution: Make :drop re-use an empty buffer
(Rocco Mao)
fixes: #13851
closes: #13881
Signed-off-by: Rocco Mao <dapeng.mao@qq.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 23 Jan 2024 21:30:05 +0100 |
parents | 5c220cf30f1f |
children |
line wrap: on
line source
" Vim indent file " Language: Go " Maintainer: David Barnett (https://github.com/google/vim-ft-go) " Last Change: 2017 Jun 13 " 2023 Aug 28 by Vim Project (undo_indent) " " TODO: " - function invocations split across lines " - general line splits (line ends in an operator) if exists('b:did_indent') finish endif let b:did_indent = 1 " C indentation is too far off useful, mainly due to Go's := operator. " Let's just define our own. setlocal nolisp setlocal autoindent setlocal indentexpr=GoIndent(v:lnum) setlocal indentkeys+=<:>,0=},0=) let b:undo_indent = "setl ai< inde< indk< lisp<" if exists('*GoIndent') finish endif function! GoIndent(lnum) let l:prevlnum = prevnonblank(a:lnum-1) if l:prevlnum == 0 " top of file return 0 endif " grab the previous and current line, stripping comments. let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '') let l:thisl = substitute(getline(a:lnum), '//.*$', '', '') let l:previ = indent(l:prevlnum) let l:ind = l:previ if l:prevl =~ '[({]\s*$' " previous line opened a block let l:ind += shiftwidth() endif if l:prevl =~# '^\s*\(case .*\|default\):$' " previous line is part of a switch statement let l:ind += shiftwidth() endif " TODO: handle if the previous line is a label. if l:thisl =~ '^\s*[)}]' " this line closed a block let l:ind -= shiftwidth() endif " Colons are tricky. " We want to outdent if it's part of a switch ("case foo:" or "default:"). " We ignore trying to deal with jump labels because (a) they're rare, and " (b) they're hard to disambiguate from a composite literal key. if l:thisl =~# '^\s*\(case .*\|default\):$' let l:ind -= shiftwidth() endif return l:ind endfunction " vim: sw=2 sts=2 et