From 0986b8be4f2e36549e21014b94b3254d6c79e587 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Feb 2022 06:36:17 +0800 Subject: [PATCH] vim-patch:8.1.2073: when editing a buffer 'colorcolumn' may not work Problem: When editing a buffer 'colorcolumn' may not work. Solution: Set the buffer before copying option values. Call check_colorcolumn() after copying window options. https://github.com/vim/vim/commit/010ee9657acf1a9f799079d718998c94e50ccadc (cherry picked from commit 612696bedc8f178cb08645dfb056f01efacf5122) --- src/nvim/buffer.c | 10 +++++----- src/nvim/option.c | 4 ++-- src/nvim/testdir/test_highlight.vim | 25 +++++++++++++++++++++++++ src/nvim/window.c | 2 -- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 6a763e3234..e4d829b157 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1498,6 +1498,11 @@ void set_curbuf(buf_T *buf, int action) */ void enter_buffer(buf_T *buf) { + // Get the buffer in the current window. + curwin->w_buffer = buf; + curbuf = buf; + curbuf->b_nwindows++; + // Copy buffer and window local option values. Not for a help buffer. buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); if (!buf->b_help) { @@ -1508,11 +1513,6 @@ void enter_buffer(buf_T *buf) } foldUpdateAll(curwin); // update folds (later). - // Get the buffer in the current window. - curwin->w_buffer = buf; - curbuf = buf; - curbuf->b_nwindows++; - if (curwin->w_p_diff) { diff_buf_add(curbuf); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 4a2a772c8c..afd4e5f12f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1944,10 +1944,9 @@ static void didset_options(void) (void)did_set_spell_option(true); // set cedit_key (void)check_cedit(); - briopt_check(curwin); // initialize the table for 'breakat'. fill_breakat_flags(); - fill_culopt_flags(NULL, curwin); + didset_window_options(curwin); } // More side effects of setting options. @@ -6007,6 +6006,7 @@ void win_copy_options(win_T *wp_from, win_T *wp_to) { copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); + didset_window_options(wp_to); } /// Copy the options from one winopt_T to another. diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index c38bfa5677..5bea282685 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -597,6 +597,31 @@ func Test_cursorline_with_visualmode() call delete('Xtest_cursorline_with_visualmode') endfunc +func Test_colorcolumn() + CheckScreendump + + " check that setting 'colorcolumn' when entering a buffer works + let lines =<< trim END + split + edit X + call setline(1, ["1111111111","22222222222","3333333333"]) + set nomodified + set colorcolumn=3,9 + set number cursorline cursorlineopt=number + wincmd w + buf X + END + call writefile(lines, 'Xtest_colorcolumn') + let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10}) + call term_sendkeys(buf, ":\") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_colorcolumn_1', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_colorcolumn') +endfunc + func Test_colorcolumn_bri() CheckScreendump diff --git a/src/nvim/window.c b/src/nvim/window.c index 3e6e42dec2..4a7a70c2cf 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1482,8 +1482,6 @@ static void win_init(win_T *newp, win_T *oldp, int flags) copyFoldingState(oldp, newp); win_init_some(newp, oldp); - - didset_window_options(newp); } /*