Add :Changes command

Close #1478
Close #1479
This commit is contained in:
Junegunn Choi
2023-09-14 22:45:00 +09:00
parent 587f55bf50
commit 937f430ce3
4 changed files with 63 additions and 4 deletions

View File

@@ -71,6 +71,7 @@ Commands
| `:BLines [QUERY]` | Lines in the current buffer |
| `:Tags [QUERY]` | Tags in the project (`ctags -R`) |
| `:BTags [QUERY]` | Tags in the current buffer |
| `:Changes` | Changelist across all open buffers |
| `:Marks` | Marks |
| `:Jumps` | Jumps |
| `:Windows` | Windows |

View File

@@ -1164,6 +1164,62 @@ function! fzf#vim#commands(...)
\ ' --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2,3,2..3 -d'.s:nbs}, a:000)
endfunction
" ------------------------------------------------------------------
" Changes
" ------------------------------------------------------------------
function! s:format_change(bufnr, offset, item)
return printf("%3d %s %4d %3d %s", a:bufnr, s:yellow(printf('%6s', a:offset)), a:item.lnum, a:item.col, getbufline(a:bufnr, a:item.lnum)[0])
endfunction
function! s:changes_sink(lines)
if len(a:lines) < 2
return
endif
call s:action_for(a:lines[0])
let [b, o, l, c] = split(a:lines[1])[0:3]
if o == '-'
execute 'buffer' b
call cursor(l, c)
elseif o[0] == '+'
execute 'normal!' o[1:].'g,'
else
execute 'normal!' o.'g;'
endif
endfunction
function! s:format_change_offset(current, index, cursor)
if !a:current
return '-'
endif
let offset = a:index - a:cursor + 1
if offset < 0
return '+'.-offset
endif
return offset
endfunction
function! fzf#vim#changes(...)
let all_changes = ["buf offset line col text"]
let cursor = 0
for bufnr in fzf#vim#_buflisted_sorted()
let [changes, position_or_length] = getchangelist(bufnr)
let current = bufnr() == bufnr
if current
let cursor = len(changes) - position_or_length
endif
let all_changes += map(reverse(changes), { idx, val -> s:format_change(bufnr, s:format_change_offset(current, idx, cursor), val) })
endfor
return s:fzf('changes', {
\ 'source': all_changes,
\ 'sink*': s:function('s:changes_sink'),
\ 'options': printf('+m -x --ansi --tiebreak=index --header-lines=1 --cycle --scroll-off 999 --sync --bind start:pos:%d --prompt "Changes> "', cursor)}, a:000)
endfunction
" ------------------------------------------------------------------
" Marks
" ------------------------------------------------------------------

View File

@@ -1,4 +1,4 @@
fzf-vim.txt fzf-vim Last change: September 6 2023
fzf-vim.txt fzf-vim Last change: September 14 2023
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
==============================================================================
@@ -103,9 +103,9 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
COMMANDS *fzf-vim-commands*
==============================================================================
*:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags* *:Marks*
*:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits* *:Commands* *:Maps*
*:Helptags* *:Filetypes*
*:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags*
*:Changes* *:Marks* *:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits*
*:Commands* *:Maps* *:Helptags* *:Filetypes*
-----------------------+--------------------------------------------------------------------------------------
Command | List ~
@@ -122,6 +122,7 @@ COMMANDS *fzf-vim-commands*
`:BLines[QUERY]` | Lines in the current buffer
`:Tags[QUERY]` | Tags in the project ( `ctags-R` )
`:BTags[QUERY]` | Tags in the current buffer
`:Changes` | Changelist across all open buffers
`:Marks` | Marks
`:Jumps` | Jumps
`:Windows` | Windows

View File

@@ -68,6 +68,7 @@ call s:defs([
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
\'command! -bar -bang Jumps call fzf#vim#jumps(<bang>0)',
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
\'command! -bar -bang Changes call fzf#vim#changes(<bang>0)',
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
\'command! -bar -bang Windows call fzf#vim#windows(fzf#vim#with_preview({ "placeholder": "{2}" }), <bang>0)',
\'command! -bar -bang -nargs=* -range=% -complete=file Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',