]> granicus.if.org Git - vim/commitdiff
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work v8.1.2073
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Sep 2019 18:37:36 +0000 (20:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Sep 2019 18:37:36 +0000 (20:37 +0200)
Problem:    When editing a buffer 'colorcolumn' may not work.
Solution:   Set the buffer before copying option values. Call
            check_colorcolumn() after copying window options.

src/buffer.c
src/option.c
src/proto/indent.pro
src/proto/option.pro
src/testdir/dumps/Test_colorcolumn_1.dump [new file with mode: 0644]
src/testdir/test_highlight.vim
src/version.c

index 81f2799f494076b5942230038e23178d2750ca3c..4f754f545247a9a3798402283dc171e9dba3488c 100644 (file)
@@ -1738,22 +1738,22 @@ set_curbuf(buf_T *buf, int action)
     static void
 enter_buffer(buf_T *buf)
 {
-    /* Copy buffer and window local option values.  Not for a help buffer. */
+    // 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)
        get_winopts(buf);
 #ifdef FEAT_FOLDING
     else
-       /* Remove all folds in the window. */
+       // Remove all folds in the window.
        clearFolding(curwin);
-    foldUpdateAll(curwin);     /* update folds (later). */
+    foldUpdateAll(curwin);     // update folds (later).
 #endif
 
-    /* Get the buffer in the current window. */
-    curwin->w_buffer = buf;
-    curbuf = buf;
-    ++curbuf->b_nwindows;
-
 #ifdef FEAT_DIFF
     if (curwin->w_p_diff)
        diff_buf_add(curbuf);
@@ -2980,9 +2980,7 @@ get_winopts(buf_T *buf)
     if (p_fdls >= 0)
        curwin->w_p_fdl = p_fdls;
 #endif
-#ifdef FEAT_SYN_HL
-    check_colorcolumn(curwin);
-#endif
+    after_copy_winopt(curwin);
 }
 
 /*
index 1ffa11d121708447f7ff12d8c34a770786f3ec84..be967dc00068e23a3dcb1ec2f6ad2b18746a352f 100644 (file)
@@ -2323,19 +2323,14 @@ didset_options(void)
     (void)did_set_spell_option(TRUE);
 #endif
 #ifdef FEAT_CMDWIN
-    /* set cedit_key */
+    // set cedit_key
     (void)check_cedit();
 #endif
-#ifdef FEAT_LINEBREAK
-    briopt_check(curwin);
-#endif
 #ifdef FEAT_LINEBREAK
     /* initialize the table for 'breakat'. */
     fill_breakat_flags();
 #endif
-#ifdef FEAT_SYN_HL
-    fill_culopt_flags(NULL, curwin);
-#endif
+    after_copy_winopt(curwin);
 }
 
 /*
@@ -5528,11 +5523,21 @@ 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);
-#if defined(FEAT_LINEBREAK)
-    briopt_check(wp_to);
+    after_copy_winopt(wp_to);
+}
+
+/*
+ * After copying window options: update variables depending on options.
+ */
+    void
+after_copy_winopt(win_T *wp)
+{
+#ifdef FEAT_LINEBREAK
+    briopt_check(wp);
 #endif
 #ifdef FEAT_SYN_HL
-    fill_culopt_flags(NULL, wp_to);
+    fill_culopt_flags(NULL, wp);
+    check_colorcolumn(wp);
 #endif
 }
 
index 71028ac336970ccb4c758d2352f7839b27440b98..b9c071c958b8f475e538b05b4fcf3c99bb092962 100644 (file)
@@ -10,4 +10,17 @@ int get_lisp_indent(void);
 void do_c_expr_indent(void);
 void fixthisline(int (*get_the_indent)(void));
 void fix_indent(void);
+int tabstop_set(char_u *var, int **array);
+int tabstop_padding(colnr_T col, int ts_arg, int *vts);
+int tabstop_at(colnr_T col, int ts, int *vts);
+colnr_T tabstop_start(colnr_T col, int ts, int *vts);
+void tabstop_fromto(colnr_T start_col, colnr_T end_col, int ts_arg, int *vts, int *ntabs, int *nspcs);
+int tabstop_eq(int *ts1, int *ts2);
+int *tabstop_copy(int *oldts);
+int tabstop_count(int *ts);
+int tabstop_first(int *ts);
+long get_sw_value(buf_T *buf);
+long get_sw_value_indent(buf_T *buf);
+long get_sw_value_col(buf_T *buf, colnr_T col);
+long get_sts_value(void);
 /* vim: set ft=c : */
index d6c8558541c72c525337abfd45cfffd7c1b31a66..40312f4fc474a4abf2e1732839da13bda3eb781f 100644 (file)
@@ -28,6 +28,7 @@ void check_redraw(long_u flags);
 int findoption(char_u *arg);
 int get_option_value(char_u *name, long *numval, char_u **stringval, int opt_flags);
 int get_option_value_strict(char_u *name, long *numval, char_u **stringval, int opt_type, void *from);
