vim-signify/plugin/signify.vim

555 lines
18 KiB
VimL
Raw Normal View History

2013-04-02 09:36:42 +02: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-07-04 13:06:08 +02:00
" Version: 1.9
2013-03-07 13:12:01 +01:00
2013-03-08 07:16:33 +01:00
if exists('g:loaded_signify') || !has('signs') || &cp
2013-03-05 19:48:21 +01:00
finish
endif
let g:loaded_signify = 1
2013-04-02 16:18:01 +02:00
" Init: values {{{1
2013-04-01 18:13:17 +02:00
let s:sy = {} " the main data structure
2013-03-16 02:19:38 +01:00
let s:other_signs_line_numbers = {}
" overwrite non-signify signs by default
2013-04-03 17:15:24 +02:00
let s:sign_overwrite = get(g:, 'signify_sign_overwrite', 1)
2013-04-16 11:37:57 +02:00
let s:vcs_list = get(g:, 'signify_vcs_list', [ 'git', 'hg', 'svn', 'darcs', 'bzr', 'fossil', 'cvs', 'rcs' ])
2013-03-05 19:48:21 +01:00
let s:id_start = 0x100
let s:id_top = s:id_start
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-06-07 17:57:51 +02:00
if !empty(get(g:, 'signify_difftool'))
let s:difftool = g:signify_difftool
else
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
endif
highlight link SignifyLineAdd DiffAdd
highlight link SignifyLineChange DiffChange
highlight link SignifyLineDelete DiffDelete
highlight link SignifySignAdd DiffAdd
highlight link SignifySignChange DiffChange
highlight link SignifySignDelete DiffDelete
sign define SignifyPlaceholder text=. texthl=SignifySignChange linehl=NONE
2013-04-02 16:18:01 +02:00
" Init: autocmds {{{1
augroup signify
autocmd!
2013-03-13 19:23:47 +01:00
2013-06-06 13:08:15 +02:00
autocmd BufRead,BufEnter * let s:path = resolve(expand('<afile>:p'))
autocmd BufRead,BufWritePost * call s:start(s:path)
2013-04-03 10:31:37 +02:00
if get(g:, 'signify_update_on_bufenter')
autocmd BufEnter * nested
\ if has_key(s:sy, s:path) && s:sy[s:path].active && &modified |
\ write |
\ endif
endif
2013-03-13 19:23:47 +01:00
2013-04-03 10:31:37 +02:00
if get(g:, 'signify_cursorhold_normal')
2013-04-14 12:26:35 +02:00
autocmd CursorHold * nested
2013-04-14 11:27:17 +02:00
\ if has_key(s:sy, s:path) && s:sy[s:path].active && &modified |
2013-04-14 12:26:35 +02:00
\ write |
2013-04-14 09:58:59 +02:00
\ endif
endif
2013-03-13 19:23:47 +01:00
2013-04-03 10:31:37 +02:00
if get(g:, 'signify_cursorhold_insert')
2013-04-14 12:26:35 +02:00
autocmd CursorHoldI * nested
2013-04-14 11:27:17 +02:00
\ if has_key(s:sy, s:path) && s:sy[s:path].active && &modified |
2013-04-14 12:26:35 +02:00
\ write |
2013-04-14 09:58:59 +02:00
\ endif
2013-04-03 01:32:51 -04:00
endif
2013-03-13 19:23:47 +01:00
if !has('gui_win32')
2013-04-03 10:31:37 +02:00
autocmd FocusGained * call s:start(s:path)
2013-03-13 14:06:52 -04:00
endif
2013-04-14 11:27:17 +02:00
autocmd BufDelete *
\ let path = resolve(expand('<afile>:p')) |
\ call s:stop(path) |
\ if has_key(s:sy, path) |
\ call remove(s:sy, path) |
2013-04-14 11:27:17 +02:00
\ endif
augroup END
2013-03-05 19:48:21 +01:00
2013-04-02 16:18:01 +02:00
" Init: commands {{{1
2013-03-15 01:27:05 +01:00
com! -nargs=0 -bar SignifyToggle call s:toggle_signify()
com! -nargs=0 -bar SignifyToggleHighlight call s:line_highlighting_toggle()
2013-03-15 01:27:05 +01: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 19:48:21 +01:00
2013-04-02 16:18:01 +02: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-12 01:11:31 +02:00
" Function: s:toggle_signify {{{1
function! s:toggle_signify() abort
if empty(s:path)
echomsg 'signify: I cannot sy empty buffers!'
2013-04-12 01:11:31 +02:00
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 16:18:01 +02:00
" Function: s:start {{{1
function! s:start(path) abort
2013-04-14 11:18:43 +02:00
if !filereadable(a:path)
2013-04-01 18:11:27 +02: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))
return
2013-03-11 23:14:58 +01:00
endif
" New buffer.. add to list.
if !has_key(s:sy, a:path)
let [ diff, type ] = s:repo_detect(a:path)
if empty(diff)
return
endif
if get(g:, 'signify_disable_by_default')
let s:sy[a:path] = { 'active': 0, 'type': type, 'hunks': [], 'id_top': s:id_top }
return
endif
let s:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': s:id_top }
" Inactive buffer.. bail out.
2013-03-15 12:34:19 +01:00
elseif !s:sy[a:path].active
2013-03-11 23:14:58 +01:00
return
2013-04-14 16:23:25 +02:00
" Update signs.
2013-03-11 23:14:58 +01:00
else
let diff = s:repo_get_diff_{s:sy[a:path].type}(a:path)
if empty(diff)
2013-04-14 16:23:25 +02:00
call s:sign_remove_all(a:path)
return
endif
2013-03-11 23:14:58 +01:00
let s:sy[a:path].id_top = s:id_top
endif
2013-03-05 19:48:21 +01: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 23:14:58 +01:00
if !s:sign_overwrite
call s:sign_get_others(a:path)
endif
2013-03-05 19:48:21 +01:00
2013-04-14 16:23:25 +02:00
execute 'sign place 99999 line=1 name=SignifyPlaceholder file='. a:path
call s:sign_remove_all(a:path)
call s:repo_process_diff(a:path, diff)
2013-04-14 16:23:25 +02:00
sign unplace 99999
2013-03-05 19:48:21 +01:00
if !maparg('[c', 'n')
nnoremap <buffer><silent> ]c :<c-u>execute v:count1 .'SignifyJumpToNextHunk'<cr>
nnoremap <buffer><silent> [c :<c-u>execute v:count1 .'SignifyJumpToPrevHunk'<cr>
endif
2013-03-15 12:34:19 +01:00
let s:sy[a:path].id_top = (s:id_top - 1)
endfunction
2013-03-07 16:54:20 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:stop {{{1
function! s:stop(path) abort
2013-03-11 23:14:58 +01:00
if !has_key(s:sy, a:path)
return
endif
2013-03-11 23:14:58 +01:00
call s:sign_remove_all(a:path)
2013-03-08 16:22:58 +01:00
silent! nunmap <buffer> ]c
silent! nunmap <buffer> [c
augroup signify
autocmd! * <buffer>
augroup END
2013-04-12 01:26:20 +02:00
let s:sy[s:path].active = 0
2013-03-05 19:48:21 +01:00
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:sign_get_others {{{1
2013-03-08 17:19:34 +01:00
function! s:sign_get_others(path) abort
2013-03-11 23:14:58 +01:00
redir => signlist
2013-04-02 16:07:23 +02:00
silent! execute 'sign place file='. a:path
2013-03-11 23:14:58 +01:00
redir END
for line in filter(split(signlist, '\n'), 'v:val =~ "^\\s\\+line"')
let lnum = matchlist(line, '\v^\s+line\=(\d+)')[1]
2013-03-27 11:06:58 +01:00
let s:other_signs_line_numbers[lnum] = 1
2013-03-11 23:14:58 +01:00
endfor
2013-03-07 12:56:25 +01:00
endfunction
2013-03-06 13:10:51 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:sign_set {{{1
function! s:sign_set(signs)
let hunk = { 'ids': [], 'start': a:signs[0].lnum, 'end': a:signs[-1].lnum }
for sign in a:signs
" Preserve non-signify signs
if !s:sign_overwrite && has_key(s:other_signs_line_numbers, sign.lnum)
next
endif
2013-03-06 13:10:51 +01:00
call add(hunk.ids, s:id_top)
execute 'sign place '. s:id_top .' line='. sign.lnum .' name='. sign.type .' file='. sign.path
2013-03-06 13:10:51 +01:00
let s:id_top += 1
endfor
call add(s:sy[sign.path].hunks, hunk)
2013-03-07 12:56:25 +01:00
endfunction
2013-03-06 13:10:51 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:sign_remove_all {{{1
2013-03-08 17:19:34 +01:00
function! s:sign_remove_all(path) abort
for hunk in s:sy[a:path].hunks
for id in hunk.ids
execute 'sign unplace '. id
endfor
2013-03-11 23:14:58 +01:00
endfor
2013-03-11 23:14:58 +01:00
let s:other_signs_line_numbers = {}
let s:sy[a:path].hunks = []
2013-03-07 12:56:25 +01:00
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:repo_detect {{{1
function! s:repo_detect(path) abort
for type in s:vcs_list
let diff = s:repo_get_diff_{type}(a:path)
if !empty(diff)
return [ diff, type ]
endif
endfor
return [ '', '' ]
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_git {{{1
function! s:repo_get_diff_git(path) abort
2013-03-11 23:14:58 +01:00
if executable('git')
2013-03-27 01:25:29 +01:00
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 -- '. s:escape(a:path))
return v:shell_error ? '' : diff
2013-03-11 23:14:58 +01:00
endif
endfunction
2013-03-07 03:28:21 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_hg {{{1
function! s:repo_get_diff_hg(path) abort
2013-03-11 23:14:58 +01:00
if executable('hg')
2013-03-27 01:25:29 +01:00
let diff = system('hg diff --nodates -U0 -- '. s:escape(a:path))
return v:shell_error ? '' : diff
2013-03-11 23:14:58 +01:00
endif
endfunction
2013-03-11 23:14:58 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_svn {{{1
function! s:repo_get_diff_svn(path) abort
if executable('svn')
2013-03-27 01:25:29 +01:00
let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 -- '. s:escape(a:path))
return v:shell_error ? '' : diff
endif
endfunction
2013-03-07 03:28:21 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_bzr {{{1
function! s:repo_get_diff_bzr(path) abort
if executable('bzr')
2013-03-27 01:25:29 +01:00
let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 -- '. s:escape(a:path))
2013-04-06 20:14:11 +02:00
return ((v:shell_error == 0) || (v:shell_error == 1) || (v:shell_error == 2)) ? diff : ''
endif
endfunction
2013-03-07 03:28:21 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_darcs {{{1
function! s:repo_get_diff_darcs(path) abort
if executable('darcs')
2013-03-27 01:25:29 +01: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))
return v:shell_error ? '' : diff
2013-03-11 23:14:58 +01:00
endif
endfunction
2013-03-11 23:14:58 +01:00
2013-04-16 11:37:57 +02: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 16:18:01 +02:00
" Function: s:repo_get_diff_cvs {{{1
function! s:repo_get_diff_cvs(path) abort
if executable('cvs')
2013-03-27 01:25:29 +01:00
let diff = system('cd '. s:escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 -- '. s:escape(fnamemodify(a:path, ':t')))
return v:shell_error ? '' : diff
2013-03-11 23:14:58 +01:00
endif
2013-03-07 03:28:21 +01:00
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:repo_get_diff_rcs {{{1
2013-03-15 13:08:56 +01:00
function! s:repo_get_diff_rcs(path) abort
if executable('rcs')
2013-03-27 01:25:29 +01:00
let diff = system('rcsdiff -U0 '. s:escape(a:path) .' 2>/dev/null')
2013-03-15 13:08:56 +01:00
return v:shell_error ? '' : diff
endif
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:repo_process_diff {{{1
function! s:repo_process_diff(path, diff) abort
2013-03-11 23:14:58 +01:00
" Determine where we have to put our signs.
for line in filter(split(a:diff, '\n'), 'v:val =~ "^@@ "')
2013-04-02 16:05:52 +02:00
let tokens = matchlist(line, '^@@ -\v(\d+),?(\d*) \+(\d+),?(\d*)')
2013-03-11 23:14:58 +01:00
2013-03-27 11:06:58 +01: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 23:14:58 +01:00
let signs = []
" 2 lines added:
" @@ -5,0 +6,2 @@ this is line 5
" +this is line 5
" +this is line 5
2013-03-11 23:14:58 +01:00
if (old_count == 0) && (new_count >= 1)
let offset = 0
while offset < new_count
call add(signs, { 'type': 'SignifyAdd', 'lnum': new_line + offset, 'path': a:path })
2013-03-11 23:14:58 +01:00
let offset += 1
endwhile
" 2 lines removed:
" @@ -6,2 +5,0 @@ this is line 5
" -this is line 6
" -this is line 7
2013-03-11 23:14:58 +01:00
elseif (old_count >= 1) && (new_count == 0)
if new_line == 0
call add(signs, { 'type': 'SignifyDeleteFirstLine', 'lnum': 1, 'path': a:path })
else
call add(signs, { 'type': (old_count > 9) ? 'SignifyDeleteMore' : 'SignifyDelete' . old_count, 'lnum': new_line, 'path': a:path })
endif
" 2 lines changed:
" @@ -5,2 +5,2 @@ this is line 4
" -this is line 5
" -this is line 6
" +this os line 5
" +this os line 6
elseif old_count == new_count
2013-03-11 23:14:58 +01:00
let offset = 0
while offset < new_count
call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path })
2013-03-11 23:14:58 +01:00
let offset += 1
endwhile
else
" 2 lines changed; 2 lines deleted:
" @@ -5,4 +5,2 @@ this is line 4
" -this is line 5
" -this is line 6
" -this is line 7
" -this is line 8
" +this os line 5
" +this os line 6
if old_count > new_count
2013-03-11 23:14:58 +01:00
let offset = 0
while offset < (new_count - 1)
call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path })
2013-03-11 23:14:58 +01:00
let offset += 1
endwhile
call add(signs, { 'type': 'SignifyChangeDelete', 'lnum': new_line + offset, 'path': a:path })
" lines changed and added:
" @@ -5 +5,3 @@ this is line 4
" -this is line 5
" +this os line 5
" +this is line 42
" +this is line 666
2013-03-11 23:14:58 +01:00
else
let offset = 0
while offset < old_count
call add(signs, { 'type': 'SignifyChange', 'lnum': new_line + offset, 'path': a:path })
2013-03-11 23:14:58 +01:00
let offset += 1
endwhile
while offset < new_count
call add(signs, { 'type': 'SignifyAdd', 'lnum': new_line + offset, 'path': a:path })
2013-03-11 23:14:58 +01:00
let offset += 1
endwhile
endif
endif
call s:sign_set(signs)
2013-03-11 23:14:58 +01:00
endfor
2013-03-05 19:48:21 +01:00
endfunction
2013-03-06 01:22:51 +01:00
2013-03-07 12:56:25 +01:00
" Function: s:line_highlighting_enable {{{1
function! s:line_highlighting_enable() abort
execute 'sign define SignifyAdd text='. s:sign_add ' texthl=SignifySignAdd linehl=SignifyLineAdd'
execute 'sign define SignifyChange text='. s:sign_change ' texthl=SignifySignChange linehl=SignifyLineChange'
execute 'sign define SignifyChangeDelete text='. s:sign_change_delete .' texthl=SignifySignChange linehl=SignifyLineChange'
execute 'sign define SignifyDelete1 text='. s:sign_delete .'1 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete2 text='. s:sign_delete .'2 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete3 text='. s:sign_delete .'3 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete4 text='. s:sign_delete .'4 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete5 text='. s:sign_delete .'5 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete6 text='. s:sign_delete .'6 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete7 text='. s:sign_delete .'7 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete8 text='. s:sign_delete .'8 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDelete9 text='. s:sign_delete .'9 texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDeleteMore text='. s:sign_delete .'# texthl=SignifySignDelete linehl=SignifyLineDelete'
execute 'sign define SignifyDeleteFirstLine text='. s:sign_delete_first_line ' texthl=SignifySignDelete linehl=SignifyLineDelete'
let s:line_highlight = 1
endfunction
" Function: s:line_highlighting_disable {{{1
function! s:line_highlighting_disable() abort
execute 'sign define SignifyAdd text='. s:sign_add ' texthl=SignifySignAdd linehl=none'
execute 'sign define SignifyChange text='. s:sign_change ' texthl=SignifySignChange linehl=none'
execute 'sign define SignifyChangeDelete text='. s:sign_change_delete .' texthl=SignifySignChange linehl=none'
execute 'sign define SignifyDelete1 text='. s:sign_delete .'1 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete2 text='. s:sign_delete .'2 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete3 text='. s:sign_delete .'3 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete4 text='. s:sign_delete .'4 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete5 text='. s:sign_delete .'5 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete6 text='. s:sign_delete .'6 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete7 text='. s:sign_delete .'7 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete8 text='. s:sign_delete .'8 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDelete9 text='. s:sign_delete .'9 texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDeleteMore text='. s:sign_delete .'# texthl=SignifySignDelete linehl=none'
execute 'sign define SignifyDeleteFirstLine text='. s:sign_delete_first_line ' texthl=SignifySignDelete linehl=none'
let s:line_highlight = 0
endfunction
" Function: s:line_highlighting_toggle {{{1
function! s:line_highlighting_toggle() abort
if !has_key(s:sy, s:path)
echomsg 'signify: I cannot detect any changes!'
return
endif
2013-03-11 23:14:58 +01:00
if s:line_highlight
call s:line_highlighting_disable()
2013-03-11 23:14:58 +01:00
else
call s:line_highlighting_enable()
2013-03-11 23:14:58 +01:00
endif
call s:start(s:path)
2013-03-05 19:48:21 +01:00
endfunction
2013-04-02 16:32:10 +02:00
" Function: s:jump_to_next_hunk {{{1
function! s:jump_to_next_hunk(count)
if !has_key(s:sy, s:path)
echomsg 'signify: I cannot detect any changes!'
2013-04-02 16:32:10 +02:00
return
endif
let lnum = line('.')
let hunks = filter(copy(s:sy[s:path].hunks), 'v:val.start > lnum')
let hunk = get(hunks, a:count - 1, {})
2013-04-02 16:32:10 +02:00
if !empty(hunk)
execute 'sign jump '. hunk.ids[0] .' file='. s:path
2013-04-02 16:32:10 +02:00
endif
endfunction
2013-04-02 16:18:01 +02:00
" Function: s:jump_to_prev_hunk {{{1
2013-03-13 16:34:55 +01:00
function! s:jump_to_prev_hunk(count)
if !has_key(s:sy, s:path)
echomsg 'signify: I cannot detect any changes!'
2013-03-11 23:14:58 +01:00
return
endif
let lnum = line('.')
let hunks = filter(copy(s:sy[s:path].hunks), 'v:val.start < lnum')
let hunk = get(hunks, 0 - a:count, {})
2013-03-13 16:34:55 +01:00
if !empty(hunk)
execute 'sign jump '. hunk.ids[0] .' file='. s:path
2013-03-11 23:14:58 +01:00
endif
2013-03-05 19:48:21 +01:00
endfunction
2013-03-07 00:15:06 +01:00
2013-04-02 16:18:01 +02:00
" Function: s:escape {{{1
2013-03-27 01:25:29 +01:00
function s:escape(path) abort
if exists('+shellslash')
2013-03-27 01:25:29 +01: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
" Function: SignifyDebugListActiveBuffers {{{1
2013-03-07 12:56:25 +01:00
function! SignifyDebugListActiveBuffers() abort
2013-04-02 15:35:52 +02:00
if empty(s:sy)
echomsg 'No active buffers!'
2013-03-11 23:14:58 +01:00
return
endif
2013-04-02 15:35:52 +02:00
for [path, stats] in items(s:sy)
echomsg "\n". path ."\n". repeat('=', strlen(path))
2013-04-02 15:35:52 +02:00
for stat in sort(keys(stats))
echomsg printf("%20s = %s\n", stat, string(stats[stat]))
2013-04-02 15:35:52 +02:00
endfor
2013-03-11 23:14:58 +01:00
endfor
2013-03-07 00:15:06 +01:00
endfunction
2013-03-11 23:14:58 +01:00
2013-04-07 14:58:39 +02:00
" vim: et sw=2 sts=2