All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 " Author: w0rp <devw0rp@gmail.com>
3 " Author: João Paulo S. de Souza <joao.paulo.silvasouza@hotmail.com>
4 " Description: Echoes lint message for the current line, if any
6 " Controls the milliseconds delay before echoing a message.
7 let g:ale_echo_delay = get(g:, 'ale_echo_delay', 10)
8 " A string format for the echoed message.
9 let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%code: %%s')
11 let s:cursor_timer = -1
13 " A wrapper for echon so we can test messages we echo in Vader tests.
14 function! ale#cursor#Echom(message) abort
17 exec "norm! :echom a:message\n"
21 function! ale#cursor#TruncatedEcho(original_message) abort
22 let l:message = a:original_message
23 " Change tabs to spaces.
24 let l:message = substitute(l:message, "\t", ' ', 'g')
25 " Remove any newlines in the message.
26 let l:message = substitute(l:message, "\n", '', 'g')
27 " Convert indentation groups into single spaces for better legibility when
28 " put on a single line
29 let l:message = substitute(l:message, ' \+', ' ', 'g')
31 " We need to remember the setting for shortmess and reset it again.
32 let l:shortmess_options = &l:shortmess
35 let l:cursor_position = getpos('.')
37 " The message is truncated and saved to the history.
38 silent! setlocal shortmess+=T
41 call ale#cursor#Echom(l:message)
42 catch /^Vim\%((\a\+)\)\=:E523/
43 " Fallback into manual truncate (#1987)
44 let l:winwidth = winwidth(0)
46 if l:winwidth < strdisplaywidth(l:message)
47 " Truncate message longer than window width with trailing '...'
48 let l:message = l:message[:l:winwidth - 4] . '...'
51 exec 'echomsg l:message'
53 " Do nothing if running from a visual selection.
56 " Reset the cursor position if we moved off the end of the line.
57 " Using :norm and :echomsg can move the cursor off the end of the
59 if l:cursor_position != getpos('.')
60 call setpos('.', l:cursor_position)
63 let &l:shortmess = l:shortmess_options
67 function! s:StopCursorTimer() abort
68 if s:cursor_timer != -1
69 call timer_stop(s:cursor_timer)
70 let s:cursor_timer = -1
74 function! ale#cursor#EchoCursorWarning(...) abort
75 let l:buffer = bufnr('')
77 if !g:ale_echo_cursor && !g:ale_cursor_detail
81 " Only echo the warnings in normal mode, otherwise we will get problems.
86 if ale#ShouldDoNothing(l:buffer)
90 let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
94 let l:format = ale#Var(l:buffer, 'echo_msg_format')
95 let l:msg = ale#GetLocItemMessage(l:loc, l:format)
96 call ale#cursor#TruncatedEcho(l:msg)
98 elseif get(l:info, 'echoed')
99 " We'll only clear the echoed message when moving off errors once,
100 " so we don't continually clear the echo line.
104 let l:info.echoed = 0
108 if g:ale_cursor_detail
110 call s:ShowCursorDetailForItem(l:loc, {'stay_here': 1})
112 call ale#preview#CloseIfTypeMatches('ale-preview')
117 function! ale#cursor#EchoCursorWarningWithDelay() abort
118 let l:buffer = bufnr('')
120 if !g:ale_echo_cursor && !g:ale_cursor_detail
124 " Only echo the warnings in normal mode, otherwise we will get problems.
125 if mode(1) isnot# 'n'
129 call s:StopCursorTimer()
131 let l:pos = getpos('.')[0:2]
133 if !exists('w:last_pos')
134 let w:last_pos = [0, 0, 0]
137 " Check the current buffer, line, and column number against the last
138 " recorded position. If the position has actually changed, *then*
139 " we should echo something. Otherwise we can end up doing processing
140 " the echo message far too frequently.
141 if l:pos != w:last_pos
142 let l:delay = ale#Var(l:buffer, 'echo_delay')
144 let w:last_pos = l:pos
145 let s:cursor_timer = timer_start(
147 \ function('ale#cursor#EchoCursorWarning')
152 function! s:ShowCursorDetailForItem(loc, options) abort
153 let l:stay_here = get(a:options, 'stay_here', 0)
155 let s:last_detailed_line = line('.')
156 let l:message = get(a:loc, 'detail', a:loc.text)
157 let l:lines = split(l:message, "\n")
159 if g:ale_floating_preview || g:ale_detail_to_floating_preview
160 call ale#floating_preview#Show(l:lines)
162 call ale#preview#Show(l:lines, {'stay_here': l:stay_here})
164 " Clear the echo message if we manually displayed details.
172 function! ale#cursor#ShowCursorDetail() abort
173 let l:buffer = bufnr('')
175 " Only echo the warnings in normal mode, otherwise we will get problems.
180 if ale#ShouldDoNothing(l:buffer)
184 call s:StopCursorTimer()
186 let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
189 call s:ShowCursorDetailForItem(l:loc, {'stay_here': 0})