diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-12-01 20:35:58 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-12-01 20:35:58 +0100 |
commit | 97ce419201421f65f4764549ed80307a7ef9c7a6 (patch) | |
tree | 0ba380c7872e3fed3b109a4af087b7c3b4417e73 | |
parent | 76bb7196f5102c9929959d710e8ed97a19affa4d (diff) | |
download | vim-git-97ce419201421f65f4764549ed80307a7ef9c7a6.tar.gz |
patch 8.0.1361: some users don't want to diff with hidden buffersv8.0.1361
Problem: Some users don't want to diff with hidden buffers.
Solution: Add the "hiddenoff" item to 'diffopt'. (Alisue, closes #2394)
-rw-r--r-- | runtime/doc/options.txt | 3 | ||||
-rw-r--r-- | src/buffer.c | 5 | ||||
-rw-r--r-- | src/diff.c | 15 | ||||
-rw-r--r-- | src/proto/diff.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_diffmode.vim | 23 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 49 insertions, 0 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 5df5f30a3..08bc78dcf 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2634,6 +2634,9 @@ A jump table for the options with a short description can be found at |Q_op|. vertical Start diff mode with vertical splits (unless explicitly specified otherwise). + hiddenoff Do not use diff mode for a buffer when it + becomes hidden. + foldcolumn:{n} Set the 'foldcolumn' option to {n} when starting diff mode. Without this 2 is used. diff --git a/src/buffer.c b/src/buffer.c index dad910388..ed5773e88 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -593,6 +593,11 @@ aucmd_abort: if (buf->b_nwindows > 0) --buf->b_nwindows; +#ifdef FEAT_DIFF + if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) + diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */ +#endif + /* Return when a window is displaying the buffer or when it's not * unloaded. */ if (buf->b_nwindows > 0 || !unload_buf) diff --git a/src/diff.c b/src/diff.c index 11952c743..2f5b38c7b 100644 --- a/src/diff.c +++ b/src/diff.c @@ -23,6 +23,7 @@ static int diff_busy = FALSE; /* ex_diffgetput() is busy */ #define DIFF_IWHITE 4 /* ignore change in white space */ #define DIFF_HORIZONTAL 8 /* horizontal splits */ #define DIFF_VERTICAL 16 /* vertical splits */ +#define DIFF_HIDDEN_OFF 32 /* diffoff when hidden */ static int diff_flags = DIFF_FILLER; #define LBUFLEN 50 /* length of line in diff file */ @@ -1924,6 +1925,11 @@ diffopt_changed(void) p += 11; diff_foldcolumn_new = getdigits(&p); } + else if (STRNCMP(p, "hiddenoff", 9) == 0) + { + p += 9; + diff_flags_new |= DIFF_HIDDEN_OFF; + } if (*p != ',' && *p != NUL) return FAIL; if (*p == ',') @@ -1962,6 +1968,15 @@ diffopt_horizontal(void) } /* + * Return TRUE if 'diffopt' contains "hiddenoff". + */ + int +diffopt_hiddenoff(void) +{ + return (diff_flags & DIFF_HIDDEN_OFF) != 0; +} + +/* * Find the difference within a changed line. * Returns TRUE if the line was added, no other buffer has it. */ diff --git a/src/proto/diff.pro b/src/proto/diff.pro index 718640152..f1afeecec 100644 --- a/src/proto/diff.pro +++ b/src/proto/diff.pro @@ -16,6 +16,7 @@ int diff_check_fill(win_T *wp, linenr_T lnum); void diff_set_topline(win_T *fromwin, win_T *towin); int diffopt_changed(void); int diffopt_horizontal(void); +int diffopt_hiddenoff(void); int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp); int diff_infold(win_T *wp, linenr_T lnum); void nv_diffgetput(int put, long count); diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim index 3273dcbd5..d6c5c83fe 100644 --- a/src/testdir/test_diffmode.vim +++ b/src/testdir/test_diffmode.vim @@ -375,6 +375,29 @@ func Test_diffopt_vertical() %bwipe endfunc +func Test_diffopt_hiddenoff() + set diffopt=filler,foldcolumn:0,hiddenoff + e! one + call setline(1, ['Two', 'Three']) + redraw + let normattr = screenattr(1, 1) + diffthis + botright vert new two + call setline(1, ['One', 'Four']) + diffthis + redraw + call assert_notequal(normattr, screenattr(1, 1)) + set hidden + close + redraw + " should not diffing with hidden buffer two while 'hiddenoff' is enabled + call assert_equal(normattr, screenattr(1, 1)) + + bwipe! + bwipe! + set hidden& diffopt& +endfunc + func Test_diffoff_hidden() set diffopt=filler,foldcolumn:0 e! one diff --git a/src/version.c b/src/version.c index ece615ca5..604fa4198 100644 --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1361, +/**/ 1360, /**/ 1359, |