To: vim_dev@googlegroups.com Subject: Patch 8.0.1836 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1836 Problem: Buffer-local window options may not be recent if the buffer is still open in another window. Solution: Copy the options from the window instead of the outdated window options. (Bjorn Linse, closes #2336) Files: src/buffer.c, src/testdir/test_options.vim *** ../vim-8.0.1835/src/buffer.c 2018-04-24 21:58:46.732368268 +0200 --- src/buffer.c 2018-05-13 18:00:51.414901816 +0200 *************** *** 2895,2902 **** #endif wip = find_wininfo(buf, TRUE); ! if (wip != NULL && wip->wi_optset) { copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING curwin->w_fold_manual = wip->wi_fold_manual; --- 2895,2917 ---- #endif wip = find_wininfo(buf, TRUE); ! if (wip != NULL && wip->wi_win != NULL ! && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) { + /* The buffer is currently displayed in the window: use the actual + * option values instead of the saved (possibly outdated) values. */ + win_T *wp = wip->wi_win; + + copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt); + #ifdef FEAT_FOLDING + curwin->w_fold_manual = wp->w_fold_manual; + curwin->w_foldinvalid = TRUE; + cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds); + #endif + } + else if (wip != NULL && wip->wi_optset) + { + /* the buffer was displayed in the current window earlier */ copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING curwin->w_fold_manual = wip->wi_fold_manual; *** ../vim-8.0.1835/src/testdir/test_options.vim 2018-05-10 14:11:47.360021533 +0200 --- src/testdir/test_options.vim 2018-05-13 17:56:20.916793346 +0200 *************** *** 348,350 **** --- 348,402 ---- endif endfor endfunc + + func Test_copy_winopt() + set hidden + + " Test copy option from current buffer in window + split + enew + setlocal numberwidth=5 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(5,&numberwidth) + bw! + call assert_equal(4,&numberwidth) + + " Test copy value from window that used to be display the buffer + split + enew + setlocal numberwidth=6 + bnext + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(6,&numberwidth) + bw! + + " Test that if buffer is current, don't use the stale cached value + " from the last time the buffer was displayed. + split + enew + setlocal numberwidth=7 + bnext + bnext + setlocal numberwidth=8 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(8,&numberwidth) + bw! + + " Test value is not copied if window already has seen the buffer + enew + split + setlocal numberwidth=9 + bnext + setlocal numberwidth=10 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(4,&numberwidth) + bw! + endfunc *** ../vim-8.0.1835/src/version.c 2018-05-13 17:30:41.745622839 +0200 --- src/version.c 2018-05-13 17:56:04.620908229 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1836, /**/ -- BRIDGEKEEPER: What is your favorite editor? GAWAIN: Emacs ... No, Viiiiiiiiiiimmmmmmm! "Monty Python and the Holy editor wars" PYTHON (MONTY) SOFTWARE LTD /// 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 ///