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