1
0
mirror of https://github.com/amix/vimrc synced 2025-06-30 20:05:01 +08:00

Updated plugins

This commit is contained in:
Amir
2023-07-15 12:43:27 +02:00
parent 68cf3c02e2
commit 747d4093f4
52 changed files with 767 additions and 165 deletions

View File

@ -75,23 +75,21 @@ function! gitgutter#debug#log(message, ...) abort
endif
endif
execute 'redir >> '.s:log_file
if s:new_log_session
let s:start = reltime()
silent echo "\n==== start log session ===="
endif
if s:new_log_session
let s:start = reltime()
call writefile(['', '========== start log session '.strftime('%d.%m.%Y %H:%M:%S').' =========='], s:log_file, 'a')
endif
let elapsed = reltimestr(reltime(s:start)).' '
silent echo ''
" callers excluding this function
silent echo elapsed.expand('<sfile>')[:-22].':'
silent echo elapsed.s:format_for_log(a:message)
if a:0 && !empty(a:1)
for msg in a:000
silent echo elapsed.s:format_for_log(msg)
endfor
endif
redir END
let elapsed = reltimestr(reltime(s:start)).' '
call writefile([''], s:log_file, 'a')
" callers excluding this function
call writefile([elapsed.expand('<sfile>')[:-22].':'], s:log_file, 'a')
call writefile([elapsed.s:format_for_log(a:message)], s:log_file, 'a')
if a:0 && !empty(a:1)
for msg in a:000
call writefile([elapsed.s:format_for_log(msg)], s:log_file, 'a')
endfor
endif
let s:new_log_session = 0
endif

View File

@ -6,7 +6,7 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(g:gitgutter_git_executable.' '.g:gitgutter_git_args.' -c foo.bar=baz --version')
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error
endfunction
@ -81,6 +81,20 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter assume unchanged'
endif
" If we are diffing against a specific branch/commit, handle the case
" where a file exists on the current branch but not in/at the diff base.
" We have to handle it here because the approach below (using git-show)
" doesn't work for this case.
if !empty(g:gitgutter_diff_base)
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd)
if v:shell_error
throw 'gitgutter file unknown in base'
endif
endif
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('
@ -124,14 +138,14 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Write file from index to temporary file.
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name.' > '.from_file.' && '
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' && '
elseif a:from ==# 'working_tree'
let from_file = gitgutter#utility#repo_path(a:bufnr, 1)
endif
" Call git-diff.
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'
let cmd .= gitgutter#git().' --no-pager'
if s:c_flag
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'
@ -376,6 +390,12 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...)
endfunction
function! gitgutter#diff#hunk_header_showing_every_line_added(bufnr)
let buf_line_count = getbufinfo(a:bufnr)[0].linecount
return '@@ -0,0 +1,'.buf_line_count.' @@'
endfunction
function! s:write_buffer(bufnr, file)
let bufcontents = getbufline(a:bufnr, 1, '$')
@ -387,7 +407,13 @@ function! s:write_buffer(bufnr, file)
endif
if getbufvar(a:bufnr, '&fileformat') ==# 'dos'
call map(bufcontents, 'v:val."\r"')
if getbufvar(a:bufnr, '&endofline')
call map(bufcontents, 'v:val."\r"')
else
for i in range(len(bufcontents) - 1)
let bufcontents[i] = bufcontents[i] . "\r"
endfor
endif
endif
if getbufvar(a:bufnr, '&endofline')

View File

@ -106,7 +106,7 @@ function! gitgutter#highlight#define_highlights() abort
highlight default link GitGutterAddLineNr CursorLineNr
highlight default link GitGutterChangeLineNr CursorLineNr
highlight default link GitGutterDeleteLineNr CursorLineNr
highlight default link GitGutterChangeDeleteLineNr CursorLineNr
highlight default link GitGutterChangeDeleteLineNr GitGutterChangeLineNr
" Highlights used intra line.
highlight default GitGutterAddIntraLine gui=reverse cterm=reverse

