To: vim_dev@googlegroups.com Subject: Patch 8.1.2289 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2289 Problem: After :diffsplit closing the window does not disable diff. Solution: Add "closeoff" to 'diffopt' and add it to the default. Files: runtime/doc/options.txt, src/optiondefs.h, src/diff.c, src/proto/diff.pro, src/window.c, src/testdir/test_diffmode.vim *** ../vim-8.1.2288/runtime/doc/options.txt 2019-11-09 23:26:36.905570965 +0100 --- runtime/doc/options.txt 2019-11-10 18:42:22.580882084 +0100 *************** *** 2592,2598 **** security reasons. *'dip'* *'diffopt'* ! 'diffopt' 'dip' string (default "internal,filler") global {not available when compiled without the |+diff| feature} --- 2591,2597 ---- security reasons. *'dip'* *'diffopt'* ! 'diffopt' 'dip' string (default "internal,filler,closeoff") global {not available when compiled without the |+diff| feature} *************** *** 2651,2656 **** --- 2650,2661 ---- vertical Start diff mode with vertical splits (unless explicitly specified otherwise). + closeoff When a window is closed where 'diff' is set + and there is only one window remaining in the + same tab page with 'diff' set, execute + `:diffoff` in that window. This undoes a + `:diffsplit` command. + hiddenoff Do not use diff mode for a buffer when it becomes hidden. *************** *** 2934,2939 **** --- 2939,2947 ---- won't work by default. NOTE: This option is set to the Vi default value when 'compatible' is set and to the Vim default value when 'compatible' is reset. + NOTE: when this option is off then the |modifyOtherKeys| functionality + is disabled while in Insert mode to avoid ending Insert mode with any + key that has a modifier. *'eventignore'* *'ei'* 'eventignore' 'ei' string (default "") *** ../vim-8.1.2288/src/optiondefs.h 2019-11-09 23:26:36.901570979 +0100 --- src/optiondefs.h 2019-11-10 18:44:15.496347354 +0100 *************** *** 846,852 **** |P_NODUP, #ifdef FEAT_DIFF (char_u *)&p_dip, PV_NONE, ! {(char_u *)"internal,filler", (char_u *)NULL} #else (char_u *)NULL, PV_NONE, {(char_u *)"", (char_u *)NULL} --- 846,853 ---- |P_NODUP, #ifdef FEAT_DIFF (char_u *)&p_dip, PV_NONE, ! {(char_u *)"internal,filler,closeoff", ! (char_u *)NULL} #else (char_u *)NULL, PV_NONE, {(char_u *)"", (char_u *)NULL} *** ../vim-8.1.2288/src/diff.c 2019-11-02 22:54:37.397188845 +0100 --- src/diff.c 2019-11-10 20:53:11.395613616 +0100 *************** *** 35,42 **** #define DIFF_VERTICAL 0x080 // vertical splits #define DIFF_HIDDEN_OFF 0x100 // diffoff when hidden #define DIFF_INTERNAL 0x200 // use internal xdiff algorithm #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) ! static int diff_flags = DIFF_INTERNAL | DIFF_FILLER; static long diff_algorithm = 0; --- 35,43 ---- #define DIFF_VERTICAL 0x080 // vertical splits #define DIFF_HIDDEN_OFF 0x100 // diffoff when hidden #define DIFF_INTERNAL 0x200 // use internal xdiff algorithm + #define DIFF_CLOSE_OFF 0x400 // diffoff when closing window #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) ! static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; static long diff_algorithm = 0; *************** *** 1545,1550 **** --- 1546,1559 ---- if (eap->forceit) diff_buf_clear(); + if (!diffwin) + { + diff_need_update = FALSE; + curtab->tp_diff_invalid = FALSE; + curtab->tp_diff_update = FALSE; + diff_clear(curtab); + } + /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) do_cmdline_cmd((char_u *)"set sbo-=hor"); *************** *** 2222,2227 **** --- 2231,2241 ---- p += 9; diff_flags_new |= DIFF_HIDDEN_OFF; } + else if (STRNCMP(p, "closeoff", 8) == 0) + { + p += 8; + diff_flags_new |= DIFF_CLOSE_OFF; + } else if (STRNCMP(p, "indent-heuristic", 16) == 0) { p += 16; *************** *** 2310,2315 **** --- 2324,2338 ---- } /* + * Return TRUE if 'diffopt' contains "closeoff". + */ + int + diffopt_closeoff(void) + { + return (diff_flags & DIFF_CLOSE_OFF) != 0; + } + + /* * Find the difference within a changed line. * Returns TRUE if the line was added, no other buffer has it. */ *** ../vim-8.1.2288/src/proto/diff.pro 2019-09-05 22:33:23.268963478 +0200 --- src/proto/diff.pro 2019-11-10 19:17:46.603926110 +0100 *************** *** 19,24 **** --- 19,25 ---- int diffopt_changed(void); int diffopt_horizontal(void); int diffopt_hiddenoff(void); + int diffopt_closeoff(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); *** ../vim-8.1.2288/src/window.c 2019-10-27 20:36:21.876503832 +0100 --- src/window.c 2019-11-10 20:54:07.927404415 +0100 *************** *** 2438,2443 **** --- 2438,2446 ---- int help_window = FALSE; tabpage_T *prev_curtab = curtab; frame_T *win_frame = win->w_frame->fr_parent; + #ifdef FEAT_DIFF + int had_diffmode = win->w_p_diff; + #endif if (ERROR_IF_POPUP_WINDOW) return FAIL; *************** *** 2625,2630 **** --- 2628,2650 ---- if (help_window) restore_snapshot(SNAP_HELP_IDX, close_curwin); + #ifdef FEAT_DIFF + // If the window had 'diff' set and now there is only one window left in + // the tab page with 'diff' set, and "closeoff" is in 'diffopt', then + // execute ":diffoff!". + if (diffopt_closeoff() && had_diffmode && curtab == prev_curtab) + { + int diffcount = 0; + win_T *dwin; + + FOR_ALL_WINDOWS(dwin) + if (dwin->w_p_diff) + ++diffcount; + if (diffcount == 1) + do_cmdline_cmd((char_u *)"diffoff!"); + } + #endif + #if defined(FEAT_GUI) /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */ if (gui.in_use && !win_hasvertsplit()) *** ../vim-8.1.2288/src/testdir/test_diffmode.vim 2019-09-15 19:31:12.840226946 +0200 --- src/testdir/test_diffmode.vim 2019-11-10 20:58:50.538890534 +0100 *************** *** 964,966 **** --- 964,991 ---- call StopVimInTerminal(buf) call delete('Xtest_diff_diff') endfunc + + func CloseoffSetup() + enew + call setline(1, ['one', 'two', 'three']) + diffthis + new + call setline(1, ['one', 'tow', 'three']) + diffthis + call assert_equal(1, &diff) + only! + endfunc + + func Test_diff_closeoff() + " "closeoff" included by default: last diff win gets 'diff' reset' + call CloseoffSetup() + call assert_equal(0, &diff) + enew! + + " "closeoff" excluded: last diff win keeps 'diff' set' + set diffopt-=closeoff + call CloseoffSetup() + call assert_equal(1, &diff) + diffoff! + enew! + endfunc *** ../vim-8.1.2288/src/version.c 2019-11-10 17:51:35.665896467 +0100 --- src/version.c 2019-11-10 18:43:11.096650814 +0100 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2289, /**/ -- hundred-and-one symptoms of being an internet addict: 59. Your wife says communication is important in a marriage...so you buy another computer and install a second phone line so the two of you can chat. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///