comparison src/optionstr.c @ 33430:18f4a04384f3 v9.0.1973

patch 9.0.1973: Clean up cmdline option completion code Commit: https://github.com/vim/vim/commit/6d113472601fa6f3a444a95ef7b11d4309215117 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Mon Oct 2 21:38:39 2023 +0200 patch 9.0.1973: Clean up cmdline option completion code Problem: Clean up cmdline option completion code Solution: Fix various minor problems - Fix manual array size calculations to just use `ARRAY_LENGTH()`. - Fix unintentional typo in comments due to copy-paste error. - Fix assert_equal() usages to pass the expected value to first parameter instead of 2nd one to avoid confusion. - Fix signed vs unsigned warnings - Correct misplaced comments about set_op_T and set_prefix_T and fix a typo in another comment closes: #13249 closes: #13237 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
author Christian Brabandt <cb@256bit.org>
date Mon, 02 Oct 2023 21:45:07 +0200
parents aa7cd2253130
children 929ecce18664
comparison
equal deleted inserted replaced
33429:c6871290807e 33430:18f4a04384f3
735 */ 735 */
736 static int 736 static int
737 expand_set_opt_string( 737 expand_set_opt_string(
738 optexpand_T *args, 738 optexpand_T *args,
739 char **values, 739 char **values,
740 int numValues, 740 size_t numValues,
741 int *numMatches, 741 int *numMatches,
742 char_u ***matches) 742 char_u ***matches)
743 { 743 {
744 char_u *p; 744 char_u *p;
745 regmatch_T *regmatch = args->oe_regmatch; 745 regmatch_T *regmatch = args->oe_regmatch;
861 char_u *option_val = args->oe_opt_value; 861 char_u *option_val = args->oe_opt_value;
862 char_u *cmdline_val = args->oe_set_arg; 862 char_u *cmdline_val = args->oe_set_arg;
863 int append = args->oe_append; 863 int append = args->oe_append;
864 int include_orig_val = args->oe_include_orig_val && (*option_val != NUL); 864 int include_orig_val = args->oe_include_orig_val && (*option_val != NUL);
865 865
866 int num_flags = STRLEN(flags); 866 size_t num_flags = STRLEN(flags);
867 867
868 // Assume we only have small number of flags, so just allocate max size. 868 // Assume we only have small number of flags, so just allocate max size.
869 *matches = ALLOC_MULT(char_u *, num_flags + 1); 869 *matches = ALLOC_MULT(char_u *, num_flags + 1);
870 if (*matches == NULL) 870 if (*matches == NULL)
871 return FAIL; 871 return FAIL;
938 expand_set_ambiwidth(optexpand_T *args, int *numMatches, char_u ***matches) 938 expand_set_ambiwidth(optexpand_T *args, int *numMatches, char_u ***matches)
939 { 939 {
940 return expand_set_opt_string( 940 return expand_set_opt_string(
941 args, 941 args,
942 p_ambw_values, 942 p_ambw_values,
943 sizeof(p_ambw_values) / sizeof(p_ambw_values[0]) - 1, 943 ARRAY_LENGTH(p_ambw_values) - 1,
944 numMatches, 944 numMatches,
945 matches); 945 matches);
946 } 946 }
947 947
948 /* 948 /*
985 expand_set_background(optexpand_T *args, int *numMatches, char_u ***matches) 985 expand_set_background(optexpand_T *args, int *numMatches, char_u ***matches)
986 { 986 {
987 return expand_set_opt_string( 987 return expand_set_opt_string(
988 args, 988 args,
989 p_bg_values, 989 p_bg_values,
990 sizeof(p_bg_values) / sizeof(p_bg_values[0]) - 1, 990 ARRAY_LENGTH(p_bg_values) - 1,
991 numMatches, 991 numMatches,
992 matches); 992 matches);
993 } 993 }
994 994
995 /* 995 /*
1013 expand_set_backspace(optexpand_T *args, int *numMatches, char_u ***matches) 1013 expand_set_backspace(optexpand_T *args, int *numMatches, char_u ***matches)
1014 { 1014 {
1015 return expand_set_opt_string( 1015 return expand_set_opt_string(
1016 args, 1016 args,
1017 p_bs_values, 1017 p_bs_values,
1018 sizeof(p_bs_values) / sizeof(p_bs_values[0]) - 1, 1018 ARRAY_LENGTH(p_bs_values) - 1,
1019 numMatches, 1019 numMatches,
1020 matches); 1020 matches);
1021 } 1021 }
1022 1022
1023 /* 1023 /*
1061 expand_set_backupcopy(optexpand_T *args, int *numMatches, char_u ***matches) 1061 expand_set_backupcopy(optexpand_T *args, int *numMatches, char_u ***matches)
1062 { 1062 {
1063 return expand_set_opt_string( 1063 return expand_set_opt_string(
1064 args, 1064 args,
1065 p_bkc_values, 1065 p_bkc_values,
1066 sizeof(p_bkc_values) / sizeof(p_bkc_values[0]) - 1, 1066 ARRAY_LENGTH(p_bkc_values) - 1,
1067 numMatches, 1067 numMatches,
1068 matches); 1068 matches);
1069 } 1069 }
1070 1070
1071 /* 1071 /*
1094 expand_set_belloff(optexpand_T *args, int *numMatches, char_u ***matches) 1094 expand_set_belloff(optexpand_T *args, int *numMatches, char_u ***matches)
1095 { 1095 {
1096 return expand_set_opt_string( 1096 return expand_set_opt_string(
1097 args, 1097 args,
1098 p_bo_values, 1098 p_bo_values,
1099 sizeof(p_bo_values) / sizeof(p_bo_values[0]) - 1, 1099 ARRAY_LENGTH(p_bo_values) - 1,
1100 numMatches, 1100 numMatches,
1101 matches); 1101 matches);
1102 } 1102 }
1103 1103
1104 #if defined(FEAT_LINEBREAK) || defined(PROTO) 1104 #if defined(FEAT_LINEBREAK) || defined(PROTO)
1123 expand_set_breakindentopt(optexpand_T *args, int *numMatches, char_u ***matches) 1123 expand_set_breakindentopt(optexpand_T *args, int *numMatches, char_u ***matches)
1124 { 1124 {
1125 return expand_set_opt_string( 1125 return expand_set_opt_string(
1126 args, 1126 args,
1127 p_briopt_values, 1127 p_briopt_values,
1128 sizeof(p_briopt_values) / sizeof(p_briopt_values[0]) - 1, 1128 ARRAY_LENGTH(p_briopt_values) - 1,
1129 numMatches, 1129 numMatches,
1130 matches); 1130 matches);
1131 } 1131 }
1132 #endif 1132 #endif
1133 1133
1149 expand_set_browsedir(optexpand_T *args, int *numMatches, char_u ***matches) 1149 expand_set_browsedir(optexpand_T *args, int *numMatches, char_u ***matches)
1150 { 1150 {
1151 return expand_set_opt_string( 1151 return expand_set_opt_string(
1152 args, 1152 args,
1153 p_bsdir_values, 1153 p_bsdir_values,
1154 sizeof(p_bsdir_values) / sizeof(p_bsdir_values[0]) - 1, 1154 ARRAY_LENGTH(p_bsdir_values) - 1,
1155 numMatches, 1155 numMatches,
1156 matches); 1156 matches);
1157 } 1157 }
1158 #endif 1158 #endif
1159 1159
1170 expand_set_bufhidden(optexpand_T *args, int *numMatches, char_u ***matches) 1170 expand_set_bufhidden(optexpand_T *args, int *numMatches, char_u ***matches)
1171 { 1171 {
1172 return expand_set_opt_string( 1172 return expand_set_opt_string(
1173 args, 1173 args,
1174 p_bufhidden_values, 1174 p_bufhidden_values,
1175 sizeof(p_bufhidden_values) / sizeof(p_bufhidden_values[0]) - 1, 1175 ARRAY_LENGTH(p_bufhidden_values) - 1,
1176 numMatches, 1176 numMatches,
1177 matches); 1177 matches);
1178 } 1178 }
1179 1179
1180 /* 1180 /*
1201 expand_set_buftype(optexpand_T *args, int *numMatches, char_u ***matches) 1201 expand_set_buftype(optexpand_T *args, int *numMatches, char_u ***matches)
1202 { 1202 {
1203 return expand_set_opt_string( 1203 return expand_set_opt_string(
1204 args, 1204 args,
1205 p_buftype_values, 1205 p_buftype_values,
1206 sizeof(p_buftype_values) / sizeof(p_buftype_values[0]) - 1, 1206 ARRAY_LENGTH(p_buftype_values) - 1,
1207 numMatches, 1207 numMatches,
1208 matches); 1208 matches);
1209 } 1209 }
1210 1210
1211 /* 1211 /*
1221 expand_set_casemap(optexpand_T *args, int *numMatches, char_u ***matches) 1221 expand_set_casemap(optexpand_T *args, int *numMatches, char_u ***matches)
1222 { 1222 {
1223 return expand_set_opt_string( 1223 return expand_set_opt_string(
1224 args, 1224 args,
1225 p_cmp_values, 1225 p_cmp_values,
1226 sizeof(p_cmp_values) / sizeof(p_cmp_values[0]) - 1, 1226 ARRAY_LENGTH(p_cmp_values) - 1,
1227 numMatches, 1227 numMatches,
1228 matches); 1228 matches);
1229 } 1229 }
1230 1230
1231 #if defined(FEAT_CLIPBOARD) || defined(PROTO) 1231 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
1233 expand_set_clipboard(optexpand_T *args, int *numMatches, char_u ***matches) 1233 expand_set_clipboard(optexpand_T *args, int *numMatches, char_u ***matches)
1234 { 1234 {
1235 return expand_set_opt_string( 1235 return expand_set_opt_string(
1236 args, 1236 args,
1237 p_cb_values, 1237 p_cb_values,
1238 sizeof(p_cb_values) / sizeof(p_cb_values[0]) - 1, 1238 ARRAY_LENGTH(p_cb_values) - 1,
1239 numMatches, 1239 numMatches,
1240 matches); 1240 matches);
1241 } 1241 }
1242 #endif 1242 #endif
1243 1243
1459 ".", "w", "b", "u", "k", "kspell", "s", "i", "d", "]", "t", "U", 1459 ".", "w", "b", "u", "k", "kspell", "s", "i", "d", "]", "t", "U",
1460 NULL}; 1460 NULL};
1461 return expand_set_opt_string( 1461 return expand_set_opt_string(
1462 args, 1462 args,
1463 p_cpt_values, 1463 p_cpt_values,
1464 sizeof(p_cpt_values) / sizeof(p_cpt_values[0]) - 1, 1464 ARRAY_LENGTH(p_cpt_values) - 1,
1465 numMatches, 1465 numMatches,
1466 matches); 1466 matches);
1467 } 1467 }
1468 1468
1469 /* 1469 /*
1483 expand_set_completeopt(optexpand_T *args, int *numMatches, char_u ***matches) 1483 expand_set_completeopt(optexpand_T *args, int *numMatches, char_u ***matches)
1484 { 1484 {
1485 return expand_set_opt_string( 1485 return expand_set_opt_string(
1486 args, 1486 args,
1487 p_cot_values, 1487 p_cot_values,
1488 sizeof(p_cot_values) / sizeof(p_cot_values[0]) - 1, 1488 ARRAY_LENGTH(p_cot_values) - 1,
1489 numMatches, 1489 numMatches,
1490 matches); 1490 matches);
1491 } 1491 }
1492 1492
1493 #if (defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)) || defined(PROTO) 1493 #if (defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)) || defined(PROTO)
1523 expand_set_completeslash(optexpand_T *args, int *numMatches, char_u ***matches) 1523 expand_set_completeslash(optexpand_T *args, int *numMatches, char_u ***matches)
1524 { 1524 {
1525 return expand_set_opt_string( 1525 return expand_set_opt_string(
1526 args, 1526 args,
1527 p_csl_values, 1527 p_csl_values,
1528 sizeof(p_csl_values) / sizeof(p_csl_values[0]) - 1, 1528 ARRAY_LENGTH(p_csl_values) - 1,
1529 numMatches, 1529 numMatches,
1530 matches); 1530 matches);
1531 } 1531 }
1532 #endif 1532 #endif
1533 1533
1662 expand_set_cryptmethod(optexpand_T *args, int *numMatches, char_u ***matches) 1662 expand_set_cryptmethod(optexpand_T *args, int *numMatches, char_u ***matches)
1663 { 1663 {
1664 return expand_set_opt_string( 1664 return expand_set_opt_string(
1665 args, 1665 args,
1666 p_cm_values, 1666 p_cm_values,
1667 sizeof(p_cm_values) / sizeof(p_cm_values[0]) - 1, 1667 ARRAY_LENGTH(p_cm_values) - 1,
1668 numMatches, 1668 numMatches,
1669 matches); 1669 matches);
1670 } 1670 }
1671 #endif 1671 #endif
1672 1672
1720 expand_set_cursorlineopt(optexpand_T *args, int *numMatches, char_u ***matches) 1720 expand_set_cursorlineopt(optexpand_T *args, int *numMatches, char_u ***matches)
1721 { 1721 {
1722 return expand_set_opt_string( 1722 return expand_set_opt_string(
1723 args, 1723 args,
1724 p_culopt_values, 1724 p_culopt_values,
1725 sizeof(p_culopt_values) / sizeof(p_culopt_values[0]) - 1, 1725 ARRAY_LENGTH(p_culopt_values) - 1,
1726 numMatches, 1726 numMatches,
1727 matches); 1727 matches);
1728 } 1728 }
1729 #endif 1729 #endif
1730 1730
1741 expand_set_debug(optexpand_T *args, int *numMatches, char_u ***matches) 1741 expand_set_debug(optexpand_T *args, int *numMatches, char_u ***matches)
1742 { 1742 {
1743 return expand_set_opt_string( 1743 return expand_set_opt_string(
1744 args, 1744 args,
1745 p_debug_values, 1745 p_debug_values,
1746 sizeof(p_debug_values) / sizeof(p_debug_values[0]) - 1, 1746 ARRAY_LENGTH(p_debug_values) - 1,
1747 numMatches, 1747 numMatches,
1748 matches); 1748 matches);
1749 } 1749 }
1750 1750
1751 #if defined(FEAT_DIFF) || defined(PROTO) 1751 #if defined(FEAT_DIFF) || defined(PROTO)
1767 expand_T *xp = args->oe_xp; 1767 expand_T *xp = args->oe_xp;
1768 1768
1769 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') 1769 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
1770 { 1770 {
1771 // Within "algorithm:", we have a subgroup of possible options. 1771 // Within "algorithm:", we have a subgroup of possible options.
1772 int algo_len = STRLEN("algorithm:"); 1772 int algo_len = (int)STRLEN("algorithm:");
1773 if (xp->xp_pattern - args->oe_set_arg >= algo_len && 1773 if (xp->xp_pattern - args->oe_set_arg >= algo_len &&
1774 STRNCMP(xp->xp_pattern - algo_len, "algorithm:", algo_len) == 0) 1774 STRNCMP(xp->xp_pattern - algo_len, "algorithm:", algo_len) == 0)
1775 { 1775 {
1776 return expand_set_opt_string( 1776 return expand_set_opt_string(
1777 args, 1777 args,
1778 p_dip_algorithm_values, 1778 p_dip_algorithm_values,
1779 sizeof(p_dip_algorithm_values) / sizeof(p_dip_algorithm_values[0]) - 1, 1779 ARRAY_LENGTH(p_dip_algorithm_values) - 1,
1780 numMatches, 1780 numMatches,
1781 matches); 1781 matches);
1782 } 1782 }
1783 return FAIL; 1783 return FAIL;
1784 } 1784 }
1785 1785
1786 return expand_set_opt_string( 1786 return expand_set_opt_string(
1787 args, 1787 args,
1788 p_dip_values, 1788 p_dip_values,
1789 sizeof(p_dip_values) / sizeof(p_dip_values[0]) - 1, 1789 ARRAY_LENGTH(p_dip_values) - 1,
1790 numMatches, 1790 numMatches,
1791 matches); 1791 matches);
1792 } 1792 }
1793 #endif 1793 #endif
1794 1794
1809 expand_set_display(optexpand_T *args, int *numMatches, char_u ***matches) 1809 expand_set_display(optexpand_T *args, int *numMatches, char_u ***matches)
1810 { 1810 {
1811 return expand_set_opt_string( 1811 return expand_set_opt_string(
1812 args, 1812 args,
1813 p_dy_values, 1813 p_dy_values,
1814 sizeof(p_dy_values) / sizeof(p_dy_values[0]) - 1, 1814 ARRAY_LENGTH(p_dy_values) - 1,
1815 numMatches, 1815 numMatches,
1816 matches); 1816 matches);
1817 } 1817 }
1818 1818
1819 /* 1819 /*
1829 expand_set_eadirection(optexpand_T *args, int *numMatches, char_u ***matches) 1829 expand_set_eadirection(optexpand_T *args, int *numMatches, char_u ***matches)
1830 { 1830 {
1831 return expand_set_opt_string( 1831 return expand_set_opt_string(
1832 args, 1832 args,
1833 p_ead_values, 1833 p_ead_values,
1834 sizeof(p_ead_values) / sizeof(p_ead_values[0]) - 1, 1834 ARRAY_LENGTH(p_ead_values) - 1,
1835 numMatches, 1835 numMatches,
1836 matches); 1836 matches);
1837 } 1837 }
1838 1838
1839 /* 1839 /*
2003 expand_set_fileformat(optexpand_T *args, int *numMatches, char_u ***matches) 2003 expand_set_fileformat(optexpand_T *args, int *numMatches, char_u ***matches)
2004 { 2004 {
2005 return expand_set_opt_string( 2005 return expand_set_opt_string(
2006 args, 2006 args,
2007 p_ff_values, 2007 p_ff_values,
2008 sizeof(p_ff_values) / sizeof(p_ff_values[0]) - 1, 2008 ARRAY_LENGTH(p_ff_values) - 1,
2009 numMatches, 2009 numMatches,
2010 matches); 2010 matches);
2011 } 2011 }
2012 2012
2013 /* 2013 /*
2062 expand_set_foldclose(optexpand_T *args, int *numMatches, char_u ***matches) 2062 expand_set_foldclose(optexpand_T *args, int *numMatches, char_u ***matches)
2063 { 2063 {
2064 return expand_set_opt_string( 2064 return expand_set_opt_string(
2065 args, 2065 args,
2066 p_fcl_values, 2066 p_fcl_values,
2067 sizeof(p_fcl_values) / sizeof(p_fcl_values[0]) - 1, 2067 ARRAY_LENGTH(p_fcl_values) - 1,
2068 numMatches, 2068 numMatches,
2069 matches); 2069 matches);
2070 } 2070 }
2071 #endif 2071 #endif
2072 2072
2138 expand_set_foldmethod(optexpand_T *args, int *numMatches, char_u ***matches) 2138 expand_set_foldmethod(optexpand_T *args, int *numMatches, char_u ***matches)
2139 { 2139 {
2140 return expand_set_opt_string( 2140 return expand_set_opt_string(
2141 args, 2141 args,
2142 p_fdm_values, 2142 p_fdm_values,
2143 sizeof(p_fdm_values) / sizeof(p_fdm_values[0]) - 1, 2143 ARRAY_LENGTH(p_fdm_values) - 1,
2144 numMatches, 2144 numMatches,
2145 matches); 2145 matches);
2146 } 2146 }
2147 2147
2148 /* 2148 /*
2158 expand_set_foldopen(optexpand_T *args, int *numMatches, char_u ***matches) 2158 expand_set_foldopen(optexpand_T *args, int *numMatches, char_u ***matches)
2159 { 2159 {
2160 return expand_set_opt_string( 2160 return expand_set_opt_string(
2161 args, 2161 args,
2162 p_fdo_values, 2162 p_fdo_values,
2163 sizeof(p_fdo_values) / sizeof(p_fdo_values[0]) - 1, 2163 ARRAY_LENGTH(p_fdo_values) - 1,
2164 numMatches, 2164 numMatches,
2165 matches); 2165 matches);
2166 } 2166 }
2167 #endif 2167 #endif
2168 2168
2379 expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches) 2379 expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches)
2380 { 2380 {
2381 char_u *p; 2381 char_u *p;
2382 expand_T *xp = args->oe_xp; 2382 expand_T *xp = args->oe_xp;
2383 static char_u hl_flags[HLF_COUNT] = HL_FLAGS; 2383 static char_u hl_flags[HLF_COUNT] = HL_FLAGS;
2384 int i; 2384 size_t i;
2385 int count = 0; 2385 int count = 0;
2386 2386
2387 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') 2387 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
2388 { 2388 {
2389 // Right after a ':', meaning we just return all highlight names. 2389 // Right after a ':', meaning we just return all highlight names.
2444 // to match against display mode modifiers. 2444 // to match against display mode modifiers.
2445 // Since the xp_pattern starts from the beginning, we need to include it in 2445 // Since the xp_pattern starts from the beginning, we need to include it in
2446 // the returned match. 2446 // the returned match.
2447 2447
2448 // Note: Keep this in sync with highlight_changed() 2448 // Note: Keep this in sync with highlight_changed()
2449 static char p_hl_mode_values[] = 2449 static char_u p_hl_mode_values[] =
2450 {':', 'b', 'i', '-', 'n', 'r', 's', 'u', 'c', '2', 'd', '=', 't'}; 2450 {':', 'b', 'i', '-', 'n', 'r', 's', 'u', 'c', '2', 'd', '=', 't'};
2451 int num_hl_modes = sizeof(p_hl_mode_values) / sizeof(p_hl_mode_values[0]); 2451 size_t num_hl_modes = ARRAY_LENGTH(p_hl_mode_values);
2452 2452
2453 *matches = ALLOC_MULT(char_u *, num_hl_modes); 2453 *matches = ALLOC_MULT(char_u *, num_hl_modes);
2454 if (*matches == NULL) 2454 if (*matches == NULL)
2455 return FAIL; 2455 return FAIL;
2456 2456
2457 int pattern_len = STRLEN(xp->xp_pattern); 2457 size_t pattern_len = STRLEN(xp->xp_pattern);
2458 2458
2459 for (i = 0; i < num_hl_modes; i++) 2459 for (i = 0; i < num_hl_modes; i++)
2460 { 2460 {
2461 // Don't allow duplicates as these are unique flags 2461 // Don't allow duplicates as these are unique flags
2462 if (vim_strchr(xp->xp_pattern + 1, p_hl_mode_values[i]) != NULL) 2462 if (vim_strchr(xp->xp_pattern + 1, p_hl_mode_values[i]) != NULL)
2574 expand_set_jumpoptions(optexpand_T *args, int *numMatches, char_u ***matches) 2574 expand_set_jumpoptions(optexpand_T *args, int *numMatches, char_u ***matches)
2575 { 2575 {
2576 return expand_set_opt_string( 2576 return expand_set_opt_string(
2577 args, 2577 args,
2578 p_jop_values, 2578 p_jop_values,
2579 sizeof(p_jop_values) / sizeof(p_jop_values[0]) - 1, 2579 ARRAY_LENGTH(p_jop_values) - 1,
2580 numMatches, 2580 numMatches,
2581 matches); 2581 matches);
2582 } 2582 }
2583 2583
2584 #if defined(FEAT_KEYMAP) || defined(PROTO) 2584 #if defined(FEAT_KEYMAP) || defined(PROTO)
2658 expand_set_keymodel(optexpand_T *args, int *numMatches, char_u ***matches) 2658 expand_set_keymodel(optexpand_T *args, int *numMatches, char_u ***matches)
2659 { 2659 {
2660 return expand_set_opt_string( 2660 return expand_set_opt_string(
2661 args, 2661 args,
2662 p_km_values, 2662 p_km_values,
2663 sizeof(p_km_values) / sizeof(p_km_values[0]) - 1, 2663 ARRAY_LENGTH(p_km_values) - 1,
2664 numMatches, 2664 numMatches,
2665 matches); 2665 matches);
2666 } 2666 }
2667 2667
2668 /* 2668 /*
2690 // 'keyprotocol' only has well-defined terms for completion for the 2690 // 'keyprotocol' only has well-defined terms for completion for the
2691 // protocol part after the colon. 2691 // protocol part after the colon.
2692 return expand_set_opt_string( 2692 return expand_set_opt_string(
2693 args, 2693 args,
2694 p_kpc_protocol_values, 2694 p_kpc_protocol_values,
2695 sizeof(p_kpc_protocol_values) / sizeof(p_kpc_protocol_values[0]) - 1, 2695 ARRAY_LENGTH(p_kpc_protocol_values) - 1,
2696 numMatches, 2696 numMatches,
2697 matches); 2697 matches);
2698 } 2698 }
2699 // Use expand_set_opt_string instead of returning FAIL so that we can 2699 // Use expand_set_opt_string instead of returning FAIL so that we can
2700 // include the original value if args->oe_include_orig_val is set. 2700 // include the original value if args->oe_include_orig_val is set.
2723 { 2723 {
2724 static char *(p_lop_values[]) = {"expr:0", "expr:1", NULL}; 2724 static char *(p_lop_values[]) = {"expr:0", "expr:1", NULL};
2725 return expand_set_opt_string( 2725 return expand_set_opt_string(
2726 args, 2726 args,
2727 p_lop_values, 2727 p_lop_values,
2728 sizeof(p_lop_values) / sizeof(p_lop_values[0]) - 1, 2728 ARRAY_LENGTH(p_lop_values) - 1,
2729 numMatches, 2729 numMatches,
2730 matches); 2730 matches);
2731 } 2731 }
2732 2732
2733 /* 2733 /*
2829 expand_set_mousemodel(optexpand_T *args, int *numMatches, char_u ***matches) 2829 expand_set_mousemodel(optexpand_T *args, int *numMatches, char_u ***matches)
2830 { 2830 {
2831 return expand_set_opt_string( 2831 return expand_set_opt_string(
2832 args, 2832 args,
2833 p_mousem_values, 2833 p_mousem_values,
2834 sizeof(p_mousem_values) / sizeof(p_mousem_values[0]) - 1, 2834 ARRAY_LENGTH(p_mousem_values) - 1,
2835 numMatches, 2835 numMatches,
2836 matches); 2836 matches);
2837 } 2837 }
2838 2838
2839 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) 2839 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
2864 expand_set_nrformats(optexpand_T *args, int *numMatches, char_u ***matches) 2864 expand_set_nrformats(optexpand_T *args, int *numMatches, char_u ***matches)
2865 { 2865 {
2866 return expand_set_opt_string( 2866 return expand_set_opt_string(
2867 args, 2867 args,
2868 p_nf_values, 2868 p_nf_values,
2869 sizeof(p_nf_values) / sizeof(p_nf_values[0]) - 1, 2869 ARRAY_LENGTH(p_nf_values) - 1,
2870 numMatches, 2870 numMatches,
2871 matches); 2871 matches);
2872 } 2872 }
2873 2873
2874 #if defined(FEAT_EVAL) || defined(PROTO) 2874 #if defined(FEAT_EVAL) || defined(PROTO)
2938 expand_T *xp = args->oe_xp; 2938 expand_T *xp = args->oe_xp;
2939 2939
2940 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') 2940 if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
2941 { 2941 {
2942 // Within "highlight:"/"border:"/"align:", we have a subgroup of possible options. 2942 // Within "highlight:"/"border:"/"align:", we have a subgroup of possible options.
2943 int border_len = STRLEN("border:"); 2943 int border_len = (int)STRLEN("border:");
2944 if (xp->xp_pattern - args->oe_set_arg >= border_len && 2944 if (xp->xp_pattern - args->oe_set_arg >= border_len &&
2945 STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0) 2945 STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0)
2946 { 2946 {
2947 return expand_set_opt_string( 2947 return expand_set_opt_string(
2948 args, 2948 args,
2949 p_popup_option_border_values, 2949 p_popup_option_border_values,
2950 sizeof(p_popup_option_border_values) / sizeof(p_popup_option_border_values[0]) - 1, 2950 ARRAY_LENGTH(p_popup_option_border_values) - 1,
2951 numMatches, 2951 numMatches,
2952 matches); 2952 matches);
2953 } 2953 }
2954 int align_len = STRLEN("align:"); 2954 int align_len = (int)STRLEN("align:");
2955 if (xp->xp_pattern - args->oe_set_arg >= align_len && 2955 if (xp->xp_pattern - args->oe_set_arg >= align_len &&
2956 STRNCMP(xp->xp_pattern - align_len, "align:", align_len) == 0) 2956 STRNCMP(xp->xp_pattern - align_len, "align:", align_len) == 0)
2957 { 2957 {
2958 return expand_set_opt_string( 2958 return expand_set_opt_string(
2959 args, 2959 args,
2960 p_popup_option_align_values, 2960 p_popup_option_align_values,
2961 sizeof(p_popup_option_align_values) / sizeof(p_popup_option_align_values[0]) - 1, 2961 ARRAY_LENGTH(p_popup_option_align_values) - 1,
2962 numMatches, 2962 numMatches,
2963 matches); 2963 matches);
2964 } 2964 }
2965 int highlight_len = STRLEN("highlight:"); 2965 int highlight_len = (int)STRLEN("highlight:");
2966 if (xp->xp_pattern - args->oe_set_arg >= highlight_len && 2966 if (xp->xp_pattern - args->oe_set_arg >= highlight_len &&
2967 STRNCMP(xp->xp_pattern - highlight_len, "highlight:", highlight_len) == 0) 2967 STRNCMP(xp->xp_pattern - highlight_len, "highlight:", highlight_len) == 0)
2968 { 2968 {
2969 // Return the list of all highlight names 2969 // Return the list of all highlight names
2970 return expand_set_opt_generic( 2970 return expand_set_opt_generic(
2977 } 2977 }
2978 2978
2979 return expand_set_opt_string( 2979 return expand_set_opt_string(
2980 args, 2980 args,
2981 p_popup_option_values, 2981 p_popup_option_values,
2982 sizeof(p_popup_option_values) / sizeof(p_popup_option_values[0]) - 1, 2982 ARRAY_LENGTH(p_popup_option_values) - 1,
2983 numMatches, 2983 numMatches,
2984 matches); 2984 matches);
2985 } 2985 }
2986 #endif 2986 #endif
2987 2987
3020 #if defined(FEAT_PRINTER) || defined(PROTO) 3020 #if defined(FEAT_PRINTER) || defined(PROTO)
3021 3021
3022 static char_u * 3022 static char_u *
3023 get_printoptions_names(expand_T *xp UNUSED, int idx) 3023 get_printoptions_names(expand_T *xp UNUSED, int idx)
3024 { 3024 {
3025 if (idx >= (int)(sizeof(printer_opts) / sizeof(printer_opts[0]))) 3025 if (idx >= (int)ARRAY_LENGTH(printer_opts))
3026 return NULL; 3026 return NULL;
3027 return (char_u*)printer_opts[idx].name; 3027 return (char_u*)printer_opts[idx].name;
3028 } 3028 }
3029 3029
3030 /* 3030 /*
3113 { 3113 {
3114 static char *(p_rlc_values[]) = {"search", NULL}; 3114 static char *(p_rlc_values[]) = {"search", NULL};
3115 return expand_set_opt_string( 3115 return expand_set_opt_string(
3116 args, 3116 args,
3117 p_rlc_values, 3117 p_rlc_values,
3118 sizeof(p_rlc_values) / sizeof(p_rlc_values[0]) - 1, 3118 ARRAY_LENGTH(p_rlc_values) - 1,
3119 numMatches, 3119 numMatches,
3120 matches); 3120 matches);
3121 } 3121 }
3122 #endif 3122 #endif
3123 3123
3145 expand_set_scrollopt(optexpand_T *args, int *numMatches, char_u ***matches) 3145 expand_set_scrollopt(optexpand_T *args, int *numMatches, char_u ***matches)
3146 { 3146 {
3147 return expand_set_opt_string( 3147 return expand_set_opt_string(
3148 args, 3148 args,
3149 p_scbopt_values, 3149 p_scbopt_values,
3150 sizeof(p_scbopt_values) / sizeof(p_scbopt_values[0]) - 1, 3150 ARRAY_LENGTH(p_scbopt_values) - 1,
3151 numMatches, 3151 numMatches,
3152 matches); 3152 matches);
3153 } 3153 }
3154 3154
3155 /* 3155 /*
3168 expand_set_selection(optexpand_T *args, int *numMatches, char_u ***matches) 3168 expand_set_selection(optexpand_T *args, int *numMatches, char_u ***matches)
3169 { 3169 {
3170 return expand_set_opt_string( 3170 return expand_set_opt_string(
3171 args, 3171 args,
3172 p_sel_values, 3172 p_sel_values,
3173 sizeof(p_sel_values) / sizeof(p_sel_values[0]) - 1, 3173 ARRAY_LENGTH(p_sel_values) - 1,
3174 numMatches, 3174 numMatches,
3175 matches); 3175 matches);
3176 } 3176 }
3177 3177
3178 /* 3178 /*
3188 expand_set_selectmode(optexpand_T *args, int *numMatches, char_u ***matches) 3188 expand_set_selectmode(optexpand_T *args, int *numMatches, char_u ***matches)
3189 { 3189 {
3190 return expand_set_opt_string( 3190 return expand_set_opt_string(
3191 args, 3191 args,
3192 p_slm_values, 3192 p_slm_values,
3193 sizeof(p_slm_values) / sizeof(p_slm_values[0]) - 1, 3193 ARRAY_LENGTH(p_slm_values) - 1,
3194 numMatches, 3194 numMatches,
3195 matches); 3195 matches);
3196 } 3196 }
3197 3197
3198 #if defined(FEAT_SESSION) || defined(PROTO) 3198 #if defined(FEAT_SESSION) || defined(PROTO)
3219 expand_set_sessionoptions(optexpand_T *args, int *numMatches, char_u ***matches) 3219 expand_set_sessionoptions(optexpand_T *args, int *numMatches, char_u ***matches)
3220 { 3220 {
3221 return expand_set_opt_string( 3221 return expand_set_opt_string(
3222 args, 3222 args,
3223 p_ssop_values, 3223 p_ssop_values,
3224 sizeof(p_ssop_values) / sizeof(p_ssop_values[0]) - 1, 3224 ARRAY_LENGTH(p_ssop_values) - 1,
3225 numMatches, 3225 numMatches,
3226 matches); 3226 matches);
3227 } 3227 }
3228 #endif 3228 #endif
3229 3229
3278 expand_set_showcmdloc(optexpand_T *args, int *numMatches, char_u ***matches) 3278 expand_set_showcmdloc(optexpand_T *args, int *numMatches, char_u ***matches)
3279 { 3279 {
3280 return expand_set_opt_string( 3280 return expand_set_opt_string(
3281 args, 3281 args,
3282 p_sloc_values, 3282 p_sloc_values,
3283 sizeof(p_sloc_values) / sizeof(p_sloc_values[0]) - 1, 3283 ARRAY_LENGTH(p_sloc_values) - 1,
3284 numMatches, 3284 numMatches,
3285 matches); 3285 matches);
3286 } 3286 }
3287 3287
3288 #if defined(FEAT_SIGNS) || defined(PROTO) 3288 #if defined(FEAT_SIGNS) || defined(PROTO)
3310 expand_set_signcolumn(optexpand_T *args, int *numMatches, char_u ***matches) 3310 expand_set_signcolumn(optexpand_T *args, int *numMatches, char_u ***matches)
3311 { 3311 {
3312 return expand_set_opt_string( 3312 return expand_set_opt_string(
3313 args, 3313 args,
3314 p_scl_values, 3314 p_scl_values,
3315 sizeof(p_scl_values) / sizeof(p_scl_values[0]) - 1, 3315 ARRAY_LENGTH(p_scl_values) - 1,
3316 numMatches, 3316 numMatches,
3317 matches); 3317 matches);
3318 } 3318 }
3319 #endif 3319 #endif
3320 3320
3380 { 3380 {
3381 static char *(p_spo_values[]) = {"camel", NULL}; 3381 static char *(p_spo_values[]) = {"camel", NULL};
3382 return expand_set_opt_string( 3382 return expand_set_opt_string(
3383 args, 3383 args,
3384 p_spo_values, 3384 p_spo_values,
3385 sizeof(p_spo_values) / sizeof(p_spo_values[0]) - 1, 3385 ARRAY_LENGTH(p_spo_values) - 1,
3386 numMatches, 3386 numMatches,
3387 matches); 3387 matches);
3388 } 3388 }
3389 3389
3390 /* 3390 /*
3403 expand_set_spellsuggest(optexpand_T *args, int *numMatches, char_u ***matches) 3403 expand_set_spellsuggest(optexpand_T *args, int *numMatches, char_u ***matches)
3404 { 3404 {
3405 return expand_set_opt_string( 3405 return expand_set_opt_string(
3406 args, 3406 args,
3407 p_sps_values, 3407 p_sps_values,
3408 sizeof(p_sps_values) / sizeof(p_sps_values[0]) - 1, 3408 ARRAY_LENGTH(p_sps_values) - 1,
3409 numMatches, 3409 numMatches,
3410 matches); 3410 matches);
3411 } 3411 }
3412 #endif 3412 #endif
3413 3413
3424 expand_set_splitkeep(optexpand_T *args, int *numMatches, char_u ***matches) 3424 expand_set_splitkeep(optexpand_T *args, int *numMatches, char_u ***matches)
3425 { 3425 {
3426 return expand_set_opt_string( 3426 return expand_set_opt_string(
3427 args, 3427 args,
3428 p_spk_values, 3428 p_spk_values,
3429 sizeof(p_spk_values) / sizeof(p_spk_values[0]) - 1, 3429 ARRAY_LENGTH(p_spk_values) - 1,
3430 numMatches, 3430 numMatches,
3431 matches); 3431 matches);
3432 } 3432 }
3433 3433
3434 #if defined(FEAT_STL_OPT) || defined(PROTO) 3434 #if defined(FEAT_STL_OPT) || defined(PROTO)
3455 expand_set_swapsync(optexpand_T *args, int *numMatches, char_u ***matches) 3455 expand_set_swapsync(optexpand_T *args, int *numMatches, char_u ***matches)
3456 { 3456 {
3457 return expand_set_opt_string( 3457 return expand_set_opt_string(
3458 args, 3458 args,
3459 p_sws_values, 3459 p_sws_values,
3460 sizeof(p_sws_values) / sizeof(p_sws_values[0]) - 1, 3460 ARRAY_LENGTH(p_sws_values) - 1,
3461 numMatches, 3461 numMatches,
3462 matches); 3462 matches);
3463 } 3463 }
3464 3464
3465 /* 3465 /*
3475 expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches) 3475 expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches)
3476 { 3476 {
3477 return expand_set_opt_string( 3477 return expand_set_opt_string(
3478 args, 3478 args,
3479 p_swb_values, 3479 p_swb_values,
3480 sizeof(p_swb_values) / sizeof(p_swb_values[0]) - 1, 3480 ARRAY_LENGTH(p_swb_values) - 1,
3481 numMatches, 3481 numMatches,
3482 matches); 3482 matches);
3483 } 3483 }
3484 3484
3485 #if defined(FEAT_STL_OPT) || defined(PROTO) 3485 #if defined(FEAT_STL_OPT) || defined(PROTO)
3527 expand_set_tagcase(optexpand_T *args, int *numMatches, char_u ***matches) 3527 expand_set_tagcase(optexpand_T *args, int *numMatches, char_u ***matches)
3528 { 3528 {
3529 return expand_set_opt_string( 3529 return expand_set_opt_string(
3530 args, 3530 args,
3531 p_tc_values, 3531 p_tc_values,
3532 sizeof(p_tc_values) / sizeof(p_tc_values[0]) - 1, 3532 ARRAY_LENGTH(p_tc_values) - 1,
3533 numMatches, 3533 numMatches,
3534 matches); 3534 matches);
3535 } 3535 }
3536 3536
3537 /* 3537 /*
3672 expand_set_termwintype(optexpand_T *args, int *numMatches, char_u ***matches) 3672 expand_set_termwintype(optexpand_T *args, int *numMatches, char_u ***matches)
3673 { 3673 {
3674 return expand_set_opt_string( 3674 return expand_set_opt_string(
3675 args, 3675 args,
3676 p_twt_values, 3676 p_twt_values,
3677 sizeof(p_twt_values) / sizeof(p_twt_values[0]) - 1, 3677 ARRAY_LENGTH(p_twt_values) - 1,
3678 numMatches, 3678 numMatches,
3679 matches); 3679 matches);
3680 } 3680 }
3681 # endif 3681 # endif
3682 #endif 3682 #endif
3716 expand_set_toolbar(optexpand_T *args, int *numMatches, char_u ***matches) 3716 expand_set_toolbar(optexpand_T *args, int *numMatches, char_u ***matches)
3717 { 3717 {
3718 return expand_set_opt_string( 3718 return expand_set_opt_string(
3719 args, 3719 args,
3720 p_toolbar_values, 3720 p_toolbar_values,
3721 sizeof(p_toolbar_values) / sizeof(p_toolbar_values[0]) - 1, 3721 ARRAY_LENGTH(p_toolbar_values) - 1,
3722 numMatches, 3722 numMatches,
3723 matches); 3723 matches);
3724 } 3724 }
3725 #endif 3725 #endif
3726 3726
3744 expand_set_toolbariconsize(optexpand_T *args, int *numMatches, char_u ***matches) 3744 expand_set_toolbariconsize(optexpand_T *args, int *numMatches, char_u ***matches)
3745 { 3745 {
3746 return expand_set_opt_string( 3746 return expand_set_opt_string(
3747 args, 3747 args,
3748 p_tbis_values, 3748 p_tbis_values,
3749 sizeof(p_tbis_values) / sizeof(p_tbis_values[0]) - 1, 3749 ARRAY_LENGTH(p_tbis_values) - 1,
3750 numMatches, 3750 numMatches,
3751 matches); 3751 matches);
3752 } 3752 }
3753 #endif 3753 #endif
3754 3754
3778 expand_set_ttymouse(optexpand_T *args, int *numMatches, char_u ***matches) 3778 expand_set_ttymouse(optexpand_T *args, int *numMatches, char_u ***matches)
3779 { 3779 {
3780 return expand_set_opt_string( 3780 return expand_set_opt_string(
3781 args, 3781 args,
3782 p_ttym_values, 3782 p_ttym_values,
3783 sizeof(p_ttym_values) / sizeof(p_ttym_values[0]) - 1, 3783 ARRAY_LENGTH(p_ttym_values) - 1,
3784 numMatches, 3784 numMatches,
3785 matches); 3785 matches);
3786 } 3786 }
3787 #endif 3787 #endif
3788 3788
3994 expand_set_virtualedit(optexpand_T *args, int *numMatches, char_u ***matches) 3994 expand_set_virtualedit(optexpand_T *args, int *numMatches, char_u ***matches)
3995 { 3995 {
3996 return expand_set_opt_string( 3996 return expand_set_opt_string(
3997 args, 3997 args,
3998 p_ve_values, 3998 p_ve_values,
3999 sizeof(p_ve_values) / sizeof(p_ve_values[0]) - 1, 3999 ARRAY_LENGTH(p_ve_values) - 1,
4000 numMatches, 4000 numMatches,
4001 matches); 4001 matches);
4002 } 4002 }
4003 4003
4004 /* 4004 /*
4035 expand_set_wildmode(optexpand_T *args, int *numMatches, char_u ***matches) 4035 expand_set_wildmode(optexpand_T *args, int *numMatches, char_u ***matches)
4036 { 4036 {
4037 return expand_set_opt_string( 4037 return expand_set_opt_string(
4038 args, 4038 args,
4039 p_wim_values, 4039 p_wim_values,
4040 sizeof(p_wim_values) / sizeof(p_wim_values[0]) - 1, 4040 ARRAY_LENGTH(p_wim_values) - 1,
4041 numMatches, 4041 numMatches,
4042 matches); 4042 matches);
4043 } 4043 }
4044 4044
4045 /* 4045 /*
4055 expand_set_wildoptions(optexpand_T *args, int *numMatches, char_u ***matches) 4055 expand_set_wildoptions(optexpand_T *args, int *numMatches, char_u ***matches)
4056 { 4056 {
4057 return expand_set_opt_string( 4057 return expand_set_opt_string(
4058 args, 4058 args,
4059 p_wop_values, 4059 p_wop_values,
4060 sizeof(p_wop_values) / sizeof(p_wop_values[0]) - 1, 4060 ARRAY_LENGTH(p_wop_values) - 1,
4061 numMatches, 4061 numMatches,
4062 matches); 4062 matches);
4063 } 4063 }
4064 4064
4065 #if defined(FEAT_WAK) || defined(PROTO) 4065 #if defined(FEAT_WAK) || defined(PROTO)
4089 expand_set_winaltkeys(optexpand_T *args, int *numMatches, char_u ***matches) 4089 expand_set_winaltkeys(optexpand_T *args, int *numMatches, char_u ***matches)
4090 { 4090 {
4091 return expand_set_opt_string( 4091 return expand_set_opt_string(
4092 args, 4092 args,
4093 p_wak_values, 4093 p_wak_values,
4094 sizeof(p_wak_values) / sizeof(p_wak_values[0]) - 1, 4094 ARRAY_LENGTH(p_wak_values) - 1,
4095 numMatches, 4095 numMatches,
4096 matches); 4096 matches);
4097 } 4097 }
4098 #endif 4098 #endif
4099 4099