From 1e8de96225a5726bb1bcc7b955f15ebcf79969d1 Mon Sep 17 00:00:00 2001 From: Sainnhe Park Date: Thu, 7 Mar 2024 17:21:57 +0800 Subject: [PATCH] Add unavailable option --- README.md | 13 ++++++++----- autoload/lightline/ale.vim | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 78a1e85..3d2e0aa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ let g:lightline.component_expand = { \ 'linter_warnings': 'lightline#ale#warnings', \ 'linter_errors': 'lightline#ale#errors', \ 'linter_ok': 'lightline#ale#ok', + \ 'linter_unavailable': 'lightline#ale#unavailable', \ } ``` @@ -41,25 +42,22 @@ let g:lightline.component_expand = { ```viml let g:lightline.component_type = { - \ 'linter_checking': 'right', - \ 'linter_infos': 'right', \ 'linter_warnings': 'warning', \ 'linter_errors': 'error', - \ 'linter_ok': 'right', \ } ``` 3. Add the components to the lightline, for example to the right side: ```viml -let g:lightline.active = { 'right': [[ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ]] } +let g:lightline.active = { 'right': [[ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok', 'linter_unavailable' ]] } ``` 3.1. Lineinfo, fileformat, etc. have to be added additionaly. Final example: ```viml let g:lightline.active = { - \ 'right': [ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ], + \ 'right': [ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok', 'linter_unavailable' ], \ [ 'lineinfo' ], \ [ 'percent' ], \ [ 'fileformat', 'fileencoding', 'filetype'] ] } @@ -88,6 +86,10 @@ The indicator to use when there are errors. Default is `E:`. The indicator to use when there are no warnings or errors. Default is `OK`. +##### `g:lightline#ale#indicator_unavailable` + +The indicator to use when there are no warnings or errors. Default is an empty string. + ### Using icons as indicators If you would like to replace the default indicators with symbols like on the screenshot, then you'll need to ensure you have some "iconic fonts" installed, such as [Font Awesome](https://fontawesome.com). A common alternative is to replace your primary font with one of the [Patched Nerd Fonts](https://github.com/ryanoasis/nerd-fonts), which saves you from having to install multiple fonts. @@ -115,6 +117,7 @@ let g:lightline#ale#indicator_infos = "\uf129" let g:lightline#ale#indicator_warnings = "\uf071" let g:lightline#ale#indicator_errors = "\uf05e" let g:lightline#ale#indicator_ok = "\uf00c" +let g:lightline#ale#indicator_unavailable = "\uf05e" ``` ## License diff --git a/autoload/lightline/ale.vim b/autoload/lightline/ale.vim index c04f5ab..7b09a7d 100644 --- a/autoload/lightline/ale.vim +++ b/autoload/lightline/ale.vim @@ -3,6 +3,7 @@ let s:indicator_warnings = get(g:, 'lightline#ale#indicator_warnings', 'W: ') let s:indicator_errors = get(g:, 'lightline#ale#indicator_errors', 'E: ') let s:indicator_ok = get(g:, 'lightline#ale#indicator_ok', 'OK') let s:indicator_checking = get(g:, 'lightline#ale#indicator_checking', 'Linting...') +let s:indicator_unavailable = get(g:, 'lightline#ale#indicator_unavailable', '') """""""""""""""""""""" @@ -46,6 +47,13 @@ function! lightline#ale#checking() abort return ale#engine#IsCheckingBuffer(bufnr('')) ? s:indicator_checking : '' endfunction +function! lightline#ale#unavailable() abort + if !lightline#ale#linted() + return s:indicator_unavailable + else + return '' + endif +endfunction """""""""""""""""" " Helper functions