369 Commits

Author SHA1 Message Date
Andy Stewart
0c3e7219b4 Extract operations on hunk preview window. 2019-08-27 11:52:50 +01:00
Andy Stewart
77fb3fd81e Enable :w in preview window to stage the hunk. 2019-08-21 10:27:23 +01:00
Andy Stewart
cbaa22e38c Use sign functions, groups, and priority, where available.
On Vims that support it, signs are placed in the "gitgutter" group with
a priority set by g:gitgutter_sign_priority.

Closes #544.
Closes #576.
Closes #627.
2019-08-16 16:21:06 +01:00
Andy Stewart
afe94ede1b Do not use a dummy sign to keep the sign column open.
This removes the g:gitgutter_sign_column_always option.

Vim 7.4.2201 introduced the |signcolumn| option to configure when the
signcolumn is visible, building in behaviour which the plugin provided
manually.

Although it would be good to maintain this feature for older Vims, the
complexity added by the code outweighs the benefit of backward
compatibility.
2019-08-16 12:06:28 +01:00
Andy Stewart
f6f425e4cf Do not use a dummy sign to prevent sign column flicker.
In fe2b4ec869 (from 2013) the plugin
started using a dummy sign to prevent the sign column briefly
disappearing then reappearing when updating signs.

Since then Vim has vastly improved its handling of signs and the sign
column no longer flickers like this.
2019-08-16 11:55:01 +01:00
Andy Stewart
53996f5cd1 Use simpler syntax for zero-width positive lookbehind. 2019-08-15 11:58:14 +01:00
Andy Stewart
b036fcf527 Stage part of any hunk.
See #279.
2019-08-13 15:57:22 +01:00
Andy Stewart
a5ee9f2f11 Rename variables for clarity. 2019-08-13 15:47:34 +01:00
Andy Stewart
c9fd335246 Add comments. 2019-08-13 15:45:51 +01:00
Andy Stewart
773a5697f1 Warn user when git rejects patch. 2019-08-13 15:45:29 +01:00
Andy Stewart
50a7a9f6cb Ensure no extra blank line in hunk preview window.
Closes #640.
2019-08-13 13:06:58 +01:00
Andy Stewart
609b2170bf Merge branch 'master' of ssh://github.com/airblade/vim-gitgutter
* 'master' of ssh://github.com/airblade/vim-gitgutter:
  Fix #639: Use more careful way to enable `numhl`
2019-08-12 17:20:02 +01:00
Andy Stewart
bc1d28db46 Allow staging part of an additions-only hunk.
See #279.
2019-08-12 17:19:05 +01:00
delphinus
f2bf8376ae Fix #639: Use more careful way to enable numhl
The development versions of v0.3.2 also report `has('nvim-0.3.2')` to be
true even if they do not support the `numhl` feature. So here it catches
and ignores the possible errors.
2019-08-12 12:08:47 +01:00
Dan Aloni
9bf988bd1d Add g:gitgutter_sign_allow_clobber to control clobbering.
I.e. how gitgutter handles non-gitgutter signs.

See #565, #627.

Co-authored-by: Andy Stewart <boss@airbladesoftware.com>
2019-08-10 07:29:15 +01:00
delphinus
67b3ed65e3 Enable to toggle numhl 2019-08-08 16:40:35 +01:00
delphinus
78876150ae Add logic for sign with numhl 2019-08-08 16:40:35 +01:00
homestar
8985017094 Add g:gitgutter_preview_win_location option 2019-08-08 16:31:44 +01:00
Andy Stewart
91471746fe Avoid asynchronous job while vim is starting.
An asynchronous job at startup evidently triggers a Vim (not NeoVim)
rendering bug in some terminals and/or with certain colorschemes.

Terminals reported to be affected: libvte-based ones such as
gnome-terminal, xfce4-terminal, lxterminal, kitty.

Terminals reported to be unaffected: xterm, urxvt.

Closes #619.
2019-07-01 11:24:45 +01:00
Andy Stewart
5989eb882e Do not overwrite registers when undoing hunks.
Fixes #629.
2019-06-14 16:56:28 +01:00
Andy Stewart
dc3c0dcd2a Ensure git calls always use configured args for git.
See #628.
2019-06-14 12:52:13 +01:00
Jonny Bylsma
25f3c56335 Make conditional style consistent with codebase 2019-06-04 11:42:20 +01:00
Jonny Bylsma
8696c880df In get_hl(), discard returned synIDattr values of -1 2019-06-04 11:42:20 +01:00
Daniel Hahler
a4e8d3f188 gitgutter#utility#getbufvar: handle not existing buffer 2019-06-03 11:58:08 +01:00
Daniel Hahler
d7777b325a gitgutter#utility#getbufvar: handle not existing buffer
`getbufvar(a:buffer, '')` returns '' then, resulting in an error.
2019-06-03 11:55:54 +01:00
Daniel Hahler
9f21e3dbba Simplify getting highlight fg/bg 2019-06-03 11:32:09 +01:00
Andy Stewart
a7650790ea Work around older Vims not accepting arguments for function().
Fixes #618.
2019-05-31 07:17:36 +01:00
Andy Stewart
222b1a2fde Extract setting of path. 2019-05-29 14:37:16 +01:00
Andy Stewart
064a3d6b10 Move #init_buffer() into #process_buffer(). 2019-05-29 14:36:53 +01:00
Daniel Hahler
50932df59a Simplify async callbacks for setting repo path. 2019-05-29 13:06:05 +01:00
Daniel Hahler
8a4b9ccf52 Fix calls to repeat#set: remove trailing "<CR>" 2019-03-08 13:51:05 +00:00
Daniel Hahler
7201afe8d1 s:on_stderr_nvim: do not call err handler for [''] 2019-03-08 13:47:54 +00:00
Andy Stewart
fd834e48ee Combine Diff* foreground colours with SignColumn's background.
For default sign colours.

