mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 14:43:35 +08:00 
			
		
		
		
	Updated plugins
This commit is contained in:
		| @ -11,10 +11,16 @@ endfunction | ||||
| let s:c_flag = s:git_supports_command_line_config_override() | ||||
|  | ||||
|  | ||||
| let s:temp_index = tempname() | ||||
| let s:temp_from = tempname() | ||||
| let s:temp_buffer = tempname() | ||||
|  | ||||
| " Returns a diff of the buffer. | ||||
| " Returns a diff of the buffer against the index or the working tree. | ||||
| " | ||||
| " After running the diff we pass it through grep where available to reduce | ||||
| " subsequent processing by the plugin.  If grep is not available the plugin | ||||
| " does the filtering instead. | ||||
| " | ||||
| " When diffing against the index: | ||||
| " | ||||
| " The buffer contents is not the same as the file on disk so we need to pass | ||||
| " two instances of the file to git-diff: | ||||
| @ -27,11 +33,6 @@ let s:temp_buffer = tempname() | ||||
| " | ||||
| " and myfileB is the buffer contents. | ||||
| " | ||||
| " After running the diff we pass it through grep where available to reduce | ||||
| " subsequent processing by the plugin.  If grep is not available the plugin | ||||
| " does the filtering instead. | ||||
| " | ||||
| " | ||||
| " Regarding line endings: | ||||
| " | ||||
| " git-show does not convert line endings. | ||||
| @ -57,7 +58,15 @@ let s:temp_buffer = tempname() | ||||
| " When writing the temporary files we preserve the original file's extension | ||||
| " so that repos using .gitattributes to control EOL conversion continue to | ||||
| " convert correctly. | ||||
| function! gitgutter#diff#run_diff(bufnr, preserve_full_diff) abort | ||||
| " | ||||
| " Arguments: | ||||
| " | ||||
| " bufnr              - the number of the buffer to be diffed | ||||
| " from               - 'index' or 'working_tree'; what the buffer is diffed against | ||||
| " preserve_full_diff - truthy to return the full diff or falsey to return only | ||||
| "                      the hunk headers (@@ -x,y +m,n @@); only possible if | ||||
| "                      grep is available. | ||||
| function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort | ||||
|   while gitgutter#utility#repo_path(a:bufnr, 0) == -1 | ||||
|     sleep 5m | ||||
|   endwhile | ||||
| @ -66,18 +75,13 @@ function! gitgutter#diff#run_diff(bufnr, preserve_full_diff) abort | ||||
|     throw 'gitgutter not tracked' | ||||
|   endif | ||||
|  | ||||
|  | ||||
|   " Wrap compound commands in parentheses to make Windows happy. | ||||
|   " bash doesn't mind the parentheses. | ||||
|   let cmd = '(' | ||||
|  | ||||
|   " Append buffer number to avoid race conditions between writing and reading | ||||
|   " the files when asynchronously processing multiple buffers. | ||||
|   " | ||||
|   " Without the buffer number, index_file would have a race in the shell | ||||
|   " between the second process writing it (with git-show) and the first | ||||
|   " reading it (with git-diff). | ||||
|   let index_file = s:temp_index.'.'.a:bufnr | ||||
|   " Append buffer number to temp filenames to avoid race conditions between | ||||
|   " writing and reading the files when asynchronously processing multiple | ||||
|   " buffers. | ||||
|  | ||||
|   " Without the buffer number, buff_file would have a race between the | ||||
|   " second gitgutter#process_buffer() writing the file (synchronously, below) | ||||
| @ -87,26 +91,39 @@ function! gitgutter#diff#run_diff(bufnr, preserve_full_diff) abort | ||||
|  | ||||
|   let extension = gitgutter#utility#extension(a:bufnr) | ||||
|   if !empty(extension) | ||||
|     let index_file .= '.'.extension | ||||
|     let buff_file .= '.'.extension | ||||
|   endif | ||||
|  | ||||
|   " Write file from index to temporary file. | ||||
|   let index_name = g:gitgutter_diff_base.':'.gitgutter#utility#repo_path(a:bufnr, 1) | ||||
|   let cmd .= g:gitgutter_git_executable.' --no-pager show '.index_name.' > '.index_file.' && ' | ||||
|  | ||||
|   " Write buffer to temporary file. | ||||
|   " Note: this is synchronous. | ||||
|   call s:write_buffer(a:bufnr, buff_file) | ||||
|  | ||||
|   " Call git-diff with the temporary files. | ||||
|   if a:from ==# 'index' | ||||
|     " Without the buffer number, from_file would have a race in the shell | ||||
|     " between the second process writing it (with git-show) and the first | ||||
|     " reading it (with git-diff). | ||||
|     let from_file = s:temp_from.'.'.a:bufnr | ||||
|  | ||||
|     if !empty(extension) | ||||
|       let from_file .= '.'.extension | ||||
|     endif | ||||
|  | ||||
|     " Write file from index to temporary file. | ||||
|     let index_name = g:gitgutter_diff_base.':'.gitgutter#utility#repo_path(a:bufnr, 1) | ||||
|     let cmd .= g:gitgutter_git_executable.' --no-pager show '.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.' --no-pager '.g:gitgutter_git_args | ||||
|   if s:c_flag | ||||
|     let cmd .= ' -c "diff.autorefreshindex=0"' | ||||
|     let cmd .= ' -c "diff.noprefix=false"' | ||||
|     let cmd .= ' -c "core.safecrlf=false"' | ||||
|   endif | ||||
|   let cmd .= ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '.index_file.' '.buff_file | ||||
|   let cmd .= ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '.from_file.' '.buff_file | ||||
|  | ||||
|   " Pipe git-diff output into grep. | ||||
|   if !a:preserve_full_diff && !empty(g:gitgutter_grep) | ||||
| @ -315,8 +332,14 @@ endfunction | ||||
|  | ||||
|  | ||||
| " Returns a diff for the current hunk. | ||||
| function! gitgutter#diff#hunk_diff(bufnr, full_diff) | ||||
| " Assumes there is only 1 current hunk unless the optional argument is given, | ||||
| " in which case the cursor is in two hunks and the argument specifies the one | ||||
| " to choose. | ||||
| " | ||||
| " Optional argument: 0 (to use the first hunk) or 1 (to use the second). | ||||
| function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...) | ||||
|   let modified_diff = [] | ||||
|   let hunk_index = 0 | ||||
|   let keep_line = 1 | ||||
|   " Don't keepempty when splitting because the diff we want may not be the | ||||
|   " final one.  Instead add trailing NL at end of function. | ||||
| @ -324,6 +347,12 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff) | ||||
|     let hunk_info = gitgutter#diff#parse_hunk(line) | ||||
|     if len(hunk_info) == 4  " start of new hunk | ||||
|       let keep_line = gitgutter#hunk#cursor_in_hunk(hunk_info) | ||||
|  | ||||
|       if a:0 && hunk_index != a:1 | ||||
|         let keep_line = 0 | ||||
|       endif | ||||
|  | ||||
|       let hunk_index += 1 | ||||
|     endif | ||||
|     if keep_line | ||||
|       call add(modified_diff, line) | ||||
|  | ||||
| @ -73,6 +73,7 @@ function! gitgutter#highlight#define_signs() abort | ||||
|   sign define GitGutterLineModified | ||||
|   sign define GitGutterLineRemoved | ||||
|   sign define GitGutterLineRemovedFirstLine | ||||
|   sign define GitGutterLineRemovedAboveAndBelow | ||||
|   sign define GitGutterLineModifiedRemoved | ||||
|   sign define GitGutterDummy | ||||
|  | ||||
| @ -82,11 +83,12 @@ function! gitgutter#highlight#define_signs() abort | ||||
| endfunction | ||||
|  | ||||
| function! s:define_sign_text() abort | ||||
|   execute "sign define GitGutterLineAdded            text=" . g:gitgutter_sign_added | ||||
|   execute "sign define GitGutterLineModified         text=" . g:gitgutter_sign_modified | ||||
|   execute "sign define GitGutterLineRemoved          text=" . g:gitgutter_sign_removed | ||||
|   execute "sign define GitGutterLineRemovedFirstLine text=" . g:gitgutter_sign_removed_first_line | ||||
|   execute "sign define GitGutterLineModifiedRemoved  text=" . g:gitgutter_sign_modified_removed | ||||
|   execute "sign define GitGutterLineAdded                 text=" . g:gitgutter_sign_added | ||||
|   execute "sign define GitGutterLineModified              text=" . g:gitgutter_sign_modified | ||||
|   execute "sign define GitGutterLineRemoved               text=" . g:gitgutter_sign_removed | ||||
|   execute "sign define GitGutterLineRemovedFirstLine      text=" . g:gitgutter_sign_removed_first_line | ||||
|   execute "sign define GitGutterLineRemovedAboveAndBelow  text=" . g:gitgutter_sign_removed_above_and_below | ||||
|   execute "sign define GitGutterLineModifiedRemoved       text=" . g:gitgutter_sign_modified_removed | ||||
| endfunction | ||||
|  | ||||
| function! gitgutter#highlight#define_sign_text_highlights() abort | ||||
| @ -95,33 +97,37 @@ function! gitgutter#highlight#define_sign_text_highlights() abort | ||||
|   " off or disabling) we make them invisible by setting their foreground colours | ||||
|   " to the background's. | ||||
|   if g:gitgutter_signs | ||||
|     sign define GitGutterLineAdded            texthl=GitGutterAdd | ||||
|     sign define GitGutterLineModified         texthl=GitGutterChange | ||||
|     sign define GitGutterLineRemoved          texthl=GitGutterDelete | ||||
|     sign define GitGutterLineRemovedFirstLine texthl=GitGutterDelete | ||||
|     sign define GitGutterLineModifiedRemoved  texthl=GitGutterChangeDelete | ||||
|     sign define GitGutterLineAdded                 texthl=GitGutterAdd | ||||
|     sign define GitGutterLineModified              texthl=GitGutterChange | ||||
|     sign define GitGutterLineRemoved               texthl=GitGutterDelete | ||||
|     sign define GitGutterLineRemovedFirstLine      texthl=GitGutterDelete | ||||
|     sign define GitGutterLineRemovedAboveAndBelow  texthl=GitGutterDelete | ||||
|     sign define GitGutterLineModifiedRemoved       texthl=GitGutterChangeDelete | ||||
|   else | ||||
|     sign define GitGutterLineAdded            texthl=GitGutterAddInvisible | ||||
|     sign define GitGutterLineModified         texthl=GitGutterChangeInvisible | ||||
|     sign define GitGutterLineRemoved          texthl=GitGutterDeleteInvisible | ||||
|     sign define GitGutterLineRemovedFirstLine texthl=GitGutterDeleteInvisible | ||||
|     sign define GitGutterLineModifiedRemoved  texthl=GitGutterChangeDeleteInvisible | ||||
|     sign define GitGutterLineAdded                 texthl=GitGutterAddInvisible | ||||
|     sign define GitGutterLineModified              texthl=GitGutterChangeInvisible | ||||
|     sign define GitGutterLineRemoved               texthl=GitGutterDeleteInvisible | ||||
|     sign define GitGutterLineRemovedFirstLine      texthl=GitGutterDeleteInvisible | ||||
|     sign define GitGutterLineRemovedAboveAndBelow  texthl=GitGutterDeleteInvisible | ||||
|     sign define GitGutterLineModifiedRemoved       texthl=GitGutterChangeDeleteInvisible | ||||
|   endif | ||||
| endfunction | ||||
|  | ||||
| function! s:define_sign_line_highlights() abort | ||||
|   if g:gitgutter_highlight_lines | ||||
|     sign define GitGutterLineAdded            linehl=GitGutterAddLine | ||||
|     sign define GitGutterLineModified         linehl=GitGutterChangeLine | ||||
|     sign define GitGutterLineRemoved          linehl=GitGutterDeleteLine | ||||
|     sign define GitGutterLineRemovedFirstLine linehl=GitGutterDeleteLine | ||||
|     sign define GitGutterLineModifiedRemoved  linehl=GitGutterChangeDeleteLine | ||||
|     sign define GitGutterLineAdded                 linehl=GitGutterAddLine | ||||
|     sign define GitGutterLineModified              linehl=GitGutterChangeLine | ||||
|     sign define GitGutterLineRemoved               linehl=GitGutterDeleteLine | ||||
|     sign define GitGutterLineRemovedFirstLine      linehl=GitGutterDeleteLine | ||||
|     sign define GitGutterLineRemovedAboveAndBelow  linehl=GitGutterDeleteLine | ||||
|     sign define GitGutterLineModifiedRemoved       linehl=GitGutterChangeDeleteLine | ||||
|   else | ||||
|     sign define GitGutterLineAdded            linehl= | ||||
|     sign define GitGutterLineModified         linehl= | ||||
|     sign define GitGutterLineRemoved          linehl= | ||||
|     sign define GitGutterLineRemovedFirstLine linehl= | ||||
|     sign define GitGutterLineModifiedRemoved  linehl= | ||||
|     sign define GitGutterLineAdded                 linehl= | ||||
|     sign define GitGutterLineModified              linehl= | ||||
|     sign define GitGutterLineRemoved               linehl= | ||||
|     sign define GitGutterLineRemovedFirstLine      linehl= | ||||
|     sign define GitGutterLineRemovedAboveAndBelow  linehl= | ||||
|     sign define GitGutterLineModifiedRemoved       linehl= | ||||
|   endif | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| @ -93,6 +93,22 @@ function! s:current_hunk() abort | ||||
|   return current_hunk | ||||
| endfunction | ||||
|  | ||||
| " Returns truthy if the cursor is in two hunks (which can only happen if the | ||||
| " cursor is on the first line and lines above have been deleted and lines | ||||
| " immediately below have been deleted) or falsey otherwise. | ||||
| function! s:cursor_in_two_hunks() | ||||
|   let hunks = gitgutter#hunk#hunks(bufnr('')) | ||||
|  | ||||
|   if line('.') == 1 && len(hunks) > 1 && hunks[0][2:3] == [0, 0] && hunks[1][2:3] == [1, 0] | ||||
|     return 1 | ||||
|   endif | ||||
|  | ||||
|   return 0 | ||||
| endfunction | ||||
|  | ||||
| " A line can be in 0 or 1 hunks, with the following exception: when the first | ||||
| " line(s) of a file has been deleted, and the new second line (and | ||||
| " optionally below) has been deleted, the new first line is in two hunks. | ||||
| function! gitgutter#hunk#cursor_in_hunk(hunk) abort | ||||
|   let current_line = line('.') | ||||
|  | ||||
| @ -151,13 +167,24 @@ function! s:hunk_op(op) | ||||
|   if gitgutter#utility#is_active(bufnr) | ||||
|     " Get a (synchronous) diff. | ||||
|     let [async, g:gitgutter_async] = [g:gitgutter_async, 0] | ||||
|     let diff = gitgutter#diff#run_diff(bufnr, 1) | ||||
|     let diff = gitgutter#diff#run_diff(bufnr, 'index', 1) | ||||
|     let g:gitgutter_async = async | ||||
|  | ||||
|     call gitgutter#hunk#set_hunks(bufnr, gitgutter#diff#parse_diff(diff)) | ||||
|  | ||||
|     if empty(s:current_hunk()) | ||||
|       call gitgutter#utility#warn('cursor is not in a hunk') | ||||
|     elseif s:cursor_in_two_hunks() | ||||
|       let choice = input('Choose hunk: upper or lower (u/l)? ') | ||||
|       " Clear input | ||||
|       normal! :<ESC> | ||||
|       if choice =~ 'u' | ||||
|         call a:op(gitgutter#diff#hunk_diff(bufnr, diff, 0)) | ||||
|       elseif choice =~ 'l' | ||||
|         call a:op(gitgutter#diff#hunk_diff(bufnr, diff, 1)) | ||||
|       else | ||||
|         call gitgutter#utility#warn('did not recognise your choice') | ||||
|       endif | ||||
|     else | ||||
|       call a:op(gitgutter#diff#hunk_diff(bufnr, diff)) | ||||
|     endif | ||||
|  | ||||
| @ -170,7 +170,16 @@ function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort | ||||
|   let other_signs         = gitgutter#utility#getbufvar(a:bufnr, 'other_signs') | ||||
|   let old_gitgutter_signs = gitgutter#utility#getbufvar(a:bufnr, 'gitgutter_signs') | ||||
|  | ||||
|   for line in a:modified_lines | ||||
|   " Handle special case where the first line is the site of two hunks: | ||||
|   " lines deleted above at the start of the file, and lines deleted | ||||
|   " immediately below. | ||||
|   if a:modified_lines[0:1] == [[1, 'removed_first_line'], [1, 'removed']] | ||||
|     let modified_lines = [[1, 'removed_above_and_below']] + a:modified_lines[2:] | ||||
|   else | ||||
|     let modified_lines = a:modified_lines | ||||
|   endif | ||||
|  | ||||
|   for line in modified_lines | ||||
|     let line_number = line[0]  " <number> | ||||
|     if index(other_signs, line_number) == -1  " don't clobber others' signs | ||||
|       let name = s:highlight_name_for_change(line[1]) | ||||
| @ -213,6 +222,8 @@ function! s:highlight_name_for_change(text) abort | ||||
|     return 'GitGutterLineModified' | ||||
|   elseif a:text ==# 'modified_removed' | ||||
|     return 'GitGutterLineModifiedRemoved' | ||||
|   elseif a:text ==# 'removed_above_and_below' | ||||
|     return 'GitGutterLineRemovedAboveAndBelow' | ||||
|   endif | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| @ -7,11 +7,12 @@ function! gitgutter#utility#supports_overscore_sign() | ||||
| endfunction | ||||
|  | ||||
| function! gitgutter#utility#setbufvar(buffer, varname, val) | ||||
|   let dict = get(getbufvar(a:buffer, ''), 'gitgutter', {}) | ||||
|   let buffer = +a:buffer | ||||
|   let dict = get(getbufvar(buffer, '', {}), 'gitgutter', {}) | ||||
|   let needs_setting = empty(dict) | ||||
|   let dict[a:varname] = a:val | ||||
|   if needs_setting | ||||
|     call setbufvar(+a:buffer, 'gitgutter', dict) | ||||
|     call setbufvar(buffer, 'gitgutter', dict) | ||||
|   endif | ||||
| endfunction | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Amir Salihefendic
					Amir Salihefendic