Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
go.vim70 linesDownload Raw Back to indent
1" Vim indent file2" Language:	Go3" Maintainer:	David Barnett (https://github.com/google/vim-ft-go)4" Last Change:	2017 Jun 135"		2023 Aug 28 by Vim Project (undo_indent)6"7" TODO:8" - function invocations split across lines9" - general line splits (line ends in an operator)10 11if exists('b:did_indent')12  finish13endif14let b:did_indent = 115 16" C indentation is too far off useful, mainly due to Go's := operator.17" Let's just define our own.18setlocal nolisp19setlocal autoindent20setlocal indentexpr=GoIndent(v:lnum)21setlocal indentkeys+=<:>,0=},0=)22 23let b:undo_indent = "setl ai< inde< indk< lisp<"24 25if exists('*GoIndent')26  finish27endif28 29function! GoIndent(lnum)30  let l:prevlnum = prevnonblank(a:lnum-1)31  if l:prevlnum == 032    " top of file33    return 034  endif35 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:previ42 43  if l:prevl =~ '[({]\s*$'44    " previous line opened a block45    let l:ind += shiftwidth()46  endif47  if l:prevl =~# '^\s*\(case .*\|default\):$'48    " previous line is part of a switch statement49    let l:ind += shiftwidth()50  endif51  " TODO: handle if the previous line is a label.52 53  if l:thisl =~ '^\s*[)}]'54    " this line closed a block55    let l:ind -= shiftwidth()56  endif57 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, and61  " (b) they're hard to disambiguate from a composite literal key.62  if l:thisl =~# '^\s*\(case .*\|default\):$'63    let l:ind -= shiftwidth()64  endif65 66  return l:ind67endfunction68 69" vim: sw=2 sts=2 et70 
codekingpro/portable-devtools · Team Ai