1
0
mirror of https://github.com/amix/vimrc synced 2025-07-08 17:56:29 +08:00

Merge remote-tracking branch 'refs/remotes/upstream/master'

Conflicts:
	sources_non_forked/ale/autoload/ale.vim
	sources_non_forked/lightline.vim/doc/lightline.txt
	sources_non_forked/nerdtree/.github/PULL_REQUEST_TEMPLATE.md
	sources_non_forked/nerdtree/autoload/nerdtree.vim
	sources_non_forked/nerdtree/plugin/NERD_tree.vim
	sources_non_forked/vim-fugitive/autoload/fugitive.vim
	sources_non_forked/vim-fugitive/doc/fugitive.txt
This commit is contained in:
geezuslucifer@gmail.com
2021-02-19 08:50:18 -06:00
352 changed files with 11973 additions and 4879 deletions

View File

@ -1,5 +1,3 @@
let s:t_string = type('')
" Primary functions {{{
function! gitgutter#all(force) abort
@ -42,7 +40,7 @@ function! gitgutter#process_buffer(bufnr, force) abort
if a:force || s:has_fresh_changes(a:bufnr)
let diff = ''
let diff = 'NOT SET'
try
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
catch /gitgutter not tracked/
@ -52,7 +50,7 @@ function! gitgutter#process_buffer(bufnr, force) abort
call gitgutter#hunk#reset(a:bufnr)
endtry
if diff != 'async'
if diff != 'async' && diff != 'NOT SET'
call gitgutter#diff#handler(a:bufnr, diff)
endif
@ -174,11 +172,7 @@ function! gitgutter#setup_maps()
endfunction
function! s:setup_path(bufnr, continuation)
let p = gitgutter#utility#repo_path(a:bufnr, 0)
if type(p) == s:t_string && !empty(p) " if path is known
return
endif
if gitgutter#utility#has_repo_path(a:bufnr) | return | endif
<<<<<<< HEAD
call gitgutter#utility#setbufvar(a:bufnr, 'mapped', 1)
@ -219,9 +213,17 @@ endfunction
" - it ignores unsaved changes in buffers
" - it does not change to the repo root
function! gitgutter#quickfix()
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' rev-parse --show-cdup'
let path_to_repo = get(systemlist(cmd), 0, '')
if !empty(path_to_repo) && path_to_repo[-1:] != '/'
let path_to_repo .= '/'
endif
let locations = []
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager '.g:gitgutter_git_args.
\ ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'.
\ ' diff --no-ext-diff --no-color -U0'.
\ ' --src-prefix=a/'.path_to_repo.' --dst-prefix=b/'.path_to_repo.' '.
\ g:gitgutter_diff_args. ' '. g:gitgutter_diff_base
let diff = systemlist(cmd)
let lnum = 0
for line in diff

View File

