vim: Show icon in airline when black is disabled

legacy
Simon Bruder 2020-08-14 16:01:59 +02:00
parent 148d5378e4
commit 482fb87e75
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
1 changed files with 17 additions and 0 deletions

View File

@ -1,3 +1,20 @@
let b:black_disable = 0
autocmd BufWritePre <buffer> if b:black_disable != 1 | execute 'silent Black' | endif
map <Leader>b :let b:black_disable = (b:black_disable + 1) % 2<CR>
" Show icon in airline when black is disabled
" Adapted from https://github.com/ryanoasis/vim-devicons/blob/a5750c6507602a7238e1c87669c64a6d820a319d/plugin/webdevicons.vim#L567
function! BlackIconStatus()
if &filetype ==# 'python' && b:black_disable == 1
return "  "
else
return ""
endif
endfunction
function! AirlineBlackIcon(...)
let w:airline_section_x = get(w:, 'airline_section_x', get(g:, 'airline_section_x', ''))
let w:airline_section_x .= '%{BlackIconStatus()}'
endfunction
call airline#add_statusline_func('AirlineBlackIcon')