Mercurial > vim
view runtime/indent/go.vim @ 21709:16d6b626aa8f v8.2.1404
patch 8.2.1404: Vim9: script test fails in the GUI
Commit: https://github.com/vim/vim/commit/b3ca98240761d8f320c5a49e077d1aac6496bb21
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 9 14:43:58 2020 +0200
patch 8.2.1404: Vim9: script test fails in the GUI
Problem: Vim9: script test fails in the GUI.
Solution: Use another key to map. Improve cleanup.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Aug 2020 14:45:04 +0200 |
parents | 63b0b7b79b25 |
children | 5c220cf30f1f |
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 " " 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=) 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