Mercurial > vim
comparison src/optionstr.c @ 29395:caaf5b270018 v9.0.0040
patch 9.0.0040: use of set_chars_option() is confusing
Commit: https://github.com/vim/vim/commit/b67f0c8e495cfbfc09d6c7ff670b8162faf07b01
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 4 21:03:36 2022 +0100
patch 9.0.0040: use of set_chars_option() is confusing
Problem: Use of set_chars_option() is confusing.
Solution: Add "apply" argument to store the result or not. Merge similar
code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 04 Jul 2022 22:15:03 +0200 |
parents | 73fb9c6efc6d |
children | d61007cc39b3 |
comparison
equal
deleted
inserted
replaced
29394:aa2921440d74 | 29395:caaf5b270018 |
---|---|
864 // 'ambiwidth' | 864 // 'ambiwidth' |
865 else if (varp == &p_ambw || varp == &p_emoji) | 865 else if (varp == &p_ambw || varp == &p_emoji) |
866 { | 866 { |
867 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) | 867 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) |
868 errmsg = e_invalid_argument; | 868 errmsg = e_invalid_argument; |
869 else if (set_chars_option(curwin, &p_fcs) != NULL) | 869 else if (set_chars_option(curwin, &p_fcs, FALSE) != NULL) |
870 errmsg = e_conflicts_with_value_of_fillchars; | 870 errmsg = e_conflicts_with_value_of_fillchars; |
871 else | 871 else |
872 { | 872 { |
873 tabpage_T *tp; | 873 tabpage_T *tp; |
874 win_T *wp; | 874 win_T *wp; |
875 | 875 |
876 FOR_ALL_TAB_WINDOWS(tp, wp) | 876 FOR_ALL_TAB_WINDOWS(tp, wp) |
877 { | 877 { |
878 if (set_chars_option(wp, &wp->w_p_lcs) != NULL) | 878 if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL) |
879 { | 879 { |
880 errmsg = e_conflicts_with_value_of_listchars; | 880 errmsg = e_conflicts_with_value_of_listchars; |
881 goto ambw_end; | 881 goto ambw_end; |
882 } | 882 } |
883 } | 883 } |
1302 } | 1302 } |
1303 s = skip_to_option_part(s); | 1303 s = skip_to_option_part(s); |
1304 } | 1304 } |
1305 } | 1305 } |
1306 | 1306 |
1307 // global 'listchars' | 1307 // global 'listchars' or 'fillchars' |
1308 else if (varp == &p_lcs) | 1308 else if (varp == &p_lcs || varp == &p_fcs) |
1309 { | 1309 { |
1310 errmsg = set_chars_option(curwin, varp); | 1310 char_u **local_ptr = varp == &p_lcs |
1311 ? &curwin->w_p_lcs : &curwin->w_p_fcs; | |
1312 | |
1313 // only apply the global value to "curwin" when it does not have a | |
1314 // local value | |
1315 errmsg = set_chars_option(curwin, varp, | |
1316 **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); | |
1311 if (errmsg == NULL) | 1317 if (errmsg == NULL) |
1312 { | 1318 { |
1313 tabpage_T *tp; | 1319 tabpage_T *tp; |
1314 win_T *wp; | 1320 win_T *wp; |
1315 | 1321 |
1316 // If the current window is set to use the global 'listchars' | 1322 // If the current window is set to use the global |
1317 // value, clear the window-local value. | 1323 // 'listchars'/'fillchars' value, clear the window-local value. |
1318 if (!(opt_flags & OPT_GLOBAL)) | 1324 if (!(opt_flags & OPT_GLOBAL)) |
1319 clear_string_option(&curwin->w_p_lcs); | 1325 clear_string_option(local_ptr); |
1320 FOR_ALL_TAB_WINDOWS(tp, wp) | 1326 FOR_ALL_TAB_WINDOWS(tp, wp) |
1327 { | |
1321 // If the current window has a local value need to apply it | 1328 // If the current window has a local value need to apply it |
1322 // again, it was changed when setting the global value. | 1329 // again, it was changed when setting the global value. |
1323 // If no error was returned above, we don't expect an error | 1330 // If no error was returned above, we don't expect an error |
1324 // here, so ignore the return value. | 1331 // here, so ignore the return value. |
1325 (void)set_chars_option(wp, &wp->w_p_lcs); | 1332 local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs; |
1333 if (**local_ptr == NUL) | |
1334 (void)set_chars_option(wp, local_ptr, TRUE); | |
1335 } | |
1326 | 1336 |
1327 redraw_all_later(NOT_VALID); | 1337 redraw_all_later(NOT_VALID); |
1328 } | 1338 } |
1329 } | 1339 } |
1330 // local 'listchars' | 1340 // local 'listchars' |
1331 else if (varp == &curwin->w_p_lcs) | 1341 else if (varp == &curwin->w_p_lcs) |
1332 errmsg = set_chars_option(curwin, varp); | 1342 errmsg = set_chars_option(curwin, varp, TRUE); |
1333 | 1343 |
1334 // 'fillchars' | |
1335 else if (varp == &p_fcs) | |
1336 { | |
1337 errmsg = set_chars_option(curwin, varp); | |
1338 if (errmsg == NULL) | |
1339 { | |
1340 tabpage_T *tp; | |
1341 win_T *wp; | |
1342 | |
1343 // If the current window is set to use the global 'fillchars' | |
1344 // value clear the window-local value. | |
1345 if (!(opt_flags & OPT_GLOBAL)) | |
1346 clear_string_option(&curwin->w_p_fcs); | |
1347 FOR_ALL_TAB_WINDOWS(tp, wp) | |
1348 // If the current window has a local value need to apply it | |
1349 // again, it was changed when setting the global value. | |
1350 // If no error was returned above, we don't expect an error | |
1351 // here, so ignore the return value. | |
1352 (void)set_chars_option(wp, &wp->w_p_fcs); | |
1353 | |
1354 redraw_all_later(NOT_VALID); | |
1355 } | |
1356 } | |
1357 // local 'fillchars' | 1344 // local 'fillchars' |
1358 else if (varp == &curwin->w_p_fcs) | 1345 else if (varp == &curwin->w_p_fcs) |
1359 { | 1346 { |
1360 errmsg = set_chars_option(curwin, varp); | 1347 errmsg = set_chars_option(curwin, varp, TRUE); |
1361 } | 1348 } |
1362 | 1349 |
1363 #ifdef FEAT_CMDWIN | 1350 #ifdef FEAT_CMDWIN |
1364 // 'cedit' | 1351 // 'cedit' |
1365 else if (varp == &p_cedit) | 1352 else if (varp == &p_cedit) |