From e4b3f579fa3c5e4edc8214194cfab4d8cb8aaa6b Mon Sep 17 00:00:00 2001 From: KabbAmine Date: Mon, 10 Oct 2016 15:53:54 +0400 Subject: [PATCH] Echo string format (#76) * Implement an option to configure the echoed message, #48 Via `g:ale_echo_msg_format` where: - `%s` is the error message itself - `%linter%` is the linter name - `%severity` is the severity type e.g let g:ale_echo_msg_fomat = '[%linter%] [%severity%] %s' * Add new options for defining the string used for errors in echoed message `g:ale_echo_msg_error_str` and `g:ale_echo_msg_warning_str` * Change text output of some linters Now that the echoed message can be customized, no need to add the type to the text variable. * Update README & documentation file * Fix some typos * Sort the table of options alphabetically (except echo_msg_x_str options) * Added echo warning str option to the doc --- README.md | 37 ++++++++++++++++++++++++---- ale_linters/coffee/coffeelint.vim | 2 +- ale_linters/yaml/yamllint.vim | 2 +- doc/ale.txt | 39 +++++++++++++++++++++++++++--- img/echo.png | Bin 0 -> 5154 bytes plugin/ale/aaflags.vim | 9 +++++++ plugin/ale/cursor.vim | 21 +++++++++++++++- 7 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 img/echo.png diff --git a/README.md b/README.md index a628e9e3..d142f400 100644 --- a/README.md +++ b/README.md @@ -76,20 +76,23 @@ vimrc file for all given linters is as follows: | Option | Description | Default | | ------ | ----------- | ------- | -| `g:ale_linters` | a dictionary of linters to whitelist | _not set_ | -| `g:ale_lint_on_text_changed` | lint while typing | `1` | +| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` | +| `g:ale_echo_msg_format` | string format to use for the echoed message | `'%s'` | +| `g:ale_echo_msg_error_str` | string used for error severity in echoed message | `'Error'` | +| `g:ale_echo_msg_warning_str` | string used for warning severity in echoed message | `'Warning'` | | `g:ale_lint_delay` | milliseconds to wait before linting | `200` | +| `g:ale_linters` | a dictionary of linters to whitelist | _not set_ | | `g:ale_lint_on_enter` | lint when opening a file | `1` | | `g:ale_lint_on_save` | lint when saving a file | `0` | +| `g:ale_lint_on_text_changed` | lint while typing | `1` | | `g:ale_set_loclist` | set the loclist with errors | `1` | | `g:ale_set_signs` | set gutter signs with error markers | `has('signs')` | | `g:ale_sign_column_always` | always show the sign gutter | `0` | | `g:ale_sign_error` | the text to use for errors in the gutter | `'>>'` | -| `g:ale_sign_warning` | the text to use for warnings in the gutter | `'--'` | | `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_sign_warning` | the text to use for warnings in the gutter | `'--'` | +| `g:ale_statusline_format` | string format to use in statusline flag | `['%d error(s)', '%d warning(s)', 'OK']` | | `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 @@ -155,6 +158,30 @@ let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok'] ![Statusline with issues](img/issues.png) ![Statusline with no issues](img/no_issues.png) + +### Customize echoed message + +There are 3 global options that allow customizing the echoed message. + +- `g:ale_echo_msg_format` where: + * `%s` is the error message itself + * `%linter%` is the linter name + * `%severity` is the severity type +- `g:ale_echo_msg_error_str` is the string used for error severity. +- `g:ale_echo_msg_warning_str` is the string used for warning severity. + +So for example this: + +```vim +let g:ale_echo_msg_error_str = 'E' +let g:ale_echo_msg_error_str = 'W' +let g:ale_echo_msg_fomat = '[%linter%] %s [%severity%]' +``` + +Will give you: + +![Echoed message](img/echo.png) + ## Installation To install this plugin, you should use one of the following methods. diff --git a/ale_linters/coffee/coffeelint.vim b/ale_linters/coffee/coffeelint.vim index aba29c4a..972fa25d 100644 --- a/ale_linters/coffee/coffeelint.vim +++ b/ale_linters/coffee/coffeelint.vim @@ -27,7 +27,7 @@ function! ale_linters#coffee#coffeelint#Handle(buffer, lines) let line = l:match[1] + 0 let column = 1 let type = l:match[3] ==# 'error' ? 'E' : 'W' - let text = l:match[3] . ': ' . l:match[4] + let text = l:match[4] " vcol is needed to indicate that the column is a character call add(output, { diff --git a/ale_linters/yaml/yamllint.vim b/ale_linters/yaml/yamllint.vim index cb7ca4b9..92a4313d 100644 --- a/ale_linters/yaml/yamllint.vim +++ b/ale_linters/yaml/yamllint.vim @@ -23,7 +23,7 @@ function! ale_linters#yaml#yamllint#Handle(buffer, lines) let line = match[1] + 0 let col = match[2] + 0 let type = match[3] - let text = printf('[%s]%s', type, match[4]) + let text = match[4] " vcol is Needed to indicate that the column is a character. call add(output, { diff --git a/doc/ale.txt b/doc/ale.txt index bdd2b801..ec2e8028 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1,7 +1,7 @@ -*ale.txt* For Vim version 8.0. Last change: 2016 October 7 +*ale.txt* For Vim version 8.0. Last change: 2016 October 10 *ale* -ALE - Asychronous Lint Engine +ALE - Asynchronous Lint Engine =============================================================================== CONTENTS *ale-contents* @@ -157,7 +157,7 @@ g:ale_set_signs *g:ale_set_signs* When this option is set to `1`, the |sign| column will be populated with signs marking where errors and warnings appear in the file. The - 'ALEErrorSign' and 'ALEWarningSign' highlight groups will be used to provide + `ALEErrorSign` and `ALEWarningSign` highlight groups will be used to provide highlighting for the signs. The text used for signs can be customised with the |g:ale_sign_error| and |g:ale_sign_warning| options. @@ -216,6 +216,39 @@ g:ale_echo_cursor *g:ale_echo_cursor* error at a column nearest to the cursor when the cursor is resting on a line which contains a warning or error. This option can be set to `0` to disable this behaviour. + The format of the message can be customizable in |g:ale_echo_msg_format|. + + +g:ale_echo_msg_format *g:ale_echo_msg_format* + + Type: |String| + Default: `%s` + + This variable defines the format of the echoed message. The `%s` is the + error message itself, and it can contain the following handlers: + - `%linter%` for linter's name + - `%severity%` for the type of severity + Note |`g:ale_echo_cursor`| should be setted to 1 + + +g:ale_echo_msg_error_str *g:ale_echo_msg_error_str* + + Type: |String| + Default: `Error` + + The string used for error severity in the echoed message. + Note |`g:ale_echo_cursor`| should be setted to 1 + Note |`g:ale_echo_msg_format`| should contain the `%severity%` handler + + +g:ale_echo_msg_warning_str *g:ale_echo_msg_warning_str* + + Type: |String| + Default: `Warning` + + The string used for warning severity in the echoed message. + Note |`g:ale_echo_cursor`| should be setted to 1 + Note |`g:ale_echo_msg_format`| should contain the `%severity%` handler g:ale_warn_about_trailing_whitespace *g:ale_warn_about_trailing_whitespace* diff --git a/img/echo.png b/img/echo.png new file mode 100644 index 0000000000000000000000000000000000000000..671a66b26b5a6077963f3e652fbc31fdb0f3f1f2 GIT binary patch literal 5154 zcmZvAc|25a*uKh^HDyaQB|Q=bZCA&w0*$-Pd#7SA>R|5pEa5Yn>=+xucjl3nfvLh>2ZyX{na`e zjn&FwMmS=)I~g}zeNC;8>px+Bo))Kje55E=d954d->%rb3)&k*4i+)ZH8q$zI`&WQ zf0bsxtBHr+1V;IOU*bm@d{Mln3@(3ze10&uh(J#L@gB9ptA|(f?*T3CSNOw6|8vK3 z;WIGazb^m#gj^ZuBVY818U^(Ds6o%fPXXNc#*sMJTWz+Eb#||iI@!TxpR?m619?v!da>ZwX950@vjt9=E9aQH=|(}mw{{YhyEpX2O!3ALQ>$LO?= zQO09>k;dBovp1g$4R9DMbou)b(YIjb=MhWTl#1H zO40|kJv10#qr+h-E1$k&JZqar;VHs=Qj$7_=%Y-<1RDF0DQlNHIBmVM*0RS)BDUCEkAOB_&KHvL zCn|Tw(q}t?gn!(TT2bg_L6b0PjRtk}NiHs)W}OFo&R%Z!PiGV*9VUYi{^f0N;yb>` zzc@Hvf7O#z#>2x?>EI^U+_c`!B>9ijfyX6TTWnd3Od7`6g`OQ4dpnkj@Qi z5VN`Ei=8K8&zzt79doVxjg$M!B^oG2dXdGe0#Arb(b+tZvn3HbRSX;56FubYzmL1i z^q$*V13)kz`l0dWP5cf%H>be!5IYzc;GZmEPD3OTlT${|BQ+$71tdpDj>ga#<)bQt z+x8A*bY+1Yu58dO<5>X#f%(Edd24Zw_;@Wn%#zSEubq~NaM(k8`!wa^|ZLC z8kkfuD~RK*fUwN5xMNxWjH>dLcUx;rc}R<@ov^powFt*qOrKz6CN5V+$qZ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knjjH7Ew zXYn`b|E08?N_>Ywc~f{=8g1m)AL71U_34Xre->vGu3Vh1Q3cnydztqCSZ_RQ#Vr-N z9wHn4&%EQ}QWUkcXaLQ%us#@3-mLF5f|hhVO_U-v2i6%IbPX=X@iWtWV%SmgjQK2# zCCO(Up+?*R70SLYM;EFfzp1;EoRU%rNcJkU$Jr4V!`&DCU4ipOkt$t%eeHOsH>H`^ z6VgmvQC{tZ1qH(ma4#Sy78eJa2i40XpYh{@H;N4<@^5F`3_pDOY+|@~@XBuwa|49l zmoLdYXEeHM%~GOL$en7ju6|u6rrU}TE6MGtnvT}Fn2L+}#4%}yJ@co}C6L>gtVg5% zFn}JIIDG?MaxVsLYde1N{?2XSGkWIrd)3dzMu1OUNvr}ZC6%BBy!HgBilQwJ8nrFD zMK3G<)iSyn&H@Ihvj^x^0d*ytv%(D^TMY0Ll?QJ_AKSdjcAv z1i_0aO**`T{xgzu+YLGJj`&>|0B#$gI_f<(8FH_N%@d?hoQa@yTV@oC1SUVssznF^szOg6p{3WOY&h)V z>0DtBaBW0*)DYDtU1W&e;dKkJT`@PmEk|93AfhdVvCEhD9tR31Ze9Op0z zZEf5T3Wmb$>@Rpmu696Ue4teT!xD*Mr3L6ZG>@>8N$`;6=i~KJ-cSWVXQPsmQV;Hi zdym`AR#(@Wj_&;;-=@1?)5dQyKL~>ZgtReJEL)Bh%>wj?qN_5ZkCqx@r$O+&*y`~} z1Xt=ZGhG&x`ypLHL>AUj zFooVvyt;g83qe|0j>{z6qi*xx+P1fu?aoktadz}!VWYk|nOkxcD7Z)d$6aCvycZ@O zkm*8L8ek!jxPi6URWQ{2zu&qM f^#9GO-AlK)EX0QLl@`GCBZDfcy)ILD_woM$OJh+r literal 0 HcmV?d00001 diff --git a/plugin/ale/aaflags.vim b/plugin/ale/aaflags.vim index 10d82128..f18dcc43 100644 --- a/plugin/ale/aaflags.vim +++ b/plugin/ale/aaflags.vim @@ -48,3 +48,12 @@ let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0) let g:ale_statusline_format = get(g:, 'ale_statusline_format', \ ['%d error(s)', '%d warning(s)', 'OK'] \) + +" String format for the echoed message +" A %s is mandatory +" It can contain 2 handlers: %linter%, %severity% +let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%s') + +" Strings used for severity in the echoed message +let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error') +let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') diff --git a/plugin/ale/cursor.vim b/plugin/ale/cursor.vim index e0751a8c..24f1f183 100644 --- a/plugin/ale/cursor.vim +++ b/plugin/ale/cursor.vim @@ -7,6 +7,23 @@ endif let g:loaded_ale_cursor = 1 +" Return a formatted message according to g:ale_echo_msg_format variable +function! s:GetMessage(linter, type, text) abort + let msg = g:ale_echo_msg_format + let type = a:type ==# 'E' + \ ? g:ale_echo_msg_error_str + \ : g:ale_echo_msg_warning_str + " Capitalize the 1st character + let text = toupper(a:text[0]) . a:text[1:-1] + + " Replace handlers if they exist + for [k, v] in items({'linter': a:linter, 'severity': type}) + let msg = substitute(msg, '\V%' . k . '%', v, '') + endfor + + return printf(msg, text) +endfunction + " This function will perform a binary search to find a message from the " loclist to echo when the cursor moves. function! s:BinarySearch(loclist, line, column) @@ -81,7 +98,9 @@ function! ale#cursor#EchoCursorWarning(...) let index = s:BinarySearch(loclist, pos[1], pos[2]) if index >= 0 - call ale#cursor#TruncatedEcho(loclist[index]['text']) + let l = loclist[index] + let msg = s:GetMessage(l.linter_name, l.type, l.text) + call ale#cursor#TruncatedEcho(msg) else echo endif