@ -6,6 +6,8 @@ let s:available = has('nvim') || (
\ )
\ )
let s:jobs = {}
function! gitgutter#async#available()
return s:available
endfunction
@ -28,11 +30,12 @@ function! gitgutter#async#execute(cmd, bufnr, handler) abort
\ 'on_exit': function('s:on_exit_nvim')
\ }))
else
call job_start(command, {
let job = job_start(command, {
\ 'out_cb': function('s:on_stdout_vim', options),
\ 'err_cb': function('s:on_stderr_vim', options),
\ 'close_cb': function('s:on_exit_vim', options)
\ })
let s:jobs[s:job_id(job)] = 1
endif
endfunction
@ -83,6 +86,8 @@ endfunction
function! s:on_exit_vim(channel) dict abort
let job = ch_getjob(a:channel)
let jobid = s:job_id(job)
if has_key(s:jobs, jobid) | unlet s:jobs[jobid] | endif
while 1
if job_status(job) == 'dead'
let exit_code = job_info(job).exitval
@ -95,3 +100,8 @@ function! s:on_exit_vim(channel) dict abort
call self.handler.out(self.buffer, join(self.stdoutbuffer, "\n"))
endif
endfunction
function! s:job_id(job)
" Vim
return job_info(a:job).process
endfunction

View File

@ -22,16 +22,6 @@ function! gitgutter#debug#debug()
call s:separator()
call s:option('updatetime')
call s:option('shell')
call s:option('shellcmdflag')
call s:option('shellpipe')
call s:option('shellquote')
call s:option('shellredir')
call s:option('shellslash')
call s:option('shelltemp')
call s:option('shelltype')
call s:option('shellxescape')
call s:option('shellxquote')
endfunction
@ -52,10 +42,10 @@ function! s:git_version()
endfunction
function! s:grep_version()
let v = system('grep --version')
let v = system(g:gitgutter_grep.' --version')
call s:output( substitute(v, '\n$', '', '') )
let v = system('grep --help')
let v = system(g:gitgutter_grep.' --help')
call s:output( substitute(v, '\%x00', '', 'g') )
endfunction

View File

@ -1,3 +1,5 @@
scriptencoding utf8
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
@ -14,7 +16,6 @@ endfunction
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
@ -122,7 +123,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
endif
" Write file from index to temporary file.
let index_name = g:gitgutter_diff_base.':'.gitgutter#utility#repo_path(a:bufnr, 1)
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.' && '
elseif a:from ==# 'working_tree'
@ -130,7 +131,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
endif
" Call git-diff.
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager '.g:gitgutter_git_args
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'
if s:c_flag
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'
@ -184,7 +185,7 @@ function! gitgutter#diff#handler(bufnr, diff) abort
let modified_lines = gitgutter#diff#process_hunks(a:bufnr, gitgutter#hunk#hunks(a:bufnr))
let signs_count = len(modified_lines)
if signs_count > g:gitgutter_max_signs
if g:gitgutter_max_signs != -1 && signs_count > g:gitgutter_max_signs
call gitgutter#utility#warn_once(a:bufnr, printf(
\ 'exceeded maximum number of signs (%d > %d, configured by g:gitgutter_max_signs).',
\ signs_count, g:gitgutter_max_signs), 'max_signs')
@ -402,12 +403,19 @@ function! s:write_buffer(bufnr, file)
let bufcontents[0]=''.bufcontents[0]
endif
call writefile(bufcontents, a:file, 'b')
" The file we are writing to is a temporary file. Sometimes the parent
" directory is deleted outside Vim but, because Vim caches the directory
" name at startup and does not check for its existence subsequently, Vim
" does not realise. This causes E482 errors.
try
call writefile(bufcontents, a:file, 'b')
catch /E482/
call mkdir(fnamemodify(a:file, ':h'), '', '0700')
call writefile(bufcontents, a:file, 'b')
endtry
endfunction
function! s:save_last_seen_change(bufnr) abort
call gitgutter#utility#setbufvar(a:bufnr, 'tick', getbufvar(a:bufnr, 'changedtick'))
endfunction

View File

