aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-09 20:35:34 +0800
committerGitHub <noreply@github.com>2022-08-09 20:35:34 +0800
commit24bf0490ea3a16c14494358fe45437e43ca8d1d1 (patch)
tree31c21d2cbc273a1a1586ab0b05ddf78c21ef40a6 /src
parent33ddca6fa0534df2605699070fdd1e5c6e4a7bcf (diff)
downloadrneovim-24bf0490ea3a16c14494358fe45437e43ca8d1d1.tar.gz
rneovim-24bf0490ea3a16c14494358fe45437e43ca8d1d1.tar.bz2
rneovim-24bf0490ea3a16c14494358fe45437e43ca8d1d1.zip
vim-patch:9.0.0176: checking character options is duplicated and incomplete (#19690)
Problem: Checking character options is duplicated and incomplete. Solution: Move checking to check_chars_options(). (closes vim/vim#10863) https://github.com/vim/vim/commit/8ca29b6a3599b82b8822b7697cad63d0244c2d59
Diffstat (limited to 'src')
-rw-r--r--src/nvim/globals.h5
-rw-r--r--src/nvim/mbyte.c22
-rw-r--r--src/nvim/option.c39
-rw-r--r--src/nvim/testdir/test_options.vim12
4 files changed, 40 insertions, 38 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 23870a572e..317423ffa0 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -1000,11 +1000,6 @@ EXTERN char e_fnametoolong[] INIT(= N_("E856: Filename too long"));
EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String"));
EXTERN char e_cannot_edit_other_buf[] INIT(= N_("E788: Not allowed to edit another buffer now"));
-EXTERN char e_conflicts_with_value_of_listchars[]
-INIT(= N_("E834: Conflicts with value of 'listchars'"));
-EXTERN char e_conflicts_with_value_of_fillchars[]
-INIT(= N_("E835: Conflicts with value of 'fillchars'"));
-
EXTERN char e_autocmd_err[] INIT(= N_("E5500: autocmd has thrown an exception: %s"));
EXTERN char e_cmdmap_err[] INIT(= N_("E5520: <Cmd> mapping must end with <CR>"));
EXTERN char e_cmdmap_repeated[]
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index e156fa58d1..8e8cf962c7 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -2844,25 +2844,9 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, FunPtr fptr)
cw_table = table;
cw_table_size = (size_t)tv_list_len(l);
- // Check that the new value does not conflict with 'fillchars' or
- // 'listchars'.
- char *error = NULL;
- if (set_chars_option(curwin, &p_fcs, false) != NULL) {
- error = e_conflicts_with_value_of_fillchars;
- } else if (set_chars_option(curwin, &p_lcs, false) != NULL) {
- error = e_conflicts_with_value_of_listchars;
- } else {
- FOR_ALL_TAB_WINDOWS(tp, wp) {
- if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) {
- error = e_conflicts_with_value_of_listchars;
- break;
- }
- if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) {
- error = e_conflicts_with_value_of_fillchars;
- break;
- }
- }
- }
+ // Check that the new value does not conflict with 'listchars' or
+ // 'fillchars'.
+ const char *const error = check_chars_options();
if (error != NULL) {
emsg(_(error));
cw_table = cw_table_save;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index d7443bc593..8eb3b64e5b 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -339,6 +339,9 @@ static char_u SHM_ALL[] = {
static char e_unclosed_expression_sequence[] = N_("E540: Unclosed expression sequence");
static char e_unbalanced_groups[] = N_("E542: unbalanced groups");
+static char e_conflicts_with_value_of_listchars[] = N_("E834: Conflicts with value of 'listchars'");
+static char e_conflicts_with_value_of_fillchars[] = N_("E835: Conflicts with value of 'fillchars'");
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "option.c.generated.h"
#endif
@@ -2578,18 +2581,7 @@ static char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, c
if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) {
errmsg = e_invarg;
} else {
- FOR_ALL_TAB_WINDOWS(tp, wp) {
- if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) {
- errmsg = _(e_conflicts_with_value_of_listchars);
- goto ambw_end;
- }
- if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) {
- errmsg = _(e_conflicts_with_value_of_fillchars);
- goto ambw_end;
- }
- }
-ambw_end:
- {} // clint prefers {} over ; as an empty statement
+ errmsg = check_chars_options();
}
} else if (varp == &p_bg) { // 'background'
if (check_opt_strings(p_bg, p_bg_values, false) == OK) {
@@ -3823,6 +3815,29 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set)
return NULL; // no error
}
+/// Check all global and local values of 'listchars' and 'fillchars'.
+/// May set different defaults in case character widths change.
+///
+/// @return an untranslated error message if any of them is invalid, NULL otherwise.
+char *check_chars_options(void)
+{
+ if (set_chars_option(curwin, &p_lcs, false) != NULL) {
+ return e_conflicts_with_value_of_listchars;
+ }
+ if (set_chars_option(curwin, &p_fcs, false) != NULL) {
+ return e_conflicts_with_value_of_fillchars;
+ }
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) {
+ return e_conflicts_with_value_of_listchars;
+ }
+ if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) {
+ return e_conflicts_with_value_of_fillchars;
+ }
+ }
+ return NULL;
+}
+
/// Check validity of options with the 'statusline' format.
/// Return an untranslated error message or NULL.
char *check_stl_option(char *s)
diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim
index b10f0f5030..6e9f2d2377 100644
--- a/src/nvim/testdir/test_options.vim
+++ b/src/nvim/testdir/test_options.vim
@@ -368,9 +368,17 @@ func Test_set_errors()
call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
call assert_fails('set foldmarker={{{,', 'E474:')
call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
- call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:')
+ setlocal listchars=trail:·
+ call assert_fails('set ambiwidth=double', 'E834:')
+ setlocal listchars=trail:-
+ setglobal listchars=trail:·
+ call assert_fails('set ambiwidth=double', 'E834:')
set listchars&
- call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:')
+ setlocal fillchars=stl:·
+ call assert_fails('set ambiwidth=double', 'E835:')
+ setlocal fillchars=stl:-
+ setglobal fillchars=stl:·
+ call assert_fails('set ambiwidth=double', 'E835:')
set fillchars&
call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
set nomodifiable