summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorKabbAmine <KabbAmine@users.noreply.github.com>2016-10-10 15:53:54 +0400
committerw0rp <w0rp@users.noreply.github.com>2016-10-10 12:53:54 +0100
commite4b3f579fa3c5e4edc8214194cfab4d8cb8aaa6b (patch)
tree9fccc3ca68d9d120ea1ac14df5f44bb23286fbdf /plugin
parentf60df660f8af489af55270d205ad70a4b569742f (diff)
downloadale-e4b3f579fa3c5e4edc8214194cfab4d8cb8aaa6b.zip
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
Diffstat (limited to 'plugin')
-rw-r--r--plugin/ale/aaflags.vim9
-rw-r--r--plugin/ale/cursor.vim21
2 files changed, 29 insertions, 1 deletions
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