@ -64,14 +64,6 @@ function! gitgutter#highlight#linenr_toggle() abort
endfunction
function! gitgutter#highlight#define_sign_column_highlight() abort
if g:gitgutter_override_sign_column_highlight
highlight! link SignColumn LineNr
else
highlight default link SignColumn LineNr
endif
endfunction
function! gitgutter#highlight#define_highlights() abort
let [guibg, ctermbg] = s:get_background_colors('SignColumn')
@ -84,12 +76,24 @@ function! gitgutter#highlight#define_highlights() abort
highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible
" When they are visible.
" By default use Diff* foreground colors with SignColumn's background.
for type in ['Add', 'Change', 'Delete']
let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type)
execute "highlight GitGutter".type."Default guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
execute "highlight default link GitGutter".type." GitGutter".type."Default"
for type in ["Add", "Change", "Delete"]
if hlexists("GitGutter".type) && s:get_foreground_colors("GitGutter".type) != ['NONE', 'NONE']
if g:gitgutter_set_sign_backgrounds
execute "highlight GitGutter".type." guibg=".guibg." ctermbg=".ctermbg
endif
continue
elseif s:useful_diff_colours()
let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type)
else
let [guifg, ctermfg] = s:get_foreground_fallback_colors(type)
endif
execute "highlight GitGutter".type." guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
endfor
if hlexists("GitGutterChangeDelete") && g:gitgutter_set_sign_backgrounds
execute "highlight GitGutterChangeDelete guibg=".guibg." ctermbg=".ctermbg
endif
highlight default link GitGutterChangeDelete GitGutterChange
" Highlights used for the whole line.
@ -107,6 +111,14 @@ function! gitgutter#highlight#define_highlights() abort
" Highlights used intra line.
highlight GitGutterAddIntraLine gui=reverse cterm=reverse
highlight GitGutterDeleteIntraLine gui=reverse cterm=reverse
" Set diff syntax colours (used in the preview window) - diffAdded,diffChanged,diffRemoved -
" to match the signs, if not set aleady.
for [dtype,type] in [['Added','Add'], ['Changed','Change'], ['Removed','Delete']]
if !hlexists('diff'.dtype)
let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type)
execute "highlight diff".dtype." guifg=".guifg." ctermfg=".ctermfg." guibg=NONE ctermbg=NONE"
endif
endfor
endfunction
function! gitgutter#highlight#define_signs() abort
@ -217,3 +229,20 @@ function! s:get_background_colors(group) abort
let guibg = s:get_hl(a:group, 'bg', 'gui')
return [guibg, ctermbg]
endfunction
function! s:useful_diff_colours()
let [guifg_add, ctermfg_add] = s:get_foreground_colors('DiffAdd')
let [guifg_del, ctermfg_del] = s:get_foreground_colors('DiffDelete')
return guifg_add != guifg_del && ctermfg_add != ctermfg_del
endfunction
function! s:get_foreground_fallback_colors(type)
if a:type == 'Add'
return ['#009900', '2']
elseif a:type == 'Change'
return ['#bbbb00', '3']
elseif a:type == 'Delete'
return ['#ff2222', '1']
endif
endfunction

View File

