Fix detailed messages with newline characters

This commit is contained in:
w0rp 2017-03-04 23:55:12 +00:00
parent c1947d13cf
commit 76df2d393b
2 changed files with 19 additions and 8 deletions

View File

@ -23,16 +23,19 @@ function! s:EchoWithShortMess(setting, message) abort
let l:shortmess_options = getbufvar('%', '&shortmess') let l:shortmess_options = getbufvar('%', '&shortmess')
try try
" Turn shormess on or off. " Turn shortmess on or off.
if a:setting ==# 'on' if a:setting ==# 'on'
setlocal shortmess+=T setlocal shortmess+=T
" echomsg is neede for the message to get truncated and appear in
" the message history.
exec "norm! :echomsg a:message\n"
elseif a:setting ==# 'off' elseif a:setting ==# 'off'
setlocal shortmess-=T setlocal shortmess-=T
" Regular echo is needed for printing newline characters.
echo a:message
else else
throw 'Invalid setting: ' . string(a:setting) throw 'Invalid setting: ' . string(a:setting)
endif endif
exec "norm! :echomsg a:message\n"
finally finally
call setbufvar('%', '&shortmess', l:shortmess_options) call setbufvar('%', '&shortmess', l:shortmess_options)
endtry endtry

View File

@ -11,7 +11,7 @@ Before:
\ 'nr': -1, \ 'nr': -1,
\ 'type': 'E', \ 'type': 'E',
\ 'text': 'Missing semicolon. (semi)', \ 'text': 'Missing semicolon. (semi)',
\ 'detail': 'Every statement should end with a semicolon' \ 'detail': "Every statement should end with a semicolon\nsecond line"
\ }, \ },
\ { \ {
\ 'lnum': 2, \ 'lnum': 2,
@ -61,6 +61,8 @@ After:
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
unlet! g:output
delfunction GetLastMessage delfunction GetLastMessage
mess clear mess clear
@ -104,12 +106,18 @@ Execute(The message at the cursor should be shown on InsertLeave):
Execute(ALEDetail should print 'detail' attributes): Execute(ALEDetail should print 'detail' attributes):
call cursor(1, 1) call cursor(1, 1)
ALEDetail
AssertEqual "Every statement should end with a semicolon", GetLastMessage() redir => g:output
ALEDetail
redir END
AssertEqual "\nEvery statement should end with a semicolon\nsecond line", g:output
Execute(ALEDetail should print regular 'text' attributes): Execute(ALEDetail should print regular 'text' attributes):
call cursor(2, 10) call cursor(2, 10)
ALEDetail
AssertEqual "Infix operators must be spaced. (space-infix-ops)", GetLastMessage() redir => g:output
ALEDetail
redir END
AssertEqual "\nInfix operators must be spaced. (space-infix-ops)", g:output