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.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Tools for managing command history
4 " A flag for controlling the maximum size of the command history to store.
5 let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20)
7 " Return a shallow copy of the command history for a given buffer number.
8 function! ale#history#Get(buffer) abort
9 return copy(getbufvar(a:buffer, 'ale_history', []))
12 function! ale#history#Add(buffer, status, job_id, command) abort
13 if g:ale_max_buffer_history_size <= 0
14 " Don't save anything if the history isn't a positive number.
15 call setbufvar(a:buffer, 'ale_history', [])
20 let l:history = getbufvar(a:buffer, 'ale_history', [])
22 " Remove the first item if we hit the max history size.
23 if len(l:history) >= g:ale_max_buffer_history_size
24 let l:history = l:history[1:]
30 \ 'command': a:command,
33 call setbufvar(a:buffer, 'ale_history', l:history)
36 function! s:FindHistoryItem(buffer, job_id) abort
37 " Search backwards to find a matching job ID. IDs might be recycled,
38 " so finding the last one should be good enough.
39 for l:obj in reverse(ale#history#Get(a:buffer))
40 if l:obj.job_id == a:job_id
48 " Set an exit code for a command which finished.
49 function! ale#history#SetExitCode(buffer, job_id, exit_code) abort
50 let l:obj = s:FindHistoryItem(a:buffer, a:job_id)
52 " If we find a match, then set the code and status.
53 let l:obj.exit_code = a:exit_code
54 let l:obj.status = 'finished'
57 " Set the output for a command which finished.
58 function! ale#history#RememberOutput(buffer, job_id, output) abort
59 let l:obj = s:FindHistoryItem(a:buffer, a:job_id)
61 let l:obj.output = a:output