@ -1,4 +1,6 @@
let s:winid = 0
let s:preview_bufnr = 0
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
function! gitgutter#hunk#set_hunks(bufnr, hunks) abort
call gitgutter#utility#setbufvar(a:bufnr, 'hunks', a:hunks)
@ -44,39 +46,57 @@ endfunction
function! gitgutter#hunk#next_hunk(count) abort
let bufnr = bufnr('')
if gitgutter#utility#is_active(bufnr)
let current_line = line('.')
let hunk_count = 0
for hunk in gitgutter#hunk#hunks(bufnr)
if hunk[2] > current_line
let hunk_count += 1
if hunk_count == a:count
execute 'normal!' hunk[2] . 'Gzv'
return
endif
endif
endfor
call gitgutter#utility#warn('No more hunks')
if !gitgutter#utility#is_active(bufnr) | return | endif
let hunks = gitgutter#hunk#hunks(bufnr)
if empty(hunks)
call gitgutter#utility#warn('No hunks in file')
return
endif
let current_line = line('.')
let hunk_count = 0
for hunk in hunks
if hunk[2] > current_line
let hunk_count += 1
if hunk_count == a:count
execute 'normal!' hunk[2] . 'Gzv'
if g:gitgutter_show_msg_on_hunk_jumping
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
endif
return
endif
endif
endfor
call gitgutter#utility#warn('No more hunks')
endfunction
function! gitgutter#hunk#prev_hunk(count) abort
let bufnr = bufnr('')
if gitgutter#utility#is_active(bufnr)
let current_line = line('.')
let hunk_count = 0
for hunk in reverse(copy(gitgutter#hunk#hunks(bufnr)))
if hunk[2] < current_line
let hunk_count += 1
if hunk_count == a:count
let target = hunk[2] == 0 ? 1 : hunk[2]
execute 'normal!' target . 'Gzv'
return
endif
endif
endfor
call gitgutter#utility#warn('No previous hunks')
if !gitgutter#utility#is_active(bufnr) | return | endif
let hunks = gitgutter#hunk#hunks(bufnr)
if empty(hunks)
call gitgutter#utility#warn('No hunks in file')
return
endif
let current_line = line('.')
let hunk_count = 0
for hunk in reverse(copy(hunks))
if hunk[2] < current_line
let hunk_count += 1
if hunk_count == a:count
let target = hunk[2] == 0 ? 1 : hunk[2]
execute 'normal!' target . 'Gzv'
if g:gitgutter_show_msg_on_hunk_jumping
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
endif
return
endif
endif
endfor
call gitgutter#utility#warn('No previous hunks')
endfunction
" Returns the hunk the cursor is currently in or an empty list if the cursor
@ -172,6 +192,8 @@ endfunction
function! gitgutter#hunk#stage(...) abort
if !s:in_hunk_preview_window() && !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
if a:0 && (a:1 != 1 || a:2 != line('$'))
call s:hunk_op(function('s:stage'), a:1, a:2)
else
@ -181,11 +203,15 @@ function! gitgutter#hunk#stage(...) abort
endfunction
function! gitgutter#hunk#undo() abort
if !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
call s:hunk_op(function('s:undo'))
silent! call repeat#set("\<Plug>(GitGutterUndoHunk)", -1)
endfunction
function! gitgutter#hunk#preview() abort
if !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
call s:hunk_op(function('s:preview'))
silent! call repeat#set("\<Plug>(GitGutterPreviewHunk)", -1)
endfunction
@ -268,6 +294,10 @@ function! s:stage(hunk_diff)
\ diff)
if v:shell_error
call gitgutter#utility#warn('patch does not apply')
else
if exists('#User#GitGutterStage')
execute 'doautocmd' s:nomodeline 'User GitGutterStage'
endif
endif
" Refresh gitgutter's view of buffer.
@ -428,13 +458,23 @@ function! s:open_hunk_preview_window()
endif
silent! wincmd P
if !&previewwindow
if &previewwindow
file gitgutter://hunk-preview
else
noautocmd execute g:gitgutter_preview_win_location &previewheight 'new gitgutter://hunk-preview'
let s:winid = win_getid()
doautocmd WinEnter
set previewwindow
setlocal filetype=diff buftype=acwrite bufhidden=delete
" Reset some defaults in case someone else has changed them.
setlocal noreadonly modifiable noswapfile
endif
if exists('*win_getid')
let s:winid = win_getid()
else
let s:preview_bufnr = bufnr('')
endif
setlocal filetype=diff buftype=acwrite bufhidden=delete
" Reset some defaults in case someone else has changed them.
setlocal noreadonly modifiable noswapfile
if g:gitgutter_close_preview_on_escape
nnoremap <buffer> <silent> <Esc> :pclose<CR>
endif
endfunction
@ -443,17 +483,22 @@ endfunction
" Preview window: assumes cursor is in preview window.
function! s:populate_hunk_preview_window(header, body)
let body_length = len(a:body)
let height = min([body_length, &previewheight])
if g:gitgutter_preview_win_floating
if exists('*nvim_open_win')
let height = min([body_length, &previewheight])
" Assumes cursor is not in previewing window.
call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header)
let [_scrolloff, &scrolloff] = [&scrolloff, 0]
let width = max(map(copy(a:body), 'strdisplaywidth(v:val)'))
call nvim_win_set_width(s:winid, width)
call nvim_win_set_height(s:winid, height)
let &scrolloff=_scrolloff
call nvim_buf_set_lines(winbufnr(s:winid), 0, -1, v:false, [])
call nvim_buf_set_lines(winbufnr(s:winid), 0, -1, v:false, a:body)
call nvim_buf_set_option(winbufnr(s:winid), 'modified', v:false)
@ -479,12 +524,16 @@ function! s:populate_hunk_preview_window(header, body)
else
let b:hunk_header = a:header
execute 'resize' height
%delete _
call setline(1, a:body)
setlocal nomodified
normal! G$
let height = min([winline(), &previewheight])
execute 'resize' height
1
call clearmatches()
for region in gitgutter#diff_highlight#process(a:body)
let group = region[1] == '+' ? 'GitGutterAddIntraLine' : 'GitGutterDeleteIntraLine'
@ -499,18 +548,21 @@ endfunction
function! s:enable_staging_from_hunk_preview_window()
augroup gitgutter_hunk_preview
autocmd!
execute 'autocmd BufWriteCmd <buffer='.winbufnr(s:winid).'> GitGutterStageHunk'
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
execute 'autocmd BufWriteCmd <buffer='.bufnr.'> GitGutterStageHunk'
augroup END
endfunction
function! s:goto_original_window()
noautocmd wincmd p
doautocmd WinEnter
endfunction
function! s:close_hunk_preview_window()
call setbufvar(winbufnr(s:winid), '&modified', 0)
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
call setbufvar(bufnr, '&modified', 0)
if g:gitgutter_preview_win_floating
if win_id2win(s:winid) > 0
@ -521,4 +573,5 @@ function! s:close_hunk_preview_window()
endif
let s:winid = 0
let s:preview_bufnr = 0
endfunction

