This reverts "Use fresh temp files for every diff" [1]. At the time I
did not realise that Vim never checks the existence of its temp
directory after creating it at startup; I thought that each call to
tempname() generated a fresh file on disk. In fact tempname() simply
generates a string path.
Therefore there is no point calling tempname() for every diff. Doing so
only serves to generate more files in the temp directory than necessary.
[1] dab840b153
Setting a colorscheme often clears all existing highlight groups. When
the plugin subsequently sets up its colours, it sees that the GitGutter*
groups exist and leaves them alone - even though they have been cleared.
This change means cleared groups do get their colours set up again.
See #727.
When previewing a hunk we re-use any existing preview window. However
we need to reset it for our purposes in case it was used in an
incompatible way before.
See #713.
If GitGutter* highlight groups already exist, they were declared
deliberately (either by the colorscheme maintainer or the user). So do
not adjust them.
However if you would like to make the signs' backgrounds match the sign
column, you can do this:
let g:gitgutter_set_sign_backgrounds = 1
This was introduced in 07d7c9d4 because many colorschemes at the time
had ugly sign columns, and people kept asking how to deal with it.
These days there are many more plugins which use the sign column and
consequently more colorschemes pay attention to the SignColumn highlight
group.
Therefore it no longer makes sense for vim-gitgutter to adjust the
sign column's appearance.
To restore the previous behaviour, add this to your vimrc:
highlight! link SignColumn LineNr
See #696.
Specifically, make it match the signs' foreground colours; and clear the
backgrounds so the GitGutter{Add,Delete}IntraLine highlights' "reverse"
colours work properly.
Previously if the user or the colourscheme had already defined
GitGutter* highlight groups, the plugin would leave their backgrounds
alone. This pushed the responsibility for figuring out and specifying
the correct backgrounds onto the user or colourscheme maintainer.
With this change the plugin now sets the correct background on existing
GitGutter* highlight groups.
Also, the documentation was simplified so it is clearer how to set your
own colours for the signs.
Originally the plugin used fresh temp files for every diff. But it
wrote to those files with `:write` which made Vim's buffer numbers
increase unnecessarily (see #297) so the plugin changed to reuse the
same temp files each time (see a871d857).
However this has the problem that after Vim has been open for a while,
e.g. a few days, the operating system can clean up the temp directory
holding those temp files. The next time the plugin runs a diff, Vim
throws an error because it cannot write to the temp files because their
directory has disappeared (see #395, #433).
In the meantime the plugin changed how it writes the temp files to
use `writefile()` (see 4e911819). This removed the problem of rapidly
increasing buffer numbers.
Now the buffer number problem has gone, the plugin can revert to using
fresh temp files each time.
win_getid() was introduced in Vim 7.4.1557. The code uses it to
remember the id of the preview window. In newer Vims or Neovim this
could be a floating window but pre-7.4.1557 it can only be an ordinary
preview window. And in that case we only need the preview window's
buffer number.
This commit uses the buffer number when win_getid() isn't available.
Fixes#683.