From 482fb87e75feebef43ca5fd1a9b14fb460fac1ec Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 14 Aug 2020 16:01:59 +0200 Subject: [PATCH] vim: Show icon in airline when black is disabled --- home/.config/nvim/ftplugin/python.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/home/.config/nvim/ftplugin/python.vim b/home/.config/nvim/ftplugin/python.vim index 888c1b6..ed43982 100644 --- a/home/.config/nvim/ftplugin/python.vim +++ b/home/.config/nvim/ftplugin/python.vim @@ -1,3 +1,20 @@ let b:black_disable = 0 autocmd BufWritePre if b:black_disable != 1 | execute 'silent Black' | endif map b :let b:black_disable = (b:black_disable + 1) % 2 + +" 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')