robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0e3ea0a262
master
1" Vim filetype plugin file 2" Language: Bazel (http://bazel.io) 3" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl) 4" Last Change: 2021 Jan 19 5" 2023 Aug 28 by Vim Project (undo_ftplugin) 6 7"" 8" @section Introduction, intro 9" Core settings for the bzl filetype, used for BUILD and *.bzl files for the 10" Bazel build system (http://bazel.io/). 11 12if exists ( 'b:did_ftplugin' ) 13finish 14endif 15 16 17" Vim 7.4.051 has opinionated settings in ftplugin/python.vim that try to force 18" PEP8 conventions on every python file, but these conflict with Google's 19" indentation guidelines. As a workaround, we explicitly source the system 20" ftplugin, but save indentation settings beforehand and restore them after. 21let s: save_expandtab = & l: expandtab 22let s: save_shiftwidth = & l: shiftwidth 23let s: save_softtabstop = & l: softtabstop 24let s: save_tabstop = & l: tabstop 25 26" NOTE: Vim versions before 7.3.511 had a ftplugin/python.vim that was broken 27" for compatible mode. 28let s: save_cpo = & cpo 29set cpo & vim 30 31" Load base python ftplugin (also defines b:did_ftplugin). 32source $VIMRUNTIME/ftplugin/python.vim 33 34" NOTE: Vim versions before 7.4.104 and later set this in ftplugin/python.vim. 35setlocal comments = b:#,fb:- 36 37" Restore pre-existing indentation settings. 38let & l: expandtab = s: save_expandtab 39let & l: shiftwidth = s: save_shiftwidth 40let & l: softtabstop = s: save_softtabstop 41let & l: tabstop = s: save_tabstop 42 43setlocal formatoptions -= t 44 45" Initially defined in the python ftplugin sourced above 46let b: undo_ftplugin .= " | setlocal fo<" 47 48" Make gf work with imports in BUILD files. 49setlocal includeexpr = substitute (v:fname,'//','','') 50 51" Enable syntax-based folding, if specified. 52if get ( g:, 'ft_bzl_fold' , 0 ) 53setlocal foldmethod = syntax 54setlocal foldtext = BzlFoldText () 55let b: undo_ftplugin .= " | setlocal fdm< fdt<" 56endif 57 58if exists ( '*BzlFoldText' ) 59let & cpo = s: save_cpo 60unlet s: save_cpo 61finish 62endif 63 64function BzlFoldText () abort 65let l: start_num = nextnonblank ( v: foldstart ) 66let l: end_num = prevnonblank ( v: foldend ) 67 68if l: end_num <= l: start_num + 1 69" If the fold is empty, don't print anything for the contents. 70let l: content = '' 71else 72" Otherwise look for something matching the content regex. 73" And if nothing matches, print an ellipsis. 74let l: content = '...' 75for l: line in getline ( l: start_num + 1 , l: end_num - 1 ) 76let l: content_match = matchstr ( l: line , '\m\C^\s*name = \zs.*\ze,$' ) 77if ! empty ( l: content_match ) 78let l: content = l: content_match 79break 80endif 81endfor 82endif 83 84" Enclose content with start and end 85let l: start_text = getline ( l: start_num ) 86let l: end_text = substitute ( getline ( l: end_num ), '^\s*' , '' , '' ) 87let l: text = l: start_text . ' ' . l: content . ' ' . l: end_text 88 89" Compute the available width for the displayed text. 90let l: width = winwidth ( 0 ) - & foldcolumn - ( & number ? & numberwidth : 0 ) 91let l: lines_folded = ' ' . string ( 1 + v: foldend - v: foldstart ) . ' lines' 92 93" Expand tabs, truncate, pad, and concatenate 94let l: text = substitute ( l: text , '\t' , repeat ( ' ' , & tabstop ), 'g' ) 95let l: text = strpart ( l: text , 0 , l: width - len ( l: lines_folded )) 96let l: padding = repeat ( ' ' , l: width - len ( l: lines_folded ) - len ( l: text )) 97return l: text . l: padding . l: lines_folded 98endfunction 99 100let & cpo = s: save_cpo 101unlet s: save_cpo