View File

@ -294,11 +294,32 @@ endfunction
function! s:stage(hunk_diff)
let bufnr = bufnr('')
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' apply --cached --unidiff-zero - '),
\ diff)
if gitgutter#utility#clean_smudge_filter_applies(bufnr)
let choice = input('File uses clean/smudge filter. Stage entire file (y/n)? ')
normal! :<ESC>
if choice =~ 'y'
" We are about to add the file to the index so write the buffer to
" ensure the file on disk matches it (the buffer).
write
let path = gitgutter#utility#repo_path(bufnr, 1)
" Add file to index.
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd)
else
return
endif
else
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff)
endif
if v:shell_error
call gitgutter#utility#warn('Patch does not apply')
else
@ -422,6 +443,9 @@ endfunction
" Floating window: does not move cursor to floating window.
" Preview window: moves cursor to preview window.
function! s:open_hunk_preview_window()
let source_wrap = &wrap
let source_window = winnr()
if g:gitgutter_preview_win_floating
if exists('*nvim_open_win')
call gitgutter#hunk#close_hunk_preview_window()
@ -429,6 +453,7 @@ function! s:open_hunk_preview_window()
let buf = nvim_create_buf(v:false, v:false)
" Set default width and height for now.
let s:winid = nvim_open_win(buf, v:false, g:gitgutter_floating_window_options)
call nvim_win_set_option(s:winid, 'wrap', source_wrap ? v:true : v:false)
call nvim_buf_set_option(buf, 'filetype', 'diff')
call nvim_buf_set_option(buf, 'buftype', 'acwrite')
call nvim_buf_set_option(buf, 'bufhidden', 'delete')
@ -458,6 +483,7 @@ function! s:open_hunk_preview_window()
let s:winid = popup_create('', g:gitgutter_floating_window_options)
call setbufvar(winbufnr(s:winid), '&filetype', 'diff')
call setwinvar(s:winid, '&wrap', source_wrap)
return
endif
@ -479,11 +505,13 @@ function! s:open_hunk_preview_window()
let s:preview_bufnr = bufnr('')
endif
setlocal filetype=diff buftype=acwrite bufhidden=delete
let &l:wrap = source_wrap
let b:source_window = source_window
" Reset some defaults in case someone else has changed them.
setlocal noreadonly modifiable noswapfile
if g:gitgutter_close_preview_on_escape
" Ensure cursor goes to the expected window.
nnoremap <buffer> <silent> <Esc> :<C-U>wincmd p<Bar>pclose<CR>
nnoremap <buffer> <silent> <Esc> :<C-U>execute b:source_window . "wincmd w"<Bar>pclose<CR>
endif
if exists('&previewpopup')
@ -594,7 +622,7 @@ endfunction
function! s:goto_original_window()
noautocmd wincmd p
noautocmd execute b:source_window . "wincmd w"
doautocmd WinEnter
endfunction

View File

@ -150,9 +150,8 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#utility#shellescape(s:filename(a:bufnr)))
\ gitgutter#git().' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
let handler = copy(s:set_path_handler)
@ -178,6 +177,20 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
endfunction
function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let filtered = gitgutter#utility#getbufvar(a:bufnr, 'filter', -1)
if filtered == -1
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
return filtered
endfunction
function! gitgutter#utility#cd_cmd(bufnr, cmd) abort
let cd = s:unc_path(a:bufnr) ? 'pushd' : (gitgutter#utility#windows() && s:dos_shell() ? 'cd /d' : 'cd')
return cd.' '.s:dir(a:bufnr).' && '.a:cmd
@ -233,7 +246,7 @@ function! s:dir(bufnr) abort
endfunction
" Not shellescaped.
function! s:filename(bufnr) abort
function! gitgutter#utility#filename(bufnr) abort
return fnamemodify(s:abs_path(a:bufnr, 0), ':t')
endfunction