mirror of
https://github.com/amix/vimrc
synced 2025-09-18 18:45:01 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let s:has_fugitive = exists('*fugitive#head')
|
||||
let s:has_fugitive_detect = exists('*fugitive#detect')
|
||||
let s:has_lawrencium = exists('*lawrencium#statusline')
|
||||
let s:has_vcscommand = get(g:, 'airline#extensions#branch#use_vcscommand', 0) && exists('*VCSCommandGetStatusLine')
|
||||
|
||||
@ -10,36 +9,77 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:git_dirs = {}
|
||||
function! s:get_git_branch(path)
|
||||
if has_key(s:git_dirs, a:path)
|
||||
return s:git_dirs[a:path]
|
||||
endif
|
||||
|
||||
let dir = fugitive#extract_git_dir(a:path)
|
||||
if empty(dir)
|
||||
let name = ''
|
||||
else
|
||||
try
|
||||
let line = join(readfile(dir . '/HEAD'))
|
||||
if strpart(line, 0, 16) == 'ref: refs/heads/'
|
||||
let name = strpart(line, 16)
|
||||
else
|
||||
" raw commit hash
|
||||
let name = strpart(line, 0, 7)
|
||||
endif
|
||||
catch
|
||||
let name = ''
|
||||
endtry
|
||||
endif
|
||||
|
||||
let s:git_dirs[a:path] = name
|
||||
return name
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#branch#head()
|
||||
let head = ''
|
||||
if exists('b:airline_head') && !empty(b:airline_head)
|
||||
return b:airline_head
|
||||
endif
|
||||
|
||||
let b:airline_head = ''
|
||||
let found_fugitive_head = 0
|
||||
|
||||
if s:has_fugitive && !exists('b:mercurial_dir')
|
||||
let head = fugitive#head()
|
||||
let b:airline_head = fugitive#head(7)
|
||||
let found_fugitive_head = 1
|
||||
|
||||
if empty(head) && s:has_fugitive_detect && !exists('b:git_dir')
|
||||
call fugitive#detect(getcwd())
|
||||
let head = fugitive#head()
|
||||
if empty(b:airline_head) && !exists('b:git_dir')
|
||||
let b:airline_head = s:get_git_branch(expand("%:p:h"))
|
||||
endif
|
||||
endif
|
||||
|
||||
if empty(head)
|
||||
if empty(b:airline_head)
|
||||
if s:has_lawrencium
|
||||
let head = lawrencium#statusline()
|
||||
let b:airline_head = lawrencium#statusline()
|
||||
endif
|
||||
endif
|
||||
|
||||
if empty(head)
|
||||
if empty(b:airline_head)
|
||||
if s:has_vcscommand
|
||||
call VCSCommandEnableBufferSetup()
|
||||
if exists('b:VCSCommandBufferInfo')
|
||||
let head = get(b:VCSCommandBufferInfo, 0, '')
|
||||
let b:airline_head = get(b:VCSCommandBufferInfo, 0, '')
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
return empty(head) || !s:check_in_path()
|
||||
\ ? ''
|
||||
\ : head
|
||||
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
||||
let b:airline_head = ''
|
||||
endif
|
||||
|
||||
if exists("g:airline#extensions#branch#displayed_head_limit")
|
||||
let w:displayed_head_limit = g:airline#extensions#branch#displayed_head_limit
|
||||
if len(b:airline_head) > w:displayed_head_limit - 1
|
||||
let b:airline_head = b:airline_head[0:w:displayed_head_limit - 1].'…'
|
||||
endif
|
||||
endif
|
||||
|
||||
return b:airline_head
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#branch#get_head()
|
||||
@ -78,5 +118,5 @@ function! airline#extensions#branch#init(ext)
|
||||
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
|
||||
|
||||
autocmd BufReadPost * unlet! b:airline_file_in_root
|
||||
autocmd CursorHold,ShellCmdPost,CmdwinLeave * unlet! b:airline_head
|
||||
endfunction
|
||||
|
||||
|
@ -63,7 +63,11 @@ function! airline#extensions#default#apply(builder, context)
|
||||
if airline#util#getwinvar(winnr, 'airline_render_left', active || (!active && !g:airline_inactive_collapse))
|
||||
call <sid>build_sections(a:builder, a:context, s:layout[0])
|
||||
else
|
||||
call a:builder.add_section('airline_c'.(a:context.bufnr), ' %f%m ')
|
||||
let text = <sid>get_section(winnr, 'c')
|
||||
if empty(text)
|
||||
let text = ' %f%m '
|
||||
endif
|
||||
call a:builder.add_section('airline_c'.(a:context.bufnr), text)
|
||||
endif
|
||||
|
||||
call a:builder.split(s:get_section(winnr, 'gutter', '', ''))
|
||||
|
@ -20,7 +20,7 @@ function! airline#extensions#eclim#get_warnings()
|
||||
|
||||
if !empty(eclimList)
|
||||
" Remove any non-eclim signs (see eclim#display#signs#Update)
|
||||
call filter(eclimList, "v:val.name =~ '^\(qf_\)\?\(error\|info\|warning\)$'")
|
||||
call filter(eclimList, 'v:val.name =~ "^\\(qf_\\)\\?\\(error\\|info\\|warning\\)$"')
|
||||
|
||||
if !empty(eclimList)
|
||||
let errorsLine = eclimList[0]['line']
|
||||
|
@ -1,7 +1,7 @@
|
||||
" MIT License. Copyright (c) 2013-2014 Bailey Ling.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
if !get(g:, 'loaded_signify', 0) && !get(g:, 'loaded_gitgutter', 0)
|
||||
if !get(g:, 'loaded_signify', 0) && !get(g:, 'loaded_gitgutter', 0) && !get(g:, 'loaded_changes', 0)
|
||||
finish
|
||||
endif
|
||||
|
||||
@ -27,6 +27,19 @@ function! s:get_hunks_gitgutter()
|
||||
return GitGutterGetHunkSummary()
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_changes()
|
||||
if !get(b:, 'changes_view_enabled', 0) || s:is_branch_empty()
|
||||
return []
|
||||
endif
|
||||
let hunks = changes#GetStats()
|
||||
for i in hunks
|
||||
if i > 0
|
||||
return hunks
|
||||
endif
|
||||
endfor
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_empty()
|
||||
return ''
|
||||
endfunction
|
||||
@ -38,6 +51,8 @@ function! s:get_hunks()
|
||||
let s:source_func = 's:get_hunks_signify'
|
||||
elseif exists('*GitGutterGetHunkSummary')
|
||||
let s:source_func = 's:get_hunks_gitgutter'
|
||||
elseif exists('*changes#GetStats')
|
||||
let s:source_func = 's:get_hunks_changes'
|
||||
else
|
||||
let s:source_func = 's:get_hunks_empty'
|
||||
endif
|
||||
|
@ -6,6 +6,10 @@ let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
||||
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
||||
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
||||
let s:show_tab_nr = get(g:, 'airline#extensions#tabline#show_tab_nr', 1)
|
||||
let s:show_tab_type = get(g:, 'airline#extensions#tabline#show_tab_type', 1)
|
||||
let s:show_close_button = get(g:, 'airline#extensions#tabline#show_close_button', 1)
|
||||
let s:close_symbol = get(g:, 'airline#extensions#tabline#close_symbol', 'X')
|
||||
let s:buffer_idx_mode = get(g:, 'airline#extensions#tabline#buffer_idx_mode', 0)
|
||||
|
||||
let s:builder_context = {
|
||||
\ 'active' : 1,
|
||||
@ -24,6 +28,21 @@ let s:buf_min_count = get(g:, 'airline#extensions#tabline#buffer_min_count', 0)
|
||||
let s:tab_min_count = get(g:, 'airline#extensions#tabline#tab_min_count', 0)
|
||||
let s:spc = g:airline_symbols.space
|
||||
|
||||
let s:number_map = &encoding == 'utf-8'
|
||||
\ ? {
|
||||
\ '0': '⁰',
|
||||
\ '1': '¹',
|
||||
\ '2': '²',
|
||||
\ '3': '³',
|
||||
\ '4': '⁴',
|
||||
\ '5': '⁵',
|
||||
\ '6': '⁶',
|
||||
\ '7': '⁷',
|
||||
\ '8': '⁸',
|
||||
\ '9': '⁹'
|
||||
\ }
|
||||
\ : {}
|
||||
|
||||
function! airline#extensions#tabline#init(ext)
|
||||
if has('gui_running')
|
||||
set guioptions-=e
|
||||
@ -35,6 +54,9 @@ function! airline#extensions#tabline#init(ext)
|
||||
|
||||
call s:toggle_on()
|
||||
call a:ext.add_theme_func('airline#extensions#tabline#load_theme')
|
||||
if s:buffer_idx_mode
|
||||
call s:define_buffer_idx_mode_mappings()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:toggle_off()
|
||||
@ -69,12 +91,20 @@ function! airline#extensions#tabline#load_theme(palette)
|
||||
let l:tabtype = get(colors, 'airline_tabtype', a:palette.visual.airline_a)
|
||||
let l:tabfill = get(colors, 'airline_tabfill', a:palette.normal.airline_c)
|
||||
let l:tabmod = get(colors, 'airline_tabmod', a:palette.insert.airline_a)
|
||||
if has_key(a:palette, 'normal_modified') && has_key(a:palette.normal_modified, 'airline_c')
|
||||
let l:tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal_modified.airline_c)
|
||||
else
|
||||
"Fall back to normal airline_c if modified airline_c isn't present
|
||||
let l:tabmodu = get(colors, 'airline_tabmod_unsel', a:palette.normal.airline_c)
|
||||
endif
|
||||
|
||||
let l:tabhid = get(colors, 'airline_tabhid', a:palette.normal.airline_c)
|
||||
call airline#highlighter#exec('airline_tab', l:tab)
|
||||
call airline#highlighter#exec('airline_tabsel', l:tabsel)
|
||||
call airline#highlighter#exec('airline_tabtype', l:tabtype)
|
||||
call airline#highlighter#exec('airline_tabfill', l:tabfill)
|
||||
call airline#highlighter#exec('airline_tabmod', l:tabmod)
|
||||
call airline#highlighter#exec('airline_tabmod_unsel', l:tabmodu)
|
||||
call airline#highlighter#exec('airline_tabhid', l:tabhid)
|
||||
endfunction
|
||||
|
||||
@ -91,7 +121,12 @@ function! s:on_cursormove(min_count, total_count)
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#get()
|
||||
if s:show_buffers && tabpagenr('$') == 1
|
||||
let curtabcnt = tabpagenr('$')
|
||||
if curtabcnt != s:current_tabcnt
|
||||
let s:current_tabcnt = curtabcnt
|
||||
let s:current_bufnr = -1 " force a refresh...
|
||||
endif
|
||||
if s:show_buffers && curtabcnt == 1
|
||||
return s:get_buffers()
|
||||
else
|
||||
return s:get_tabs()
|
||||
@ -178,11 +213,13 @@ function! s:get_visible_buffers()
|
||||
endif
|
||||
endif
|
||||
|
||||
let g:current_visible_buffers = buffers
|
||||
return buffers
|
||||
endfunction
|
||||
|
||||
let s:current_bufnr = -1
|
||||
let s:current_tabnr = -1
|
||||
let s:current_tabcnt = -1
|
||||
let s:current_tabline = ''
|
||||
let s:current_modified = 0
|
||||
function! s:get_buffers()
|
||||
@ -193,6 +230,7 @@ function! s:get_buffers()
|
||||
endif
|
||||
endif
|
||||
|
||||
let l:index = 1
|
||||
let b = airline#builder#new(s:builder_context)
|
||||
let tab_bufs = tabpagebuflist(tabpagenr())
|
||||
for nr in s:get_visible_buffers()
|
||||
@ -200,6 +238,7 @@ function! s:get_buffers()
|
||||
call b.add_raw('%#airline_tabhid#...')
|
||||
continue
|
||||
endif
|
||||
|
||||
if cur == nr
|
||||
if g:airline_detect_modified && getbufvar(nr, '&modified')
|
||||
let group = 'airline_tabmod'
|
||||
@ -208,13 +247,25 @@ function! s:get_buffers()
|
||||
endif
|
||||
let s:current_modified = (group == 'airline_tabmod') ? 1 : 0
|
||||
else
|
||||
if index(tab_bufs, nr) > -1
|
||||
if g:airline_detect_modified && getbufvar(nr, '&modified')
|
||||
let group = 'airline_tabmod_unsel'
|
||||
elseif index(tab_bufs, nr) > -1
|
||||
let group = 'airline_tab'
|
||||
else
|
||||
let group = 'airline_tabhid'
|
||||
endif
|
||||
endif
|
||||
call b.add_section(group, s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.s:spc)
|
||||
|
||||
if s:buffer_idx_mode
|
||||
if len(s:number_map) > 0
|
||||
call b.add_section(group, s:spc . get(s:number_map, l:index, '') . '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)' . s:spc)
|
||||
else
|
||||
call b.add_section(group, '['.l:index.s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.']')
|
||||
endif
|
||||
let l:index = l:index + 1
|
||||
else
|
||||
call b.add_section(group, s:spc.'%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)'.s:spc)
|
||||
endif
|
||||
endfor
|
||||
|
||||
call b.add_section('airline_tabfill', '')
|
||||
@ -226,6 +277,35 @@ function! s:get_buffers()
|
||||
return s:current_tabline
|
||||
endfunction
|
||||
|
||||
function! s:select_tab(buf_index)
|
||||
" no-op when called in the NERDTree buffer
|
||||
if exists('t:NERDTreeBufName') && bufname('%') == t:NERDTreeBufName
|
||||
return
|
||||
endif
|
||||
|
||||
let idx = a:buf_index
|
||||
if g:current_visible_buffers[0] == -1
|
||||
let idx = idx + 1
|
||||
endif
|
||||
|
||||
let buf = get(g:current_visible_buffers, idx, 0)
|
||||
if buf != 0
|
||||
exec 'b!' . buf
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:define_buffer_idx_mode_mappings()
|
||||
noremap <unique> <Plug>AirlineSelectTab1 :call <SID>select_tab(0)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab2 :call <SID>select_tab(1)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab3 :call <SID>select_tab(2)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab4 :call <SID>select_tab(3)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab5 :call <SID>select_tab(4)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab6 :call <SID>select_tab(5)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab7 :call <SID>select_tab(6)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab8 :call <SID>select_tab(7)<CR>
|
||||
noremap <unique> <Plug>AirlineSelectTab9 :call <SID>select_tab(8)<CR>
|
||||
endfunction
|
||||
|
||||
function! s:get_tabs()
|
||||
let curbuf = bufnr('%')
|
||||
let curtab = tabpagenr()
|
||||
@ -264,8 +344,12 @@ function! s:get_tabs()
|
||||
call b.add_raw('%T')
|
||||
call b.add_section('airline_tabfill', '')
|
||||
call b.split()
|
||||
call b.add_section('airline_tab', ' %999XX ')
|
||||
call b.add_section('airline_tabtype', ' tabs ')
|
||||
if s:show_close_button
|
||||
call b.add_section('airline_tab', ' %999X'.s:close_symbol.' ')
|
||||
endif
|
||||
if s:show_tab_type
|
||||
call b.add_section('airline_tabtype', ' tabs ')
|
||||
endif
|
||||
|
||||
let s:current_bufnr = curbuf
|
||||
let s:current_tabnr = curtab
|
||||
|
@ -14,9 +14,9 @@ function! airline#extensions#tabline#unique_tail_improved#format(bufnr, buffers)
|
||||
|
||||
for nr in a:buffers
|
||||
let name = bufname(nr)
|
||||
if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail
|
||||
if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail " only perform actions if curbuf_tail isn't unique
|
||||
let do_deduplicate = 1
|
||||
let tokens = reverse(split(substitute(fnamemodify(name, ':p:.:h'), '\\', '/', 'g'), '/'))
|
||||
let tokens = reverse(split(substitute(fnamemodify(name, ':p:h'), '\\', '/', 'g'), '/'))
|
||||
let token_index = 0
|
||||
for token in tokens
|
||||
if token == '' | continue | endif
|
||||
@ -33,7 +33,7 @@ function! airline#extensions#tabline#unique_tail_improved#format(bufnr, buffers)
|
||||
if do_deduplicate == 1
|
||||
let path = []
|
||||
let token_index = 0
|
||||
for token in reverse(split(substitute(fnamemodify(bufname(a:bufnr), ':p:.:h'), '\\', '/', 'g'), '/'))
|
||||
for token in reverse(split(substitute(fnamemodify(bufname(a:bufnr), ':p:h'), '\\', '/', 'g'), '/'))
|
||||
if token == '.' | break | endif
|
||||
let duplicated = 0
|
||||
let uniq = 1
|
||||
|
@ -15,10 +15,25 @@ let s:default_checks = ['indent', 'trailing']
|
||||
|
||||
let s:trailing_format = get(g:, 'airline#extensions#whitespace#trailing_format', 'trailing[%s]')
|
||||
let s:mixed_indent_format = get(g:, 'airline#extensions#whitespace#mixed_indent_format', 'mixed-indent[%s]')
|
||||
let s:indent_algo = get(g:, 'airline#extensions#whitespace#mixed_indent_algo', 0)
|
||||
|
||||
let s:max_lines = get(g:, 'airline#extensions#whitespace#max_lines', 20000)
|
||||
|
||||
let s:enabled = 1
|
||||
let s:enabled = get(g:, 'airline#extensions#whitespace#enabled', 1)
|
||||
|
||||
function! s:check_mixed_indent()
|
||||
if s:indent_algo == 1
|
||||
" [<tab>]<space><tab>
|
||||
" spaces before or between tabs are not allowed
|
||||
let t_s_t = '(^\t* +\t\s*\S)'
|
||||
" <tab>(<space> x count)
|
||||
" count of spaces at the end of tabs should be less then tabstop value
|
||||
let t_l_s = '(^\t+ {' . &ts . ',}' . '\S)'
|
||||
return search('\v' . t_s_t . '|' . t_l_s, 'nw')
|
||||
else
|
||||
return search('\v(^\t+ +)|(^ +\t+)', 'nw')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#whitespace#check()
|
||||
if &readonly || !&modifiable || !s:enabled || line('$') > s:max_lines
|
||||
@ -31,12 +46,12 @@ function! airline#extensions#whitespace#check()
|
||||
|
||||
let trailing = 0
|
||||
if index(checks, 'trailing') > -1
|
||||
let trailing = search(' $', 'nw')
|
||||
let trailing = search('\s$', 'nw')
|
||||
endif
|
||||
|
||||
let mixed = 0
|
||||
if index(checks, 'indent') > -1
|
||||
let mixed = search('\v(^\t+ +)|(^ +\t+)', 'nw')
|
||||
let mixed = s:check_mixed_indent()
|
||||
endif
|
||||
|
||||
if trailing != 0 || mixed != 0
|
||||
@ -56,13 +71,23 @@ endfunction!
|
||||
|
||||
function! airline#extensions#whitespace#toggle()
|
||||
if s:enabled
|
||||
autocmd! airline_whitespace CursorHold,BufWritePost
|
||||
augroup airline_whitespace
|
||||
autocmd!
|
||||
augroup END
|
||||
augroup! airline_whitespace
|
||||
let s:enabled = 0
|
||||
else
|
||||
call airline#extensions#whitespace#init()
|
||||
let s:enabled = 1
|
||||
endif
|
||||
|
||||
if exists("g:airline#extensions#whitespace#enabled")
|
||||
let g:airline#extensions#whitespace#enabled = s:enabled
|
||||
if s:enabled && match(g:airline_section_warning, '#whitespace#check') < 0
|
||||
let g:airline_section_warning .= airline#section#create(['whitespace'])
|
||||
call airline#update_statusline()
|
||||
endif
|
||||
endif
|
||||
echo 'Whitespace checking: '.(s:enabled ? 'Enabled' : 'Disabled')
|
||||
endfunction
|
||||
|
||||
|
Reference in New Issue
Block a user