+char_u *option_iter_next(void **option, int opt_type);
 long_u get_option_flags(int opt_idx);
 void set_option_flag(int opt_idx, long_u flag);
 void clear_option_flag(int opt_idx, long_u flag);
@@ -36,7 +37,6 @@ int is_global_local_option(int opt_idx);
 int is_window_local_option(int opt_idx);
 int is_hidden_option(int opt_idx);
 int is_crypt_key_option(int opt_idx);
-char_u *option_iter_next(void **option, int opt_type);
 char *set_option_value(char_u *name, long number, char_u *string, int opt_flags);
 char_u *get_term_code(char_u *tname);
 char_u *get_highlight_default(void);
@@ -54,6 +54,7 @@ char_u *get_option_var(int opt_idx);
 char_u *get_option_fullname(int opt_idx);
 char_u *get_equalprg(void);
 void win_copy_options(win_T *wp_from, win_T *wp_to);
+void after_copy_winopt(win_T *wp);
 void copy_winopt(winopt_T *from, winopt_T *to);
 void clear_winopt(winopt_T *wop);
 void buf_copy_options(buf_T *buf, int flags);
@@ -74,19 +75,6 @@ int check_opt_wim(void);
 int can_bs(int what);
 void save_file_ff(buf_T *buf);
 int file_ff_differs(buf_T *buf, int ignore_empty);
-int tabstop_set(char_u *var, int **array);
-int tabstop_padding(colnr_T col, int ts_arg, int *vts);
-int tabstop_at(colnr_T col, int ts, int *vts);
-colnr_T tabstop_start(colnr_T col, int ts, int *vts);
-void tabstop_fromto(colnr_T start_col, colnr_T end_col, int ts_arg, int *vts, int *ntabs, int *nspcs);
-int tabstop_eq(int *ts1, int *ts2);
-int *tabstop_copy(int *oldts);
-int tabstop_count(int *ts);
-int tabstop_first(int *ts);
-long get_sw_value(buf_T *buf);
-long get_sw_value_indent(buf_T *buf);
-long get_sw_value_col(buf_T *buf, colnr_T col);
-long get_sts_value(void);
 long get_scrolloff_value(void);
 long get_sidescrolloff_value(void);
 void find_mps_values(int *initc, int *findc, int *backwards, int switchit);
diff --git a/src/testdir/dumps/Test_colorcolumn_1.dump b/src/testdir/dumps/Test_colorcolumn_1.dump
new file mode 100644 (file)
index 0000000..cbaf27d
--- /dev/null
@@ -0,0 +1,10 @@
+| +8#af5f00255#ffffff0@1|1| |1+0#0000000&@1|1+0&#ffd7d7255|1+0&#ffffff0@4|1+0&#ffd7d7255|1+0&#ffffff0| @60
+| +0#af5f00255&@1|2| |2+0#0000000&@1|2+0&#ffd7d7255|2+0&#ffffff0@4|2+0&#ffd7d7255|2+0&#ffffff0@1| @59
+| +0#af5f00255&@1|3| |3+0#0000000&@1|3+0&#ffd7d7255|3+0&#ffffff0@4|3+0&#ffd7d7255|3+0&#ffffff0| @60
+|~+0#4040ff13&| @73
+|X+1#0000000&| @55|1|,|1| @11|A|l@1
+| +8#af5f00255&@1|1| >1+0#0000000&@1|1+0&#ffd7d7255|1+0&#ffffff0@4|1+0&#ffd7d7255|1+0&#ffffff0| @60
+| +0#af5f00255&@1|2| |2+0#0000000&@1|2+0&#ffd7d7255|2+0&#ffffff0@4|2+0&#ffd7d7255|2+0&#ffffff0@1| @59
+| +0#af5f00255&@1|3| |3+0#0000000&@1|3+0&#ffd7d7255|3+0&#ffffff0@4|3+0&#ffd7d7255|3+0&#ffffff0| @60
+|X+3&&| @55|1|,|1| @11|A|l@1
+|:+0&&| @73
index 7db33bf30697ca4d8ed50201f6659bc4bbab29cb..9e1af9730f9e8e52561775c5fb426ae433d89693 100644 (file)
@@ -618,6 +618,31 @@ func Test_wincolor()
   call delete('Xtest_wincolor')
 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, ":\<CR>")
+  call term_wait(buf)
+  call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('Xtest_colorcolumn')
+endfunc
+
 " This test must come before the Test_cursorline test, as it appears this
 " defines the Normal highlighting group anyway.
 func Test_1_highlight_Normalgroup_exists()
index ec9aa76635c5cbbe8d8542acde77c5238d38ab60..6f8107c4f2c7d3dc4436de8e7bf223cb88623dad 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2073,
 /**/
     2072,
 /**/