Merge pull request #58 from KabbAmine/statusline
Add an initial getStatuslineStr function with customizable output
This commit is contained in:
commit
f6e95586dd
28
README.md
28
README.md
@ -3,7 +3,7 @@
|
|||||||
ALE (Asynchronous Lint Engine) is a plugin for providing linting in NeoVim
|
ALE (Asynchronous Lint Engine) is a plugin for providing linting in NeoVim
|
||||||
and Vim 8 while you edit your text files.
|
and Vim 8 while you edit your text files.
|
||||||
|
|
||||||
![linting example](example.gif?raw=true)
|
![linting example](img/example.gif?raw=true)
|
||||||
|
|
||||||
ALE makes use of NeoVim and Vim 8 job control functions and timers to
|
ALE makes use of NeoVim and Vim 8 job control functions and timers to
|
||||||
run linters on the contents of text buffers and return errors as
|
run linters on the contents of text buffers and return errors as
|
||||||
@ -84,6 +84,7 @@ vimrc file for all given linters is as follows:
|
|||||||
| `g:ale_sign_offset` | an offset for sign ids | `1000000` |
|
| `g:ale_sign_offset` | an offset for sign ids | `1000000` |
|
||||||
| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` |
|
| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` |
|
||||||
| `g:ale_warn_about_trailing_whitespace` | enable trailing whitespace warnings for some linters | `1` |
|
| `g:ale_warn_about_trailing_whitespace` | enable trailing whitespace warnings for some linters | `1` |
|
||||||
|
| `g:ale_statusline_format` | String format to use in statusline flag | `['%d error(s)', '%d warning(s)', 'OK']` |
|
||||||
|
|
||||||
### Selecting Particular Linters
|
### Selecting Particular Linters
|
||||||
|
|
||||||
@ -124,6 +125,31 @@ let g:ale_sign_error = '>>'
|
|||||||
let g:ale_sign_warning = '--'
|
let g:ale_sign_warning = '--'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Statusline
|
||||||
|
|
||||||
|
You can use `ALEGetStatusLine()` to integrate ALE into vim statusline.
|
||||||
|
To enable it, you should have in your `statusline` settings
|
||||||
|
|
||||||
|
```vim
|
||||||
|
%{ALEGetStatusLine()}
|
||||||
|
```
|
||||||
|
|
||||||
|
When errors are detected a string showing the number of errors will be shown.
|
||||||
|
You can customize the output format using the global list `g:ale_statusline_format` where:
|
||||||
|
|
||||||
|
- The 1st element is for errors
|
||||||
|
- The 2nd element is for warnings
|
||||||
|
- The 3rd element is for when no erros are detected
|
||||||
|
|
||||||
|
e.g
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
|
||||||
|
```
|
||||||
|
|
||||||
|
![Statusline with issues](img/issues.png)
|
||||||
|
![Statusline with no issues](img/no_issues.png)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
To install this plugin, you should use one of the following methods.
|
To install this plugin, you should use one of the following methods.
|
||||||
|
18
doc/ale.txt
18
doc/ale.txt
@ -1,4 +1,4 @@
|
|||||||
*ale.txt* For Vim version 8.0. Last change: 2016 October 5
|
*ale.txt* For Vim version 8.0. Last change: 2016 October 7
|
||||||
*ale*
|
*ale*
|
||||||
|
|
||||||
ALE - Asychronous Lint Engine
|
ALE - Asychronous Lint Engine
|
||||||
@ -222,6 +222,16 @@ you can disable these warnings for some linters by setting this option to `0`.
|
|||||||
Not all linters may respect this option. If a linter does not, please
|
Not all linters may respect this option. If a linter does not, please
|
||||||
file a bug report, and it may be possible to add such support.
|
file a bug report, and it may be possible to add such support.
|
||||||
|
|
||||||
|
g:ale_statusline_format *g:ale_statusline_format*
|
||||||
|
|
||||||
|
Type: |List|
|
||||||
|
Default: `['%d error(s)', '%d warning(s)', 'OK']`
|
||||||
|
|
||||||
|
This variable defines the format of |`ALEGetStatusLine()`| output.
|
||||||
|
- The 1st element is for errors
|
||||||
|
- The 2nd element is for warnings
|
||||||
|
- The 3rd element is for when no erros are detected
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
4. Linter Specific Options *ale-linter-options*
|
4. Linter Specific Options *ale-linter-options*
|
||||||
|
|
||||||
@ -346,6 +356,12 @@ ALEGetLinters(filetype) *ALEGetLinters()*
|
|||||||
Return all of linters configured for a given filetype as a |List| of
|
Return all of linters configured for a given filetype as a |List| of
|
||||||
|Dictionary| values in the format specified by |ALEAddLinter()|.
|
|Dictionary| values in the format specified by |ALEAddLinter()|.
|
||||||
|
|
||||||
|
ALEGetStatusLine() *ALEGetStatusLine()*
|
||||||
|
Return a formatted string that can be added to the statusline.
|
||||||
|
The output's format is defined in |`g:ale_statusline_format`|.
|
||||||
|
To enable it, the following should be present in your |statusline| settings: >
|
||||||
|
%{ALEGetStatusLine()}
|
||||||
|
|
||||||
g:ale#util#stdin_wrapper *g:ale#util#stdin_wrapper*
|
g:ale#util#stdin_wrapper *g:ale#util#stdin_wrapper*
|
||||||
This variable names a wrapper script for sending stdin input to programs
|
This variable names a wrapper script for sending stdin input to programs
|
||||||
which cannot accept input via stdin. See |ALEAddLinter| for more.
|
which cannot accept input via stdin. See |ALEAddLinter| for more.
|
||||||
|
Before Width: | Height: | Size: 3.3 MiB After Width: | Height: | Size: 3.3 MiB |
BIN
img/issues.png
Normal file
BIN
img/issues.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1008 B |
BIN
img/no_issues.png
Normal file
BIN
img/no_issues.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 956 B |
@ -39,3 +39,12 @@ let g:ale_warn_about_trailing_whitespace =
|
|||||||
|
|
||||||
" This flag can be set to 1 to keep sign gutter always open
|
" This flag can be set to 1 to keep sign gutter always open
|
||||||
let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
|
let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
|
||||||
|
|
||||||
|
" String format for statusline
|
||||||
|
" Its a list where:
|
||||||
|
" * The 1st element is for errors
|
||||||
|
" * The 2nd element is for warnings
|
||||||
|
" * The 3rd element is when there are no errors
|
||||||
|
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
|
||||||
|
\ ['%d error(s)', '%d warning(s)', 'OK']
|
||||||
|
\)
|
||||||
|
39
plugin/ale/statusline.vim
Normal file
39
plugin/ale/statusline.vim
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
" Author: KabbAmine <amine.kabb@gmail.com>
|
||||||
|
" Description: Statusline related function(s)
|
||||||
|
|
||||||
|
function! ALEGetStatusLine() abort
|
||||||
|
" Returns a formatted string that can be integrated in the
|
||||||
|
" statusline
|
||||||
|
|
||||||
|
let buf = bufnr('%')
|
||||||
|
let bufLoclist = g:ale_buffer_loclist_map
|
||||||
|
|
||||||
|
if !has_key(bufLoclist, buf)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
let errors = 0
|
||||||
|
let warnings = 0
|
||||||
|
for e in bufLoclist[buf]
|
||||||
|
if e.type ==# 'E'
|
||||||
|
let errors += 1
|
||||||
|
else
|
||||||
|
let warnings += 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
let errors = errors ? printf(g:ale_statusline_format[0], errors) : ''
|
||||||
|
let warnings = warnings ? printf(g:ale_statusline_format[1], warnings) : ''
|
||||||
|
let noErrors = g:ale_statusline_format[2]
|
||||||
|
|
||||||
|
" Different formats if no errors or no warnings
|
||||||
|
if empty(errors) && empty(warnings)
|
||||||
|
let res = noErrors
|
||||||
|
elseif !empty(errors) && !empty(warnings)
|
||||||
|
let res = printf('%s %s', errors, warnings)
|
||||||
|
else
|
||||||
|
let res = empty(errors) ? warnings : errors
|
||||||
|
endif
|
||||||
|
|
||||||
|
return res
|
||||||
|
endfunction
|
Loading…
Reference in New Issue
Block a user