Merge pull request #260 from dmitmel/master

[pull] master from dmitmel:master
This commit is contained in:
pull[bot] 2021-05-16 13:10:49 +00:00 committed by GitHub
commit b5fbb5b982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 68 deletions

View File

@ -0,0 +1,43 @@
" Based on <https://github.com/vim-airline/vim-airline/blob/70b06be4b067fec44756e843e2445cce5c97082f/autoload/airline/extensions/example.vim>
function! airline#extensions#dotfiles_filesize#init(ext) abort
call airline#parts#define_function('dotfiles_filesize', 'airline#extensions#dotfiles_filesize#get')
call a:ext.add_statusline_func('airline#extensions#dotfiles_filesize#apply')
endfunction
function! airline#extensions#dotfiles_filesize#apply(...) abort
call airline#extensions#append_to_section('y', airline#section#create_right(['', '', 'dotfiles_filesize']))
endfunction
" Finally, this function will be invoked from the statusline.
function! airline#extensions#dotfiles_filesize#get() abort
" Use several preliminary checks to prevent frequent updates. You see,
" wordcount() has to iterate the entire file to calculate its byte size.
" <https://github.com/vim-airline/vim-airline/blob/ecac148e19fe28d0f13af5f99d9500c2eadefe4c/autoload/airline/extensions/wordcount.vim#L78-L82>
" <https://github.com/vim-airline/vim-airline/blob/2e9df43962539e3a05e5571c63ccf6356451d46c/autoload/airline/extensions/lsp.vim#L95-L100>
" Implementation of wordcount: <https://github.com/neovim/neovim/blob/dab6b08a1e5571d0a0c4cb1f2f1af7000870c652/src/nvim/ops.c#L5568-L5808>
if empty(get(b:, 'dotfiles_filesize_str', '')) ||
\ (get(b:, 'dotfiles_filesize_changedtick', 0) !=# b:changedtick &&
\ reltimefloat(reltime()) - get(b:, 'dotfiles_filesize_timer') >=# get(g:, 'airline#extensions#dotfiles_filesize#update_delay', 0))
let bytes = wordcount().bytes
let b:dotfiles_filesize = bytes
let factor = 1
for unit in ['B', 'K', 'M', 'G']
let next_factor = factor * 1024
if bytes <# next_factor
let number_str = printf('%.2f', (bytes * 1.0) / factor)
" remove trailing zeros
let number_str = substitute(number_str, '\v(\.0*)=$', '', '')
let b:dotfiles_filesize_str = number_str . unit
break
endif
let factor = next_factor
endfor
let b:dotfiles_filesize_changedtick = b:changedtick
let b:dotfiles_filesize_timer = reltimefloat(reltime())
endif
return b:dotfiles_filesize_str
endfunction

View File

@ -0,0 +1,11 @@
function! airline#extensions#dotfiles_tweaks#init(ext) abort
" Undo this commit a little bit:
" <https://github.com/vim-airline/vim-airline/commit/8929bc72a13d358bb8369443386ac3cc4796ca16>
call airline#parts#define('maxlinenr', {
\ 'raw': trim(airline#parts#get('maxlinenr').raw),
\ })
call airline#parts#define('colnr', {
\ 'raw': trim(airline#parts#get('colnr').raw),
\ 'accent': 'none',
\ })
endfunction

View File

@ -14,12 +14,7 @@
endif
Plug 'Raimondi/delimitMate'
Plug 'tpope/vim-repeat'
" if g:vim_ide
Plug 'tomtom/tcomment_vim'
Plug 'glts/vim-textobj-comment'
" else
" Plug 'tpope/vim-commentary'
" endif
Plug 'tpope/vim-surround'
Plug 'Yggdroot/indentLine'
Plug 'idbrii/detectindent'
@ -37,6 +32,7 @@
Plug 'kana/vim-textobj-entire'
Plug 'kana/vim-textobj-line'
Plug 'kana/vim-textobj-indent'
Plug 'glts/vim-textobj-comment'
" }}}
" UI {{{

View File

@ -31,6 +31,13 @@ set commentstring=//%s
let g:indentLine_showFirstIndentLevel = 1
let g:indentLine_fileTypeExclude = ['text', 'help', 'tutor', 'man']
augroup vimrc-indentlines-disable
autocmd!
autocmd TermOpen * IndentLinesDisable
" <https://github.com/Yggdroot/indentLine/issues/315#issuecomment-734535963>
autocmd VimEnter * if bufname('%') == '' | IndentLinesDisable | endif
augroup END
let g:detectindent_max_lines_to_analyse = 128
let g:detectindent_check_comment_syntax = 1

View File

@ -87,71 +87,35 @@ endif
" Airline (statusline) {{{
let g:airline_theme = 'dotfiles'
let g:airline_symbols = {
\ 'readonly': 'RO',
\ 'whitespace': "\u21e5 ",
\ 'whitespace': '',
\ 'colnr': '',
\ 'linenr': '',
\ 'maxlinenr': ' ',
\ 'branch': '',
\ 'notexists': " [?]",
\ 'notexists': ' [?]',
\ }
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#coc#enabled = 1
let g:airline#extensions#po#enabled = 0
let g:airline#extensions#scrollbar#enabled = 0
let g:airline_extensions = [
\ 'quickfix',
\ 'fzf',
\ 'term',
\ 'hunks',
\ 'branch',
\ 'fugitiveline',
\ 'coc',
\ 'whitespace',
\ 'wordcount',
\ 'tabline',
\ 'obsession',
\ 'dotfiles_tweaks',
\ 'dotfiles_filesize',
\ ]
let g:airline_detect_iminsert = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = ''
function StatusLine_filesize()
let bytes = getfsize(expand('%'))
if bytes < 0 | return '' | endif
let factor = 1
for unit in ['B', 'K', 'M', 'G']
let next_factor = factor * 1024
if bytes < next_factor
let number_str = printf('%.2f', (bytes * 1.0) / factor)
" remove trailing zeros
let number_str = substitute(number_str, '\v\.?0+$', '', '')
return number_str . unit
endif
let factor = next_factor
endfor
endfunction
call airline#parts#define('filesize', { 'function': 'StatusLine_filesize' })
" Undo this commit a little bit:
" <https://github.com/vim-airline/vim-airline/commit/8929bc72a13d358bb8369443386ac3cc4796ca16>
call airline#parts#define('maxlinenr', {
\ 'raw': '/%L%{g:airline_symbols.maxlinenr}',
\ 'accent': 'bold',
\ })
call airline#parts#define('colnr', {
\ 'raw': '%{g:airline_symbols.colnr}:%v',
\ 'accent': 'none',
\ })
function s:airline_section_prepend(section, items)
let g:airline_section_{a:section} = airline#section#create_right(a:items + ['']) . g:airline_section_{a:section}
endfunction
function s:airline_section_append(section, items)
let g:airline_section_{a:section} = g:airline_section_{a:section} . airline#section#create_left([''] + a:items)
endfunction
function s:tweak_airline()
call s:airline_section_append('y', ['filesize'])
endfunction
augroup vimrc-interface-airline
autocmd!
autocmd user AirlineAfterInit call s:tweak_airline()
augroup END
let g:airline#extensions#dotfiles_filesize#update_delay = 2
" }}}
@ -173,12 +137,4 @@ endif
" }}}
" Terminal {{{
augroup vimrc-terminal
autocmd!
autocmd TermOpen * IndentLinesDisable
augroup END
" }}}
nnoremap <silent> <F9> <Cmd>make<CR>