Skip to content

Commit

Permalink
Preserve '[ and '] marks, and &modified, during realtime diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
airblade committed Apr 1, 2015
1 parent 07d7c9d commit e098491
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions autoload/gitgutter/diff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep)
let buff_file .= '.'.extension
endif
let cmd .= 'git show '.blob_name.' > '.blob_file.' && '

" Writing the whole buffer resets the '[ and '] marks and also the
" 'modified' flag (if &cpoptions includes '+'). These are unwanted
" side-effects so we save and restore the values ourselves.
let modified = getbufvar(bufnr, "&mod")
let op_mark_start = getpos("'[")
let op_mark_end = getpos("']")

execute 'keepalt silent write' buff_file

call setbufvar(bufnr, "&mod", modified)
call setpos("'[", op_mark_start)
call setpos("']", op_mark_end)
endif

let cmd .= 'git diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '
Expand Down
2 changes: 2 additions & 0 deletions test/keepModified.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modified: 1
modified: 1
4 changes: 4 additions & 0 deletions test/keepOpMarks.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'[ mark: 0,6,1,0
'] mark: 0,6,2,0
'[ mark: 0,6,1,0
'] mark: 0,6,2,0
8 changes: 8 additions & 0 deletions test/testKeepModified.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source helper.vim
call Setup()

normal 5Go*
call Dump("modified: ".getbufvar('', '&modified'), 'keepModified')
doautocmd CursorHold
call Dump("modified: ".getbufvar('', '&modified'), 'keepModified')

10 changes: 10 additions & 0 deletions test/testKeepOpMarks.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source helper.vim
call Setup()

normal 5Go*
call Dump("'[ mark: ".join(getpos("'["), ','), 'keepOpMarks')
call Dump("'] mark: ".join(getpos("']"), ','), 'keepOpMarks')
doautocmd CursorHold
call Dump("'[ mark: ".join(getpos("'["), ','), 'keepOpMarks')
call Dump("'] mark: ".join(getpos("']"), ','), 'keepOpMarks')

0 comments on commit e098491

Please sign in to comment.