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.
When you look at previous versions of a file, e.g. with Fugitive's
:0Gclog, gitgutter will set the diff base to the current version's
parent so that diff markers appear as expected.
Thannks to @rcreasi for the idea and initial implementation.
matchaddpos() has better backward compatibility than text properties. I
only used text properties inside Vim popups because I did not think
there was a way to use matchaddpos(), but then I found a way.
For example consider:
-The cat in the hat.
+The ox in the box.
Before this change the highlights would be:
-The cat in the hat.
^^^^^^^^^^^^^^
+The ox in the box.
^^^^^^^^^^^^^
After this change the highlights are:
-The cat in the hat.
^^^ ^^^
+The ox in the box.
^^ ^^^
Another example; before:
-The quick brown fox jumped
+The (quick) brown (fox) jumped
^^^^^^^^^^^^^^^^^^^
And after:
-The quick brown fox jumped
+The (quick) brown (fox) jumped
^ ^ ^ ^