View File

@ -9,25 +9,19 @@ endfunction
function! gitgutter#utility#setbufvar(buffer, varname, val)
let buffer = +a:buffer
" 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
call setbufvar(buffer, 'gitgutter', dict)
let ggvars = getbufvar(buffer, 'gitgutter')
if type(ggvars) == type('')
unlet ggvars
let ggvars = {}
call setbufvar(buffer, 'gitgutter', ggvars)
endif
let ggvars[a:varname] = a:val
endfunction
function! gitgutter#utility#getbufvar(buffer, varname, ...)
let bvars = getbufvar(a:buffer, '')
if !empty(bvars)
let dict = get(bvars, 'gitgutter', {})
if has_key(dict, a:varname)
return dict[a:varname]
endif
let ggvars = getbufvar(a:buffer, 'gitgutter')
if type(ggvars) == type({}) && has_key(ggvars, a:varname)
return ggvars[a:varname]
endif
if a:0
return a:1
@ -105,6 +99,10 @@ function! gitgutter#utility#system(cmd, ...) abort
return output
endfunction
function! gitgutter#utility#has_repo_path(bufnr)
return index(['', -1, -2], gitgutter#utility#repo_path(a:bufnr, 0)) == -1
endfunction
" Path of file relative to repo root.
"
" * empty string - not set
@ -112,7 +110,7 @@ endfunction
" * -1 - pending
" * -2 - not tracked by git
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
let p = gitgutter#utility#getbufvar(a:bufnr, 'path')
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
return a:shellesc ? gitgutter#utility#shellescape(p) : p
endfunction
@ -164,7 +162,7 @@ endfunction
function! gitgutter#utility#cd_cmd(bufnr, cmd) abort
let cd = s:unc_path(a:bufnr) ? 'pushd' : (gitgutter#utility#windows() ? 'cd /d' : 'cd')
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
endfunction
@ -172,6 +170,10 @@ function! s:unc_path(bufnr)
return s:abs_path(a:bufnr, 0) =~ '^\\\\'
endfunction
function! s:dos_shell()
return &shell == 'cmd.exe' || &shell == 'command.com'
endfunction
function! s:use_known_shell() abort
if has('unix') && &shell !=# 'sh'
let [s:shell, s:shellcmdflag, s:shellredir] = [&shell, &shellcmdflag, &shellredir]
@ -186,8 +188,21 @@ function! s:restore_shell() abort
endif
endfunction
function! gitgutter#utility#get_diff_base(bufnr)
let p = resolve(expand('#'.a:bufnr.':p'))
let ml = matchlist(p, '\v^fugitive:/.*/(\x{40,})/')
if !empty(ml) && !empty(ml[1])
return ml[1].'^'
endif
return g:gitgutter_diff_base
endfunction
function! s:abs_path(bufnr, shellesc)
let p = resolve(expand('#'.a:bufnr.':p'))
" Remove extra parts from fugitive's filepaths
let p = substitute(substitute(p, '^fugitive:', '', ''), '\v\.git/\x{40,}/', '', '')
return a:shellesc ? gitgutter#utility#shellescape(p) : p
endfunction