mirror of
https://github.com/amix/vimrc
synced 2025-06-23 06:35:01 +08:00
Updated vim plugins
This commit is contained in:
@ -77,13 +77,19 @@ endfunction
|
||||
|
||||
function! s:on_stderr_vim(channel, _data) dict abort
|
||||
call self.handler.err(self.buffer)
|
||||
try
|
||||
call ch_close(a:channel) " so close_cb and its 'out' handler are not triggered
|
||||
catch /E906/
|
||||
" noop
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:on_exit_vim(_channel) dict abort
|
||||
call self.handler.out(self.buffer, join(self.stdoutbuffer, "\n"))
|
||||
function! s:on_exit_vim(channel) dict abort
|
||||
let job = ch_getjob(a:channel)
|
||||
while 1
|
||||
if job_status(job) == 'dead'
|
||||
let exit_code = job_info(job).exitval
|
||||
break
|
||||
endif
|
||||
sleep 5m
|
||||
endwhile
|
||||
|
||||
if !exit_code
|
||||
call self.handler.out(self.buffer, join(self.stdoutbuffer, "\n"))
|
||||
endif
|
||||
endfunction
|
||||
|
@ -13,6 +13,7 @@ let s:c_flag = s:git_supports_command_line_config_override()
|
||||
|
||||
let s:temp_from = tempname()
|
||||
let s:temp_buffer = tempname()
|
||||
let s:counter = 0
|
||||
|
||||
" Returns a diff of the buffer against the index or the working tree.
|
||||
"
|
||||
@ -89,6 +90,11 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
||||
" git-diff).
|
||||
let buff_file = s:temp_buffer.'.'.a:bufnr
|
||||
|
||||
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
||||
" Use a modulus greater than a maximum reasonable number of visible buffers.
|
||||
let s:counter = (s:counter + 1) % 20
|
||||
let buff_file .= '.'.s:counter
|
||||
|
||||
let extension = gitgutter#utility#extension(a:bufnr)
|
||||
if !empty(extension)
|
||||
let buff_file .= '.'.extension
|
||||
@ -104,6 +110,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
||||
" reading it (with git-diff).
|
||||
let from_file = s:temp_from.'.'.a:bufnr
|
||||
|
||||
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
||||
let from_file .= '.'.s:counter
|
||||
|
||||
if !empty(extension)
|
||||
let from_file .= '.'.extension
|
||||
endif
|
||||
@ -365,6 +374,13 @@ endfunction
|
||||
function! s:write_buffer(bufnr, file)
|
||||
let bufcontents = getbufline(a:bufnr, 1, '$')
|
||||
|
||||
if bufcontents == [''] && line2byte(1) == -1
|
||||
" Special case: completely empty buffer.
|
||||
" A nearly empty buffer of only a newline has line2byte(1) == 1.
|
||||
call writefile([], a:file)
|
||||
return
|
||||
endif
|
||||
|
||||
if getbufvar(a:bufnr, '&fileformat') ==# 'dos'
|
||||
call map(bufcontents, 'v:val."\r"')
|
||||
endif
|
||||
|
@ -8,7 +8,12 @@ endfunction
|
||||
|
||||
function! gitgutter#utility#setbufvar(buffer, varname, val)
|
||||
let buffer = +a:buffer
|
||||
let dict = get(getbufvar(buffer, '', {}), 'gitgutter', {})
|
||||
" Default value for getbufvar() was introduced in Vim 7.3.831.
|
||||
let bvars = getbufvar(buffer, '')
|
||||
if empty(bvars)
|
||||
let bvars = {}
|
||||
endif
|
||||
let dict = get(bvars, 'gitgutter', {})
|
||||
let needs_setting = empty(dict)
|
||||
let dict[a:varname] = a:val
|
||||
if needs_setting
|
||||
@ -115,7 +120,7 @@ function! gitgutter#utility#set_repo_path(bufnr) abort
|
||||
" * -2 - not tracked by git
|
||||
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
|
||||
let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' ls-files --error-unmatch --full-name -- '.gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
||||
let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' ls-files --error-unmatch --full-name -z -- '.gitgutter#utility#shellescape(s:filename(a:bufnr)))
|
||||
|
||||
if g:gitgutter_async && gitgutter#async#available()
|
||||
if has('lambda')
|
||||
@ -202,8 +207,13 @@ function! s:exists_file(bufnr) abort
|
||||
return filereadable(s:abs_path(a:bufnr, 0))
|
||||
endfunction
|
||||
|
||||
" Get rid of any trailing new line or SOH character.
|
||||
"
|
||||
" git ls-files -z produces output with null line termination.
|
||||
" Vim's system() replaces any null characters in the output
|
||||
" with SOH (start of header), i.e. ^A.
|
||||
function! s:strip_trailing_new_line(line) abort
|
||||
return substitute(a:line, '\n$', '', '')
|
||||
return substitute(a:line, '[[:cntrl:]]$', '', '')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#windows()
|
||||
|
@ -191,6 +191,20 @@ function Test_filename_leading_dash()
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_filename_umlaut()
|
||||
call system('touch -- fixtüre.txt && git add -- fixtüre.txt')
|
||||
edit fixtüre.txt
|
||||
normal ggo*
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = [
|
||||
\ 'line=1 id=3000 name=GitGutterLineAdded',
|
||||
\ 'line=2 id=3001 name=GitGutterLineAdded'
|
||||
\ ]
|
||||
call assert_equal(expected, s:signs('fixtüre.txt'))
|
||||
endfunction
|
||||
|
||||
|
||||
" FIXME: this test fails when it is the first (or only) test to be run
|
||||
function Test_follow_symlink()
|
||||
let tmp = 'symlink'
|
||||
@ -273,6 +287,7 @@ function Test_untracked_file_within_repo()
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs(tmp))
|
||||
call assert_equal(-2, b:gitgutter.path)
|
||||
|
||||
call system('rm '.tmp)
|
||||
endfunction
|
||||
@ -633,3 +648,33 @@ function Test_encoding()
|
||||
|
||||
call assert_equal([], s:signs('cp932.txt'))
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_empty_file()
|
||||
" 0-byte file
|
||||
call system('touch empty.txt && git add empty.txt')
|
||||
edit empty.txt
|
||||
|
||||
call s:trigger_gitgutter()
|
||||
call assert_equal([], s:signs('empty.txt'))
|
||||
|
||||
|
||||
" File consisting only of a newline
|
||||
call system('echo "" > newline.txt && git add newline.txt')
|
||||
edit newline.txt
|
||||
|
||||
call s:trigger_gitgutter()
|
||||
call assert_equal([], s:signs('newline.txt'))
|
||||
|
||||
|
||||
" 1 line file without newline
|
||||
" Vim will force a newline unless we tell it not to.
|
||||
call system('echo -n a > oneline.txt && git add oneline.txt')
|
||||
set noeol nofixeol
|
||||
edit! oneline.txt
|
||||
|
||||
call s:trigger_gitgutter()
|
||||
call assert_equal([], s:signs('oneline.txt'))
|
||||
|
||||
set eol fixeol
|
||||
endfunction
|
||||
|
Reference in New Issue
Block a user