Profiling shows that `:sign place` and `:sign unplace` are slow despite
being native vimscript functions. This commit minimises the number of
such calls by only updating signs that have changed.
This was motivated by Vim regaining focus into a buffer with unsaved
changes, and the realtime diff being replaced with an out of date disk
diff. With this commit the realtime diff will be run again.
Use `cd` instead of `popd` because POSIX sh(1) does not have `pushd` and
also because this plugin did not pair its `pushd` with a `popd` anyway.
Use file redirection because POSIX sh(1) does not have anonymous pipes.
If the plugin slows down your Vim too much, you can have it run less
often by setting `g:gitgutter_eager = 0`.
This replaces the former options `g:gitgutter_on_bufenter` and
`g:gitgutter_on_focusgained`.
This problem was revealed when using BufExplorer:
- Open vim with two files: `$ vim a.txt b.txt`
- Type `\\` to open BufExplorer.
- Press <enter> on `b.txt`.
- Vim shows `b.txt` as expected.
- Type `\\` to open BufExplorer.
- Press <enter> on `a.txt`.
- Expected: Vim shows `a.txt`.
Actual Vim shows `a.txt`, `b.txt`, `a.txt`.
I.e. the first invocation was fine but all subsequent invocations
rapidly flicked through <new file>, <old file>, <new file>.
Previously with `gitgutter_sign_column_always = 1` the sign column would
remain after calling `GitGutterDisable`. Now the sign column is always
removed when disabling gutter.
When vim-gitgutter is configured to update on `BufEnter`, which is the
default, we only need to update visible buffers on `FocusGained`.
Other buffers will be updated as and when the user enters them.
When opening Vim without editing any file, calling GitGutterDisable
would fail because `s:file` was undefined at that point. The fix breaks
what encapsulation there is, but has the virtue of working.