Skip to content

Commit 97ce419

Browse files
committed
patch 8.0.1361: some users don't want to diff with hidden buffers
Problem: Some users don't want to diff with hidden buffers. Solution: Add the "hiddenoff" item to 'diffopt'. (Alisue, closes #2394)
1 parent 76bb719 commit 97ce419

6 files changed

Lines changed: 49 additions & 0 deletions

File tree

runtime/doc/options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,9 @@ A jump table for the options with a short description can be found at |Q_op|.
26342634
vertical Start diff mode with vertical splits (unless
26352635
explicitly specified otherwise).
26362636

2637+
hiddenoff Do not use diff mode for a buffer when it
2638+
becomes hidden.
2639+
26372640
foldcolumn:{n} Set the 'foldcolumn' option to {n} when
26382641
starting diff mode. Without this 2 is used.
26392642

src/buffer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@ close_buffer(
593593
if (buf->b_nwindows > 0)
594594
--buf->b_nwindows;
595595

596+
#ifdef FEAT_DIFF
597+
if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0)
598+
diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */
599+
#endif
600+
596601
/* Return when a window is displaying the buffer or when it's not
597602
* unloaded. */
598603
if (buf->b_nwindows > 0 || !unload_buf)

src/diff.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static int diff_busy = FALSE; /* ex_diffgetput() is busy */
2323
#define DIFF_IWHITE 4 /* ignore change in white space */
2424
#define DIFF_HORIZONTAL 8 /* horizontal splits */
2525
#define DIFF_VERTICAL 16 /* vertical splits */
26+
#define DIFF_HIDDEN_OFF 32 /* diffoff when hidden */
2627
static int diff_flags = DIFF_FILLER;
2728

2829
#define LBUFLEN 50 /* length of line in diff file */
@@ -1924,6 +1925,11 @@ diffopt_changed(void)
19241925
p += 11;
19251926
diff_foldcolumn_new = getdigits(&p);
19261927
}
1928+
else if (STRNCMP(p, "hiddenoff", 9) == 0)
1929+
{
1930+
p += 9;
1931+
diff_flags_new |= DIFF_HIDDEN_OFF;
1932+
}
19271933
if (*p != ',' && *p != NUL)
19281934
return FAIL;
19291935
if (*p == ',')
@@ -1961,6 +1967,15 @@ diffopt_horizontal(void)
19611967
return (diff_flags & DIFF_HORIZONTAL) != 0;
19621968
}
19631969

1970+
/*
1971+
* Return TRUE if 'diffopt' contains "hiddenoff".
1972+
*/
1973+
int
1974+
diffopt_hiddenoff(void)
1975+
{
1976+
return (diff_flags & DIFF_HIDDEN_OFF) != 0;
1977+
}
1978+
19641979
/*
19651980
* Find the difference within a changed line.
19661981
* Returns TRUE if the line was added, no other buffer has it.

src/proto/diff.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int diff_check_fill(win_T *wp, linenr_T lnum);
1616
void diff_set_topline(win_T *fromwin, win_T *towin);
1717
int diffopt_changed(void);
1818
int diffopt_horizontal(void);
19+
int diffopt_hiddenoff(void);
1920
int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp);
2021
int diff_infold(win_T *wp, linenr_T lnum);
2122
void nv_diffgetput(int put, long count);

src/testdir/test_diffmode.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,29 @@ func Test_diffopt_vertical()
375375
%bwipe
376376
endfunc
377377

378+
func Test_diffopt_hiddenoff()
379+
set diffopt=filler,foldcolumn:0,hiddenoff
380+
e! one
381+
call setline(1, ['Two', 'Three'])
382+
redraw
383+
let normattr = screenattr(1, 1)
384+
diffthis
385+
botright vert new two
386+
call setline(1, ['One', 'Four'])
387+
diffthis
388+
redraw
389+
call assert_notequal(normattr, screenattr(1, 1))
390+
set hidden
391+
close
392+
redraw
393+
" should not diffing with hidden buffer two while 'hiddenoff' is enabled
394+
call assert_equal(normattr, screenattr(1, 1))
395+
396+
bwipe!
397+
bwipe!
398+
set hidden& diffopt&
399+
endfunc
400+
378401
func Test_diffoff_hidden()
379402
set diffopt=filler,foldcolumn:0
380403
e! one

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1361,
774776
/**/
775777
1360,
776778
/**/

0 commit comments

Comments
 (0)