It seems the Diff* highlight groups are generally designed for line
highlighting so they have background colours which differ from the main
background colour.  While desirable for line highlights, this isn't what
we want for the signs.
2019-02-04 14:45:58 +00:00
Andy Stewart
afa4f2ddf0 Use the Diff* highlight groups by default.
This change makes the plugin default to using the highlight groups
defined by the colorscheme instead of hardcoding its own foreground
colours.

If you liked the previous colours you can restore them by adding these
lines to your vimrc:

highlight GitGutterAdd    guifg=#009900 guibg=<X> ctermfg=2 ctermb=<Y>
highlight GitGutterChange guifg=#bbbb00 guibg=<X> ctermfg=3 ctermb=<Y>
highlight GitGutterDelete guifg=#ff2222 guibg=<X> ctermfg=1 ctermb=<Y>

– where you should replace <X> and <Y> are the background colour of your
SignColumn in the gui and the terminal respectively.

For example, with the solarized colorscheme and a dark background,
guibg=#073642 and ctermbg=0.

Closes #545, #560.
2019-01-25 17:27:08 +00:00
Andy Stewart
bea21f4162 Extract variable for clarity. 2019-01-15 13:36:05 +00:00
Andy Stewart
8f6c4cb88c Minor refactor. 2019-01-15 11:40:04 +00:00
Andy Stewart
bf2a9ff4e8 Save and restore foldlevel. 2019-01-15 11:39:17 +00:00
Andy Stewart
714d468344 Enable unfolding 3 lines of context around each hunk. 2019-01-15 11:33:48 +00:00
Andy Stewart
ac787afa02 Add GitGutterFold command.
Closes #286, #571.
2019-01-14 11:48:24 +00:00
Andy Stewart
2dce8e032b Add commands to enable/disable/toggle GitGutter per buffer. 2019-01-08 12:47:10 +00:00
Andy Stewart
1d422b9f98 Revert to non-binary writefile() for writing buffer.
The previous commit switched use of writefile() to binary mode so that
we could prevent a newline being added to a completely empty buffer.
Evidently, however, binary mode has side effects (see #567) so this
commit returns to non-binary mode - with a simpler fix for completely
empty files.

Unfortunately this implementation does not work for noeol files - see
the failing test - because writefile() does not take account of
'nofixeol' (unlike :write).  This is suboptimal but acceptable because
noeol files are not be encountered often.

See #567.
2018-12-15 14:55:14 +00:00
Andy Stewart
5c636b128e Fix handling of buffer consisting only of a newline.
See #510.
2018-12-13 10:50:02 +00:00
Daniel Hahler
9a23a2f207 diff: fix handling of empty file
An empty, unchanged file was considered to be changed (a new line
added).
This patch fixes s:write_buffer to use binary mode with `writefile` to
not append a newline always, and does so manually for non-empty buffers,
according to &endofline, &binary and &fixendofline.

This is taken out of Neomake, and tested there in
https://github.com/neomake/neomake/blob/091d148b/tests/utils.vader#L713-L759.
2018-12-13 10:35:06 +00:00
Andy Stewart
c2651aefbd Do not pass a default value to getbufvar().
That was introduced in Vim 7.3.831 but there are a few Vims older than
that still around.

See:
af1e674155 (commitcomment-31431773)
2018-11-26 16:46:51 +00:00
Andy Stewart
208b439585 Vim: remove unreliable way of preventing close callback for unsuccessful job.
Until this commit the err callback closed the channel to prevent the close
callback from being invoked, because the close callback invoked the out
handler (which we don't want when the job was unsuccessful).

This mostly worked but if closing the channel took too long, which it
seemed it could when dealing with large files, the close callback could
be called in the meantime.

This commit removes the unreliable code.  The parent commit ensured that
the close callback only calls the out handler when the job succeeded, so
we no longer need to try to prevent the close callback from being
called.
2018-11-17 17:22:53 +00:00
Andy Stewart
da91d44889 Vim: only invoke async out handler when job succeeded.
This makes the plugin use Vim the same was as Neovim in terms of
invoking callback handlers.
2018-11-17 17:13:13 +00:00
Andy Stewart
32d53f134a Avoid race condition processing the same buffer twice, quickly.
The diffing part of the plugin diffs two files which are written afresh
each time.  When the same buffer was processed twice in quick
succession, the second process to write a file could write it before the
first process had finished reading it.  This manifested as the "from"
file being read as empty, causing diff to report that all the lines in
the file had been added.

This commit adds a counter to disambiguate successive temporary files.
2018-11-17 11:29:41 +00:00
Andy Stewart
947737c76f Handle non-ASCII paths.
This prevents git-ls-files from escaping "unusual" characters in
pathnames.  When this happened, gitgutter would feed the escaped name
back to git-show but git-show would not recognise it.

This commit makes git-ls-files use the -z option to output pathnames
verbatim.  These pathnames also become null terminated so we have to
ensure we remove the null terminator too.

Closes #562.
2018-11-17 11:24:36 +00:00
Andy Stewart
0597380f6b Prompt user to choose hunk when overlapping.
See #556.
2018-10-18 15:39:55 +01:00
Andy Stewart
4bd95abe6a Improve comment. 2018-10-18 15:39:47 +01:00