2013-04-02 03:36:42 -04:00
|
|
|
" Plugin: https://github.com/mhinz/vim-signify
|
|
|
|
" Description: show a diff from a version control system via the signcolumn
|
|
|
|
" Maintainer: Marco Hinz <http://github.com/mhinz>
|
2013-04-16 05:39:21 -04:00
|
|
|
" Version: 1.7
|
2013-03-07 07:12:01 -05:00
|
|
|
|
2013-03-08 01:16:33 -05:00
|
|
|
if exists('g:loaded_signify') || !has('signs') || &cp
|
2013-03-05 13:48:21 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_signify = 1
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Init: values {{{1
|
2013-04-01 12:13:17 -04:00
|
|
|
let s:sy = {} " the main data structure
|
2013-03-15 21:19:38 -04:00
|
|
|
let s:other_signs_line_numbers = {}
|
2013-03-08 03:11:18 -05:00
|
|
|
|
|
|
|
" overwrite non-signify signs by default
|
2013-04-03 11:15:24 -04:00
|
|
|
let s:sign_overwrite = get(g:, 'signify_sign_overwrite', 1)
|
2013-04-16 05:37:57 -04:00
|
|
|
let s:vcs_list = get(g:, 'signify_vcs_list', [ 'git', 'hg', 'svn', 'darcs', 'bzr', 'fossil', 'cvs', 'rcs' ])
|
2013-03-25 11:12:31 -04:00
|
|
|
|
2013-03-05 13:48:21 -05:00
|
|
|
let s:id_start = 0x100
|
|
|
|
let s:id_top = s:id_start
|
|
|
|
|
2013-04-25 08:37:45 -04:00
|
|
|
let s:line_color_add = get(g:, 'signify_line_color_add', 'DiffAdd')
|
|
|
|
let s:line_color_delete = get(g:, 'signify_line_color_delete', 'DiffDelete')
|
|
|
|
let s:line_color_change = get(g:, 'signify_line_color_change', 'DiffChange')
|
|
|
|
let s:line_color_change_delete = get(g:, 'signify_line_color_change_delete', 'DiffChange')
|
2013-04-07 06:09:23 -04:00
|
|
|
|
|
|
|
let s:sign_add = get(g:, 'signify_sign_add', '+')
|
|
|
|
let s:sign_delete = get(g:, 'signify_sign_delete', '_')
|
|
|
|
let s:sign_delete_first_line = get(g:, 'signify_sign_delete_first_line', '‾')
|
|
|
|
let s:sign_change = get(g:, 'signify_sign_change', '!')
|
|
|
|
let s:sign_change_delete = get(g:, 'signify_sign_change_delete', '!_')
|
|
|
|
|
2013-03-26 19:39:39 -04:00
|
|
|
if has('win32')
|
|
|
|
if $VIMRUNTIME =~ ' '
|
|
|
|
let s:difftool = (&sh =~ '\<cmd') ? ('"'. $VIMRUNTIME .'\diff"') : (substitute($VIMRUNTIME, ' ', '" ', '') .'\diff"')
|
|
|
|
else
|
|
|
|
let s:difftool = $VIMRUNTIME .'\diff'
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
if !executable('diff')
|
|
|
|
echomsg 'signify: No diff tool found!'
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let s:difftool = 'diff'
|
|
|
|
endif
|
|
|
|
|
2013-04-18 08:01:38 -04:00
|
|
|
sign define SignifyPlaceholder text=. texthl=SignifyChange linehl=NONE
|
2013-03-13 09:30:42 -04:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Init: autocmds {{{1
|
2013-03-12 07:25:22 -04:00
|
|
|
augroup signify
|
|
|
|
autocmd!
|
2013-03-13 14:23:47 -04:00
|
|
|
|
2013-04-03 04:31:37 -04:00
|
|
|
autocmd BufEnter * let s:path = resolve(expand('<afile>:p'))
|
|
|
|
autocmd BufWritePost * call s:start(s:path)
|
|
|
|
autocmd VimEnter,ColorScheme * call s:colors_set()
|
|
|
|
|
|
|
|
if get(g:, 'signify_update_on_bufenter', 1)
|
|
|
|
autocmd BufEnter * call s:start(s:path)
|
2013-03-12 07:25:22 -04:00
|
|
|
endif
|
2013-03-13 14:23:47 -04:00
|
|
|
|
2013-04-03 04:31:37 -04:00
|
|
|
if get(g:, 'signify_cursorhold_normal')
|
2013-04-14 06:26:35 -04:00
|
|
|
autocmd CursorHold * nested
|
2013-04-14 05:27:17 -04:00
|
|
|
\ if has_key(s:sy, s:path) && s:sy[s:path].active && &modified |
|
2013-04-14 06:26:35 -04:00
|
|
|
\ write |
|
2013-04-14 03:58:59 -04:00
|
|
|
\ endif
|
2013-03-12 07:25:22 -04:00
|
|
|
endif
|
2013-03-13 14:23:47 -04:00
|
|
|
|
2013-04-03 04:31:37 -04:00
|
|
|
if get(g:, 'signify_cursorhold_insert')
|
2013-04-14 06:26:35 -04:00
|
|
|
autocmd CursorHoldI * nested
|
2013-04-14 05:27:17 -04:00
|
|
|
\ if has_key(s:sy, s:path) && s:sy[s:path].active && &modified |
|
2013-04-14 06:26:35 -04:00
|
|
|
\ write |
|
2013-04-14 03:58:59 -04:00
|
|
|
\ endif
|
2013-04-03 01:32:51 -04:00
|
|
|
endif
|
|
|
|
|
2013-03-13 14:23:47 -04:00
|
|
|
if !has('gui_win32')
|
2013-04-03 04:31:37 -04:00
|
|
|
autocmd FocusGained * call s:start(s:path)
|
2013-03-13 14:06:52 -04:00
|
|
|
endif
|
2013-04-14 05:27:17 -04:00
|
|
|
|
|
|
|
autocmd BufDelete *
|
2013-04-14 06:09:02 -04:00
|
|
|
\ call s:stop(s:path) |
|
|
|
|
\ if has_key(s:sy, s:path) |
|
|
|
|
\ call remove(s:sy, s:path) |
|
2013-04-14 05:27:17 -04:00
|
|
|
\ endif
|
2013-03-12 07:25:22 -04:00
|
|
|
augroup END
|
2013-03-05 13:48:21 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Init: commands {{{1
|
2013-03-14 20:27:05 -04:00
|
|
|
com! -nargs=0 -bar SignifyToggle call s:toggle_signify()
|
2013-04-04 05:14:07 -04:00
|
|
|
com! -nargs=0 -bar SignifyToggleHighlight call s:line_highlighting_toggle()
|
2013-03-14 20:27:05 -04:00
|
|
|
com! -nargs=0 -bar -count SignifyJumpToNextHunk call s:jump_to_next_hunk(<count>)
|
|
|
|
com! -nargs=0 -bar -count SignifyJumpToPrevHunk call s:jump_to_prev_hunk(<count>)
|
2013-03-05 13:48:21 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Init: mappings {{{1
|
|
|
|
if exists('g:signify_mapping_next_hunk')
|
|
|
|
execute 'nnoremap <silent> '. g:signify_mapping_next_hunk .' :<c-u>execute v:count ."SignifyJumpToNextHunk"<cr>'
|
|
|
|
else
|
|
|
|
nnoremap <silent> <leader>gj :<c-u>execute v:count .'SignifyJumpToNextHunk'<cr>
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_mapping_prev_hunk')
|
|
|
|
execute 'nnoremap <silent> '. g:signify_mapping_prev_hunk .' :<c-u>execute v:count ."SignifyJumpToPrevHunk"<cr>'
|
|
|
|
else
|
|
|
|
nnoremap <silent> <leader>gk :<c-u>execute v:count .'SignifyJumpToPrevHunk'<cr>
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_mapping_toggle_highlight')
|
|
|
|
execute 'nnoremap <silent> '. g:signify_mapping_toggle_highlight .' :SignifyToggleHighlight<cr>'
|
|
|
|
else
|
|
|
|
nnoremap <silent> <leader>gh :SignifyToggleHighlight<cr>
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_mapping_toggle')
|
|
|
|
execute 'nnoremap <silent> '. g:signify_mapping_toggle .' :SignifyToggle<cr>'
|
|
|
|
else
|
|
|
|
nnoremap <silent> <leader>gt :SignifyToggle<cr>
|
|
|
|
endif
|
|
|
|
|
2013-04-11 19:11:31 -04:00
|
|
|
" Function: s:toggle_signify {{{1
|
|
|
|
function! s:toggle_signify() abort
|
|
|
|
if empty(s:path)
|
|
|
|
echo 'signify: I cannot sy empty buffers!'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(s:sy, s:path)
|
|
|
|
if s:sy[s:path].active
|
|
|
|
call s:stop(s:path)
|
|
|
|
else
|
|
|
|
let s:sy[s:path].active = 1
|
|
|
|
call s:start(s:path)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call s:start(s:path)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:start {{{1
|
2013-03-08 03:11:18 -05:00
|
|
|
function! s:start(path) abort
|
2013-04-14 05:18:43 -04:00
|
|
|
if !filereadable(a:path)
|
2013-04-01 12:11:27 -04:00
|
|
|
\ || (exists('g:signify_skip_filetype') && has_key(g:signify_skip_filetype, &ft))
|
|
|
|
\ || (exists('g:signify_skip_filename') && has_key(g:signify_skip_filename, a:path))
|
2013-03-26 05:34:29 -04:00
|
|
|
return
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
" New buffer.. add to list.
|
|
|
|
if !has_key(s:sy, a:path)
|
2013-03-12 20:37:46 -04:00
|
|
|
let [ diff, type ] = s:repo_detect(a:path)
|
|
|
|
if empty(diff)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let s:sy[a:path] = { 'active': 1, 'type': type, 'ids': [], 'id_jump': s:id_top, 'id_top': s:id_top, 'last_jump_was_next': -1 }
|
|
|
|
" Inactive buffer.. bail out.
|
2013-03-15 07:34:19 -04:00
|
|
|
elseif !s:sy[a:path].active
|
2013-03-11 18:14:58 -04:00
|
|
|
return
|
2013-04-14 10:23:25 -04:00
|
|
|
" Update signs.
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-03-12 20:37:46 -04:00
|
|
|
let diff = s:repo_get_diff_{s:sy[a:path].type}(a:path)
|
|
|
|
if empty(diff)
|
2013-04-14 10:23:25 -04:00
|
|
|
call s:sign_remove_all(a:path)
|
2013-03-12 20:37:46 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-03-11 18:14:58 -04:00
|
|
|
let s:sy[a:path].id_top = s:id_top
|
|
|
|
let s:sy[a:path].id_jump = s:id_top
|
|
|
|
let s:sy[a:path].last_jump_was_next = -1
|
|
|
|
endif
|
2013-03-05 13:48:21 -05:00
|
|
|
|
2013-04-04 05:14:07 -04:00
|
|
|
if !exists('s:line_highlight')
|
|
|
|
if get(g:, 'signify_line_highlight')
|
|
|
|
call s:line_highlighting_enable()
|
|
|
|
else
|
|
|
|
call s:line_highlighting_disable()
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
if !s:sign_overwrite
|
|
|
|
call s:sign_get_others(a:path)
|
|
|
|
endif
|
2013-03-05 13:48:21 -05:00
|
|
|
|
2013-04-14 10:23:25 -04:00
|
|
|
execute 'sign place 99999 line=1 name=SignifyPlaceholder file='. a:path
|
|
|
|
call s:sign_remove_all(a:path)
|
2013-03-12 20:37:46 -04:00
|
|
|
call s:repo_process_diff(a:path, diff)
|
2013-04-14 10:23:25 -04:00
|
|
|
sign unplace 99999
|
2013-03-05 13:48:21 -05:00
|
|
|
|
2013-04-11 18:25:26 -04:00
|
|
|
if !maparg('[c', 'n')
|
|
|
|
nnoremap <buffer><silent> ]c :<c-u>execute v:count .'SignifyJumpToNextHunk'<cr>
|
|
|
|
nnoremap <buffer><silent> [c :<c-u>execute v:count .'SignifyJumpToPrevHunk'<cr>
|
|
|
|
endif
|
|
|
|
|
2013-03-15 07:34:19 -04:00
|
|
|
let s:sy[a:path].id_top = (s:id_top - 1)
|
2013-03-08 03:11:18 -05:00
|
|
|
endfunction
|
2013-03-07 10:54:20 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:stop {{{1
|
2013-03-08 03:11:18 -05:00
|
|
|
function! s:stop(path) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
if !has_key(s:sy, a:path)
|
|
|
|
return
|
|
|
|
endif
|
2013-03-08 03:54:42 -05:00
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
call s:sign_remove_all(a:path)
|
2013-03-08 10:22:58 -05:00
|
|
|
|
2013-04-11 18:25:26 -04:00
|
|
|
silent! nunmap <buffer> ]c
|
|
|
|
silent! nunmap <buffer> [c
|
|
|
|
|
2013-03-25 11:12:31 -04:00
|
|
|
augroup signify
|
|
|
|
autocmd! * <buffer>
|
|
|
|
augroup END
|
2013-04-11 19:26:20 -04:00
|
|
|
|
|
|
|
let s:sy[s:path].active = 0
|
2013-03-05 13:48:21 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:sign_get_others {{{1
|
2013-03-08 11:19:34 -05:00
|
|
|
function! s:sign_get_others(path) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
redir => signlist
|
2013-04-02 10:07:23 -04:00
|
|
|
silent! execute 'sign place file='. a:path
|
2013-03-11 18:14:58 -04:00
|
|
|
redir END
|
|
|
|
|
2013-04-07 08:59:33 -04:00
|
|
|
for line in filter(split(signlist, '\n'), 'v:val =~ "^\\s\\+line"')
|
|
|
|
let lnum = matchlist(line, '\v^\s+line\=(\d+)')[1]
|
2013-03-27 06:06:58 -04:00
|
|
|
let s:other_signs_line_numbers[lnum] = 1
|
2013-03-11 18:14:58 -04:00
|
|
|
endfor
|
2013-03-07 06:56:25 -05:00
|
|
|
endfunction
|
2013-03-06 07:10:51 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:sign_set {{{1
|
2013-03-08 11:19:34 -05:00
|
|
|
function! s:sign_set(lnum, type, path)
|
2013-03-11 18:14:58 -04:00
|
|
|
" Preserve non-signify signs
|
2013-03-13 08:44:37 -04:00
|
|
|
if !s:sign_overwrite && has_key(s:other_signs_line_numbers, a:lnum)
|
2013-03-11 18:14:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-03-06 07:10:51 -05:00
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
call add(s:sy[a:path].ids, s:id_top)
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'sign place '. s:id_top .' line='. a:lnum .' name='. a:type .' file='. a:path
|
2013-03-06 07:10:51 -05:00
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
let s:id_top += 1
|
2013-03-07 06:56:25 -05:00
|
|
|
endfunction
|
2013-03-06 07:10:51 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:sign_remove_all {{{1
|
2013-03-08 11:19:34 -05:00
|
|
|
function! s:sign_remove_all(path) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
for id in s:sy[a:path].ids
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'sign unplace '. id
|
2013-03-11 18:14:58 -04:00
|
|
|
endfor
|
2013-03-08 03:11:18 -05:00
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
let s:other_signs_line_numbers = {}
|
2013-03-15 07:34:19 -04:00
|
|
|
let s:sy[a:path].ids = []
|
2013-03-07 06:56:25 -05:00
|
|
|
endfunction
|
2013-03-08 03:11:18 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_detect {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_detect(path) abort
|
2013-03-25 11:12:31 -04:00
|
|
|
for type in s:vcs_list
|
2013-03-12 20:37:46 -04:00
|
|
|
let diff = s:repo_get_diff_{type}(a:path)
|
|
|
|
if !empty(diff)
|
|
|
|
return [ diff, type ]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return [ '', '' ]
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_git {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_git(path) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
if executable('git')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 -- '. s:escape(a:path))
|
2013-03-26 08:57:57 -04:00
|
|
|
return v:shell_error ? '' : diff
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-12 20:37:46 -04:00
|
|
|
endfunction
|
2013-03-06 21:28:21 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_hg {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_hg(path) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
if executable('hg')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('hg diff --nodates -U0 -- '. s:escape(a:path))
|
2013-03-12 20:37:46 -04:00
|
|
|
return v:shell_error ? '' : diff
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-12 20:37:46 -04:00
|
|
|
endfunction
|
2013-03-11 18:14:58 -04:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_svn {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_svn(path) abort
|
|
|
|
if executable('svn')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 -- '. s:escape(a:path))
|
2013-03-12 20:37:46 -04:00
|
|
|
return v:shell_error ? '' : diff
|
|
|
|
endif
|
|
|
|
endfunction
|
2013-03-06 21:28:21 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_bzr {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_bzr(path) abort
|
|
|
|
if executable('bzr')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 -- '. s:escape(a:path))
|
2013-04-06 14:14:11 -04:00
|
|
|
return ((v:shell_error == 0) || (v:shell_error == 1) || (v:shell_error == 2)) ? diff : ''
|
2013-03-12 20:37:46 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
2013-03-06 21:28:21 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_darcs {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_darcs(path) abort
|
|
|
|
if executable('darcs')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2" -- '. s:escape(a:path))
|
2013-03-26 08:57:57 -04:00
|
|
|
return v:shell_error ? '' : diff
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-12 20:37:46 -04:00
|
|
|
endfunction
|
2013-03-11 18:14:58 -04:00
|
|
|
|
2013-04-16 05:37:57 -04:00
|
|
|
" Function: s:repo_get_diff_fossil {{{1
|
|
|
|
function! s:repo_get_diff_fossil(path) abort
|
|
|
|
if executable('fossil')
|
|
|
|
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 -- '. s:escape(a:path))
|
|
|
|
return v:shell_error ? '' : diff
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_cvs {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_get_diff_cvs(path) abort
|
2013-03-25 11:12:31 -04:00
|
|
|
if executable('cvs')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 -- '. s:escape(fnamemodify(a:path, ':t')))
|
2013-03-12 20:37:46 -04:00
|
|
|
return v:shell_error ? '' : diff
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-06 21:28:21 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_get_diff_rcs {{{1
|
2013-03-15 08:08:56 -04:00
|
|
|
function! s:repo_get_diff_rcs(path) abort
|
|
|
|
if executable('rcs')
|
2013-03-26 20:25:29 -04:00
|
|
|
let diff = system('rcsdiff -U0 '. s:escape(a:path) .' 2>/dev/null')
|
2013-03-15 08:08:56 -04:00
|
|
|
return v:shell_error ? '' : diff
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:repo_process_diff {{{1
|
2013-03-12 20:37:46 -04:00
|
|
|
function! s:repo_process_diff(path, diff) abort
|
2013-03-11 18:14:58 -04:00
|
|
|
" Determine where we have to put our signs.
|
2013-04-02 14:09:05 -04:00
|
|
|
for line in filter(split(a:diff, '\n'), 'v:val =~ "^@@ "')
|
2013-04-02 10:05:52 -04:00
|
|
|
let tokens = matchlist(line, '^@@ -\v(\d+),?(\d*) \+(\d+),?(\d*)')
|
2013-03-11 18:14:58 -04:00
|
|
|
|
2013-03-27 06:06:58 -04:00
|
|
|
let [ old_line, old_count, new_line, new_count ] = [ str2nr(tokens[1]), empty(tokens[2]) ? 1 : str2nr(tokens[2]), str2nr(tokens[3]), empty(tokens[4]) ? 1 : str2nr(tokens[4]) ]
|
2013-03-11 18:14:58 -04:00
|
|
|
|
|
|
|
" A new line was added.
|
|
|
|
if (old_count == 0) && (new_count >= 1)
|
|
|
|
let offset = 0
|
|
|
|
while offset < new_count
|
|
|
|
call s:sign_set(new_line + offset, 'SignifyAdd', a:path)
|
|
|
|
let offset += 1
|
|
|
|
endwhile
|
|
|
|
" An old line was removed.
|
|
|
|
elseif (old_count >= 1) && (new_count == 0)
|
2013-03-11 19:44:51 -04:00
|
|
|
if new_line == 0
|
|
|
|
call s:sign_set(1, 'SignifyDeleteFirstLine', a:path)
|
|
|
|
else
|
|
|
|
call s:sign_set(new_line, 'SignifyDelete', a:path)
|
|
|
|
endif
|
2013-03-11 18:14:58 -04:00
|
|
|
" A line was changed.
|
|
|
|
elseif (old_count == new_count)
|
|
|
|
let offset = 0
|
|
|
|
while offset < new_count
|
|
|
|
call s:sign_set(new_line + offset, 'SignifyChange', a:path)
|
|
|
|
let offset += 1
|
|
|
|
endwhile
|
|
|
|
else
|
|
|
|
" Lines were changed && deleted.
|
|
|
|
if (old_count > new_count)
|
|
|
|
let offset = 0
|
|
|
|
while offset < new_count
|
|
|
|
call s:sign_set(new_line + offset, 'SignifyChange', a:path)
|
|
|
|
let offset += 1
|
|
|
|
endwhile
|
2013-03-11 20:09:46 -04:00
|
|
|
call s:sign_set(new_line + offset - 1, 'SignifyChangeDelete', a:path)
|
|
|
|
" (old_count < new_count): Lines were changed && added.
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
|
|
|
let offset = 0
|
|
|
|
while offset < old_count
|
|
|
|
call s:sign_set(new_line + offset, 'SignifyChange', a:path)
|
|
|
|
let offset += 1
|
|
|
|
endwhile
|
|
|
|
while offset < new_count
|
|
|
|
call s:sign_set(new_line + offset, 'SignifyAdd', a:path)
|
|
|
|
let offset += 1
|
|
|
|
endwhile
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
2013-03-05 13:48:21 -05:00
|
|
|
endfunction
|
2013-03-05 19:22:51 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:colors_set {{{1
|
2013-03-10 05:17:53 -04:00
|
|
|
function! s:colors_set() abort
|
2013-04-18 00:55:53 -04:00
|
|
|
let weight = get(g:, 'signify_sign_weight', 'bold')
|
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
if has('gui_running')
|
|
|
|
if exists('g:signify_sign_color_guibg')
|
|
|
|
let guibg = g:signify_sign_color_guibg
|
2013-04-03 11:15:24 -04:00
|
|
|
elseif get(g:, 'signify_sign_color_inherit_from_linenr')
|
2013-03-16 19:42:11 -04:00
|
|
|
let guibg = synIDattr(hlID('LineNr'), 'bg', 'gui')
|
2013-03-16 20:05:02 -04:00
|
|
|
else
|
2013-03-11 18:14:58 -04:00
|
|
|
let guibg = synIDattr(hlID('SignColumn'), 'bg', 'gui')
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_add')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyAdd '. g:signify_sign_color_group_add
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let guifg_add = get(g:, 'signify_sign_color_guifg_add', '#11ee11')
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(guibg) || guibg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyAdd gui='. weight .' guifg='. guifg_add
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyAdd gui='. weight .' guifg='. guifg_add .' guibg='. guibg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_delete')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyDelete '. g:signify_sign_color_group_delete
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let guifg_delete = get(g:, 'signify_sign_color_guifg_delete', '#ee1111')
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(guibg) || guibg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyDelete gui='. weight .' guifg='. guifg_delete
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyDelete gui='. weight .' guifg='. guifg_delete .' guibg='. guibg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_change')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyChange '. g:signify_sign_color_group_change
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let guifg_change = get(g:, 'signify_sign_color_guifg_change', '#eeee11')
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(guibg) || guibg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyChange gui='. weight .' guifg='. guifg_change
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyChange gui='. weight .' guifg='. guifg_change .' guibg='. guibg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
if exists('g:signify_sign_color_ctermbg')
|
|
|
|
let ctermbg = g:signify_sign_color_ctermbg
|
2013-04-03 11:15:24 -04:00
|
|
|
elseif get(g:, 'signify_sign_color_inherit_from_linenr')
|
2013-03-16 20:05:02 -04:00
|
|
|
let ctermbg = synIDattr(hlID('LineNr'), 'bg', 'cterm')
|
|
|
|
else
|
2013-03-11 18:14:58 -04:00
|
|
|
let ctermbg = synIDattr(hlID('SignColumn'), 'bg', 'cterm')
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_add')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyAdd '. g:signify_sign_color_group_add
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let ctermfg_add = get(g:, 'signify_sign_color_ctermfg_add', 2)
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(ctermbg) || ctermbg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyAdd cterm='. weight .' ctermfg='. ctermfg_add
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyAdd cterm='. weight .' ctermfg='. ctermfg_add .' ctermbg='. ctermbg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_delete')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyDelete '. g:signify_sign_color_group_delete
|
2013-03-10 05:17:53 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let ctermfg_delete = get(g:, 'signify_sign_color_ctermfg_delete', 1)
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(ctermbg) || ctermbg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyDelete cterm='. weight .' ctermfg='. ctermfg_delete
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyDelete cterm='. weight .' ctermfg='. ctermfg_delete .' ctermbg='. ctermbg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-07 06:56:25 -05:00
|
|
|
endif
|
2013-03-11 18:14:58 -04:00
|
|
|
|
|
|
|
if exists('g:signify_sign_color_group_change')
|
2013-03-17 20:40:03 -04:00
|
|
|
execute 'hi! link SignifyChange '. g:signify_sign_color_group_change
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-03 11:15:24 -04:00
|
|
|
let ctermfg_change = get(g:, 'signify_sign_color_ctermfg_change', 3)
|
2013-03-11 18:14:58 -04:00
|
|
|
if empty(ctermbg) || ctermbg < 0
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyChange cterm='. weight .' ctermfg='. ctermfg_change
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-18 00:55:53 -04:00
|
|
|
execute 'hi SignifyChange cterm='. weight .' ctermfg='. ctermfg_change .' ctermbg='. ctermbg
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2013-03-10 05:17:53 -04:00
|
|
|
endfunction
|
2013-03-07 06:56:25 -05:00
|
|
|
|
2013-04-04 05:14:07 -04:00
|
|
|
" Function: s:line_highlighting_enable {{{1
|
|
|
|
function! s:line_highlighting_enable() abort
|
2013-04-07 06:09:23 -04:00
|
|
|
execute 'sign define SignifyAdd text='. s:sign_add .' texthl=SignifyAdd linehl='. s:line_color_add
|
|
|
|
execute 'sign define SignifyChange text='. s:sign_change .' texthl=SignifyChange linehl='. s:line_color_change
|
2013-04-25 08:37:45 -04:00
|
|
|
execute 'sign define SignifyChangeDelete text='. s:sign_change_delete .' texthl=SignifyChange linehl='. s:line_color_change_delete
|
2013-04-07 06:09:23 -04:00
|
|
|
execute 'sign define SignifyDelete text='. s:sign_delete .' texthl=SignifyDelete linehl='. s:line_color_delete
|
|
|
|
execute 'sign define SignifyDeleteFirstLine text='. s:sign_delete_first_line .' texthl=SignifyDelete linehl='. s:line_color_delete
|
2013-04-04 05:14:07 -04:00
|
|
|
|
|
|
|
let s:line_highlight = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:line_highlighting_disable {{{1
|
|
|
|
function! s:line_highlighting_disable() abort
|
2013-04-18 08:01:38 -04:00
|
|
|
execute 'sign define SignifyAdd text='. s:sign_add .' texthl=SignifyAdd linehl=NONE'
|
|
|
|
execute 'sign define SignifyChange text='. s:sign_change .' texthl=SignifyChange linehl=NONE'
|
|
|
|
execute 'sign define SignifyChangeDelete text='. s:sign_change_delete .' texthl=SignifyChange linehl=NONE'
|
|
|
|
execute 'sign define SignifyDelete text='. s:sign_delete .' texthl=SignifyDelete linehl=NONE'
|
|
|
|
execute 'sign define SignifyDeleteFirstLine text='. s:sign_delete_first_line .' texthl=SignifyDelete linehl=NONE'
|
2013-04-04 05:14:07 -04:00
|
|
|
|
|
|
|
let s:line_highlight = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:line_highlighting_toggle {{{1
|
|
|
|
function! s:line_highlighting_toggle() abort
|
2013-03-26 18:09:13 -04:00
|
|
|
if !has_key(s:sy, s:path)
|
|
|
|
echo 'signify: I cannot detect any changes!'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-03-11 18:14:58 -04:00
|
|
|
if s:line_highlight
|
2013-04-04 05:14:07 -04:00
|
|
|
call s:line_highlighting_disable()
|
2013-03-11 18:14:58 -04:00
|
|
|
else
|
2013-04-04 05:14:07 -04:00
|
|
|
call s:line_highlighting_enable()
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-04-04 05:14:07 -04:00
|
|
|
|
2013-03-26 18:09:13 -04:00
|
|
|
call s:start(s:path)
|
2013-03-05 13:48:21 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:32:10 -04:00
|
|
|
" Function: s:jump_to_next_hunk {{{1
|
|
|
|
function! s:jump_to_next_hunk(count)
|
|
|
|
if !has_key(s:sy, s:path) || s:sy[s:path].id_jump == -1
|
|
|
|
echo 'signify: I cannot detect any changes!'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if s:sy[s:path].last_jump_was_next == 0
|
|
|
|
let s:sy[s:path].id_jump += 2
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:sy[s:path].id_jump += a:count ? (a:count - 1) : 0
|
|
|
|
|
|
|
|
if s:sy[s:path].id_jump > s:sy[s:path].id_top
|
|
|
|
let s:sy[s:path].id_jump = s:sy[s:path].ids[0]
|
|
|
|
endif
|
|
|
|
|
|
|
|
execute 'sign jump '. s:sy[s:path].id_jump .' file='. s:path
|
|
|
|
|
|
|
|
let s:sy[s:path].id_jump += 1
|
|
|
|
let s:sy[s:path].last_jump_was_next = 1
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:jump_to_prev_hunk {{{1
|
2013-03-13 11:34:55 -04:00
|
|
|
function! s:jump_to_prev_hunk(count)
|
2013-03-17 20:51:19 -04:00
|
|
|
if !has_key(s:sy, s:path) || s:sy[s:path].id_jump == -1
|
2013-03-26 18:09:13 -04:00
|
|
|
echo 'signify: I cannot detect any changes!'
|
2013-03-11 18:14:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-03-10 12:41:46 -04:00
|
|
|
|
2013-03-17 20:51:19 -04:00
|
|
|
if s:sy[s:path].last_jump_was_next == 1
|
|
|
|
let s:sy[s:path].id_jump -= 2
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-08 03:11:18 -05:00
|
|
|
|
2013-03-17 20:51:19 -04:00
|
|
|
let s:sy[s:path].id_jump -= a:count ? (a:count - 1) : 0
|
2013-03-13 11:34:55 -04:00
|
|
|
|
2013-03-17 20:51:19 -04:00
|
|
|
if s:sy[s:path].id_jump < s:sy[s:path].ids[0]
|
|
|
|
let s:sy[s:path].id_jump = s:sy[s:path].id_top
|
2013-03-11 18:14:58 -04:00
|
|
|
endif
|
2013-03-08 03:11:18 -05:00
|
|
|
|
2013-03-17 20:51:19 -04:00
|
|
|
execute 'sign jump '. s:sy[s:path].id_jump .' file='. s:path
|
2013-03-08 03:11:18 -05:00
|
|
|
|
2013-03-17 20:51:19 -04:00
|
|
|
let s:sy[s:path].id_jump -= 1
|
|
|
|
let s:sy[s:path].last_jump_was_next = 0
|
2013-03-05 13:48:21 -05:00
|
|
|
endfunction
|
2013-03-06 18:15:06 -05:00
|
|
|
|
2013-04-02 10:18:01 -04:00
|
|
|
" Function: s:escape {{{1
|
2013-03-26 20:25:29 -04:00
|
|
|
function s:escape(path) abort
|
2013-03-27 12:38:33 -04:00
|
|
|
if exists('+shellslash')
|
2013-03-26 20:25:29 -04:00
|
|
|
let old_ssl = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
endif
|
|
|
|
|
|
|
|
let path = shellescape(a:path)
|
|
|
|
|
|
|
|
if exists('old_ssl')
|
|
|
|
let &shellslash = old_ssl
|
|
|
|
endif
|
|
|
|
|
|
|
|
return path
|
|
|
|
endfunction
|
|
|
|
|
2013-04-04 05:14:07 -04:00
|
|
|
" Function: SignifyDebugListActiveBuffers {{{1
|
2013-03-07 06:56:25 -05:00
|
|
|
function! SignifyDebugListActiveBuffers() abort
|
2013-04-02 09:35:52 -04:00
|
|
|
if empty(s:sy)
|
2013-03-11 18:14:58 -04:00
|
|
|
echo 'No active buffers!'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-04-02 09:35:52 -04:00
|
|
|
for [path, stats] in items(s:sy)
|
|
|
|
echo "\n". path ."\n". repeat('=', strlen(path))
|
|
|
|
for stat in sort(keys(stats))
|
|
|
|
echo printf("%20s = %s\n", stat, string(stats[stat]))
|
|
|
|
endfor
|
2013-03-11 18:14:58 -04:00
|
|
|
endfor
|
2013-03-06 18:15:06 -05:00
|
|
|
endfunction
|
2013-03-11 18:14:58 -04:00
|
|
|
|
2013-04-07 08:58:39 -04:00
|
|
|
" vim: et sw=2 sts=2
|