diff --git a/autoload/sy/util.vim b/autoload/sy/util.vim index c866a14..402112f 100644 --- a/autoload/sy/util.vim +++ b/autoload/sy/util.vim @@ -48,3 +48,30 @@ function! sy#util#refresh_windows() abort windo if exists('b:sy') | call sy#start() | endif execute winnr .'wincmd w' endfunction + +" Function: #hunk_text_object {{{1 +function! sy#util#hunk_text_object(emptylines) abort + if !exists('b:sy') + return + endif + + let lnum = line('.') + let hunks = filter(copy(b:sy.hunks), 'v:val.start <= lnum && v:val.end >= lnum') + + if empty(hunks) + return + endif + + execute hunks[0].start + normal! V + + if a:emptylines + let lnum = hunks[0].end + while getline(lnum+1) =~ '^$' + let lnum += 1 + endwhile + execute lnum + else + execute hunks[0].end + endif +endfunction diff --git a/doc/signify.txt b/doc/signify.txt index 4b6cd71..2bc49a0 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -33,9 +33,8 @@ TOC *signify-contents* OPTIONS ........................ |signify-options| COMMANDS ....................... |signify-commands| MAPPINGS ....................... |signify-mappings| - FUNCTIONS ...................... |signify-functions| - OBJECTS ........................ |signify-objects| COLORS ......................... |signify-colors| + EXAMPLE ........................ |signify-example| ============================================================================== INTRO *signify-intro* @@ -90,10 +89,6 @@ All available options:~ |g:signify_vcs_list| |g:signify_disable_by_default| - |g:signify_mapping_next_hunk| - |g:signify_mapping_prev_hunk| - |g:signify_mapping_toggle_highlight| - |g:signify_mapping_toggle| |g:signify_skip_filetype| |g:signify_skip_filename| |g:signify_update_on_bufenter| @@ -152,40 +147,8 @@ VCS will be tested for. > let g:signify_disable_by_default = 0 < -Don't run Sy by default. You can toggle it anytime via :SignifyToggle. - ------------------------------------------------------------------------------- - *g:signify_mapping_next_hunk* - *g:signify_mapping_prev_hunk* -> - let g:signify_mapping_next_hunk = 'gj' - let g:signify_mapping_prev_hunk = 'gk' -< -Mapping for jumping to the start of the next or previous hunk. - -Alternatively, you can also map it yourself: -> - nmap gj (signify-next-hunk) - nmap gk (signify-prev-hunk) -< -There is no difference between both variants. - -NOTE: Analog to Vim's diff mode, you can also use |]c| and |[c| for jumping -between hunks. - ------------------------------------------------------------------------------- - *g:signify_mapping_toggle_highlight* -> - let g:signify_mapping_toggle_highlight = 'gh' -< -Mapping for toggling line highlighting for lines containing changes. - ------------------------------------------------------------------------------- - *g:signify_mapping_toggle* -> - let g:signify_mapping_toggle = 'gt' -< -Mapping for toggling the plugin for the current buffer only. +This loads Sy, but it won't look for changes. You can toggle it anytime via +:SignifyToggle. ------------------------------------------------------------------------------ *g:signify_skip_filetype* @@ -294,55 +257,61 @@ Default: Does not exist. ============================================================================== COMMAND *signify-commands* -MAPPINGS *signify-mappings* + *signify-:SignifyToggle* > :SignifyToggle < Toggle the plugin for the current buffer only. -Default mapping: gt ------------------------------------------------------------------------------ + *signify-:SignifyToggleHighlight* > :SignifyToggleHighlight < Toggle line highlighting for lines containing changes. -Default mapping: gh - -============================================================================== -FUNCTIONS *signify-functions* - -Signify exposes some functions which you can use to customize its behavior. ------------------------------------------------------------------------------ - *signify-#refresh_windows()* - -This function updates signs for all windows. For example, to update signs when -Vim loses focus, you use: + *signify-:SignifyRefresh* > - autocmd FocusLost * call sy#util#refresh_windows() + :SignifyRefresh < +Refresh signs in all windows. + +------------------------------------------------------------------------------ + *signify-:SignifyDebug* +> + :SignifyDebug +< +Outputs debug info for all managed buffers. + ============================================================================== -OBJECTS *signify-objects* +MAPPINGS *signify-mappings* -Sy also provides text objects that operate on the current hunk: +There are no default mappings, except for ]c / [c, but there are additional +plug mappings available that you can put into your vimrc. + +------------------------------------------------------------------------------ +Hunk jumping:~ > - ic -> -Operate on all the lines of the current hunk. -> - ac + nmap gj (signify-next-hunk) + nmap gk (signify-prev-hunk) < -Does the same as ic and also removes all trailing empty lines. +NOTE: Analog to Vim's diff mode, you can also use |]c| and |[c| for +jumping between hunks. -NOTE: Don't be surprised that this also works with "deleted lines". - -Map hunk text objects like this: +------------------------------------------------------------------------------ +Hunk text object:~ > omap ic (signify-motion-inner-pending) xmap ic (signify-motion-inner-visual) omap ac (signify-motion-outer-pending) xmap ac (signify-motion-outer-visual) < +"ic" operates on all lines of the current hunk. "ac" does the same, but also +removes all trailing empty lines. + +NOTE: Don't be surprised that this also works with "deleted lines". + ============================================================================== COLORS *signify-colors* @@ -384,5 +353,31 @@ For Unix people there is a small script, showcolors.bash, in the repo that shows all 256 colors available to the terminal. That makes picking the right numbers much easier. +============================================================================== +EXAMPLE *signify-example* + +An example configuration for Sy: +> + let g:signify_vcs_list = [ 'git', 'hg' ] + let g:signify_cursorhold_insert = 1 + let g:signify_cursorhold_normal = 1 + let g:signify_update_on_bufenter = 0 + let g:signify_update_on_focusgained = 1 + + nnoremap gt SignifyToggle + nnoremap gh SignifyToggleHighlight + nnoremap gr SignifyRefresh + nnoremap gd SignifyDebug + + " hunk jumping + nmap gj (signify-next-hunk) + nmap gk (signify-prev-hunk) + + " hunk text object + omap ic (signify-motion-inner-pending) + xmap ic (signify-motion-inner-visual) + omap ac (signify-motion-outer-pending) + xmap ac (signify-motion-outer-visual) +< ============================================================================== vim: tw=78 diff --git a/plugin/signify.vim b/plugin/signify.vim index 0e244b9..f3c66f8 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -7,10 +7,12 @@ if exists('g:loaded_signify') || !has('signs') || &compatible endif " Init: values {{{1 + let g:loaded_signify = 1 let g:signify_locked = 0 " Init: autocmds {{{1 + augroup signify autocmd! @@ -31,33 +33,26 @@ augroup signify endif if get(g:, 'signify_update_on_focusgained') && !has('gui_win32') - autocmd FocusGained * call sy#util#refresh_windows() + autocmd FocusGained * call SignifyRefresh endif augroup END " Init: commands {{{1 -com! -nargs=0 -bar SignifyToggle call sy#toggle() -com! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggle() -com! -nargs=0 -bar SyDebug call sy#debug#list_active_buffers() + +command! -nargs=0 -bar SignifyDebug call sy#debug#list_active_buffers() +command! -nargs=0 -bar SignifyRefresh call sy#util#refresh_windows() +command! -nargs=0 -bar SignifyToggle call sy#toggle() +command! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggle() " Init: mappings {{{1 -nnoremap (signify-toggle) :call sy#toggle() -nnoremap (signify-toggle-highlight) :call sy#highlight#line_toggle() - -if exists('g:signify_mapping_toggle') - execute 'nmap '. g:signify_mapping_toggle .' (signify-toggle)' -elseif !hasmapto('(signify-toggle)') && empty(maparg('gt', 'n')) - nmap gt (signify-toggle) -endif -if exists('g:signify_mapping_toggle_highlight') - execute 'nmap '. g:signify_mapping_toggle_highlight .' (signify-toggle-highlight)' -elseif !hasmapto('(signify-toggle-highlight)') && empty(maparg('gh', 'n')) - nmap gh (signify-toggle-highlight) -endif " hunk jumping -nnoremap (signify-next-hunk) &diff ? ']c' : ":\call sy#jump#next_hunk(v:count1)\" -nnoremap (signify-prev-hunk) &diff ? '[c' : ":\call sy#jump#prev_hunk(v:count1)\" +nnoremap (signify-next-hunk) &diff + \ ? ']c' + \ : ":\call sy#jump#next_hunk(v:count1)\" +nnoremap (signify-prev-hunk) &diff + \ ? '[c' + \ : ":\call sy#jump#prev_hunk(v:count1)\" if empty(maparg(']c', 'n')) nmap ]c (signify-next-hunk) @@ -65,66 +60,17 @@ endif if empty(maparg('[c', 'n')) nmap [c (signify-prev-hunk) endif -if exists('g:signify_mapping_next_hunk') - execute 'nmap '. g:signify_mapping_next_hunk .' (signify-next-hunk)' -elseif !hasmapto('(signify-next-hunk)') && empty(maparg('gj', 'n')) - nmap gj (signify-next-hunk) -endif -if exists('g:signify_mapping_prev_hunk') - execute 'nmap '. g:signify_mapping_prev_hunk .' (signify-prev-hunk)' -elseif !hasmapto('(signify-prev-hunk)') && empty(maparg('gk', 'n')) - nmap gk (signify-prev-hunk) -endif " hunk text object -onoremap (signify-motion-inner-pending) :call hunk_text_object(0) -xnoremap (signify-motion-inner-visual) :call hunk_text_object(0) -onoremap (signify-motion-outer-pending) :call hunk_text_object(1) -xnoremap (signify-motion-outer-visual) :call hunk_text_object(1) - -if !hasmapto('(signify-motion-inner-pending)') && empty(maparg('ic', 'o')) - omap ic (signify-motion-inner-pending) -endif -if !hasmapto('(signify-motion-inner-visual)') && empty(maparg('ic', 'v')) - xmap ic (signify-motion-inner-visual) -endif -if !hasmapto('(signify-motion-outer-pending)') && empty(maparg('ac', 'o')) - omap ac (signify-motion-outer-pending) -endif -if !hasmapto('(signify-motion-outer-visual)') && empty(maparg('ac', 'v')) - xmap ac (signify-motion-outer-visual) -endif +onoremap (signify-motion-inner-pending) :call sy#util#hunk_text_object(0) +xnoremap (signify-motion-inner-visual) :call sy#util#hunk_text_object(0) +onoremap (signify-motion-outer-pending) :call sy#util#hunk_text_object(1) +xnoremap (signify-motion-outer-visual) :call sy#util#hunk_text_object(1) " Function: save {{{1 + function! s:save() if exists('b:sy') && b:sy.active && &modified write endif endfunction - -" Function: hunk_text_object {{{1 -function! s:hunk_text_object(emptylines) abort - if !exists('b:sy') - return - endif - - let lnum = line('.') - let hunks = filter(copy(b:sy.hunks), 'v:val.start <= lnum && v:val.end >= lnum') - - if empty(hunks) - return - endif - - execute hunks[0].start - normal! V - - if a:emptylines - let lnum = hunks[0].end - while getline(lnum+1) =~ '^$' - let lnum += 1 - endwhile - execute lnum - else - execute hunks[0].end - endif -endfunction