From f128f7810dee652dec02349fcacb78b26a515559 Mon Sep 17 00:00:00 2001 From: Kabbaj Amine Date: Fri, 7 Oct 2016 08:49:30 +0300 Subject: [PATCH 1/2] Add an initial ALEGetStatusLine function with customizable output, #25 --- plugin/ale/aaflags.vim | 9 +++++++++ plugin/ale/statusline.vim | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 plugin/ale/statusline.vim diff --git a/plugin/ale/aaflags.vim b/plugin/ale/aaflags.vim index f0c0bb7c..10d82128 100644 --- a/plugin/ale/aaflags.vim +++ b/plugin/ale/aaflags.vim @@ -39,3 +39,12 @@ let g:ale_warn_about_trailing_whitespace = " 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) + +" 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'] +\) diff --git a/plugin/ale/statusline.vim b/plugin/ale/statusline.vim new file mode 100644 index 00000000..def7db6d --- /dev/null +++ b/plugin/ale/statusline.vim @@ -0,0 +1,39 @@ +" Author: KabbAmine +" 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 From c3ae8305b788fe3efba85d4e152727b10abecd41 Mon Sep 17 00:00:00 2001 From: Kabbaj Amine Date: Fri, 7 Oct 2016 19:48:47 +0300 Subject: [PATCH 2/2] Update the documentation files ... and move all pictures to img/ directory --- README.md | 28 +++++++++++++++++++++++++++- doc/ale.txt | 18 +++++++++++++++++- example.gif => img/example.gif | Bin img/issues.png | Bin 0 -> 1008 bytes img/no_issues.png | Bin 0 -> 956 bytes 5 files changed, 44 insertions(+), 2 deletions(-) rename example.gif => img/example.gif (100%) create mode 100644 img/issues.png create mode 100644 img/no_issues.png diff --git a/README.md b/README.md index 03bca3cf..827479c5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ALE (Asynchronous Lint Engine) is a plugin for providing linting in NeoVim 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 run linters on the contents of text buffers and return errors as @@ -83,6 +83,7 @@ vimrc file for all given linters is as follows: | `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_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 @@ -123,6 +124,31 @@ let g:ale_sign_error = '>>' 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 To install this plugin, you should use one of the following methods. diff --git a/doc/ale.txt b/doc/ale.txt index b428d6d8..1f6ef977 100644 --- a/doc/ale.txt +++ b/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 - Asychronous Lint Engine @@ -219,6 +219,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 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* @@ -319,6 +329,12 @@ ALEGetLinters(filetype) *ALEGetLinters()* Return all of linters configured for a given filetype as a |List| of |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* This variable names a wrapper script for sending stdin input to programs which cannot accept input via stdin. See |ALEAddLinter| for more. diff --git a/example.gif b/img/example.gif similarity index 100% rename from example.gif rename to img/example.gif diff --git a/img/issues.png b/img/issues.png new file mode 100644 index 0000000000000000000000000000000000000000..7415d03988945ea5f10f3515bb41b1dc228ca4cc GIT binary patch literal 1008 zcmVXMz@72;DymZI=B#>GQ|Yr#SnxA z{sWB@#l(>EtK}gYpSTUlD!PbU;{yir; z-_eda@CwH8acr;Gm72DyVhkPU_9I&xmPf1mOqa>GZNNIXpY*OLKv4j&JsuPnYNz%* z%jz3HGkc_;$l!^F5f*(&UI}feqxBl<|b^fUQ;d2O5(dd zg;FRuiBv@~6k=iX!!&<;nNpJvH8oGu4_8U;ep+}QN21la6p`UkyoOPcy|86-MRMTc z1i|q$t^}=zn@0}OdgdGeS~7*2N)ectWd6Bc*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