]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/history.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / history.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Tools for managing command history
3
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)
6
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', []))
10 endfunction
11
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', [])
16
17         return
18     endif
19
20     let l:history = getbufvar(a:buffer, 'ale_history', [])
21
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:]
25     endif
26
27     call add(l:history, {
28     \   'status': a:status,
29     \   'job_id': a:job_id,
30     \   'command': a:command,
31     \})
32
33     call setbufvar(a:buffer, 'ale_history', l:history)
34 endfunction
35
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
41             return l:obj
42         endif
43     endfor
44
45     return {}
46 endfunction
47
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)
51
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'
55 endfunction
56
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)
60
61     let l:obj.output = a:output
62 endfunction