comparison src/highlight.c @ 31667:b89cfd86e18e v9.0.1166

patch 9.0.1166: code is indented more than necessary Commit: https://github.com/vim/vim/commit/1cfb14aa972ccf3235ac67f07b7db1175b7c5384 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Jan 9 19:04:23 2023 +0000 patch 9.0.1166: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11792)
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Jan 2023 20:15:03 +0100
parents 53c3df37a2b0
children 4545f58c8490
comparison
equal deleted inserted replaced
31666:feb8dcde5ff2 31667:b89cfd86e18e
919 return did_change; 919 return did_change;
920 } 920 }
921 #endif 921 #endif
922 922
923 /* 923 /*
924 * Set the cterm foreground color for the Normal highlight group to "color" and
925 * the bold attribute to "bold".
926 */
927 static void
928 hl_set_ctermfg_normal_group(int color, int bold)
929 {
930 cterm_normal_fg_color = color + 1;
931 cterm_normal_fg_bold = bold;
932 #ifdef FEAT_GUI
933 // Don't do this if the GUI is used.
934 if (!gui.in_use && !gui.starting)
935 #endif
936 {
937 set_must_redraw(UPD_CLEAR);
938 if (termcap_active && color >= 0)
939 term_fg_color(color);
940 }
941 }
942
943 /*
924 * Set the cterm foreground color for the highlight group at 'idx' to 'color'. 944 * Set the cterm foreground color for the highlight group at 'idx' to 'color'.
925 * Returns TRUE if the foreground color is set.
926 */ 945 */
927 static void 946 static void
928 highlight_set_ctermfg(int idx, int color, int is_normal_group) 947 highlight_set_ctermfg(int idx, int color, int is_normal_group)
929 { 948 {
930 HL_TABLE()[idx].sg_cterm_fg = color + 1; 949 HL_TABLE()[idx].sg_cterm_fg = color + 1;
931 if (is_normal_group) 950 if (is_normal_group)
932 { 951 hl_set_ctermfg_normal_group(color,
933 cterm_normal_fg_color = color + 1; 952 (HL_TABLE()[idx].sg_cterm & HL_BOLD));
934 cterm_normal_fg_bold = (HL_TABLE()[idx].sg_cterm & HL_BOLD); 953 }
954
955 /*
956 * Set the cterm background color for the Normal highlight group to "color".
957 */
958 static void
959 hl_set_ctermbg_normal_group(int color)
960 {
961 cterm_normal_bg_color = color + 1;
935 #ifdef FEAT_GUI 962 #ifdef FEAT_GUI
936 // Don't do this if the GUI is used. 963 // Don't mess with 'background' if the GUI is used.
937 if (!gui.in_use && !gui.starting) 964 if (!gui.in_use && !gui.starting)
938 #endif 965 #endif
939 { 966 {
940 set_must_redraw(UPD_CLEAR); 967 set_must_redraw(UPD_CLEAR);
941 if (termcap_active && color >= 0) 968 if (color >= 0)
942 term_fg_color(color); 969 {
970 int dark = -1;
971
972 if (termcap_active)
973 term_bg_color(color);
974 if (t_colors < 16)
975 dark = (color == 0 || color == 4);
976 // Limit the heuristic to the standard 16 colors
977 else if (color < 16)
978 dark = (color < 7 || color == 8);
979 // Set the 'background' option if the value is
980 // wrong.
981 if (dark != -1
982 && dark != (*p_bg == 'd')
983 && !option_was_set((char_u *)"bg"))
984 {
985 set_option_value_give_err((char_u *)"bg",
986 0L, (char_u *)(dark ? "dark" : "light"), 0);
987 reset_option_was_set((char_u *)"bg");
988 }
943 } 989 }
944 } 990 }
945 } 991 }
946 992
947 /* 993 /*
948 * Set the cterm background color for the highlight group at 'idx' to 'color'. 994 * Set the cterm background color for the highlight group at 'idx' to 'color'.
949 * Returns TRUE if the background color is set.
950 */ 995 */
951 static void 996 static void
952 highlight_set_ctermbg(int idx, int color, int is_normal_group) 997 highlight_set_ctermbg(int idx, int color, int is_normal_group)
953 { 998 {
954 HL_TABLE()[idx].sg_cterm_bg = color + 1; 999 HL_TABLE()[idx].sg_cterm_bg = color + 1;
955 if (is_normal_group) 1000 if (is_normal_group)
956 { 1001 hl_set_ctermbg_normal_group(color);
957 cterm_normal_bg_color = color + 1; 1002 }
1003
1004 /*
1005 * Set the cterm underline color for the Normal highlight group to "color".
1006 */
1007 static void
1008 hl_set_ctermul_normal_group(int color)
1009 {
1010 cterm_normal_ul_color = color + 1;
958 #ifdef FEAT_GUI 1011 #ifdef FEAT_GUI
959 // Don't mess with 'background' if the GUI is used. 1012 // Don't do this if the GUI is used.
960 if (!gui.in_use && !gui.starting) 1013 if (!gui.in_use && !gui.starting)
961 #endif 1014 #endif
962 { 1015 {
963 set_must_redraw(UPD_CLEAR); 1016 set_must_redraw(UPD_CLEAR);
964 if (color >= 0) 1017 if (termcap_active && color >= 0)
965 { 1018 term_ul_color(color);
966 int dark = -1;
967
968 if (termcap_active)
969 term_bg_color(color);
970 if (t_colors < 16)
971 dark = (color == 0 || color == 4);
972 // Limit the heuristic to the standard 16 colors
973 else if (color < 16)
974 dark = (color < 7 || color == 8);
975 // Set the 'background' option if the value is
976 // wrong.
977 if (dark != -1
978 && dark != (*p_bg == 'd')
979 && !option_was_set((char_u *)"bg"))
980 {
981 set_option_value_give_err((char_u *)"bg",
982 0L, (char_u *)(dark ? "dark" : "light"), 0);
983 reset_option_was_set((char_u *)"bg");
984 }
985 }
986 }
987 } 1019 }
988 } 1020 }
989 1021
990 /* 1022 /*
991 * Set the cterm underline color for the highlight group at 'idx' to 'color'. 1023 * Set the cterm underline color for the highlight group at 'idx' to 'color'.
992 * Returns TRUE if the underline color is set.
993 */ 1024 */
994 static void 1025 static void
995 highlight_set_ctermul(int idx, int color, int is_normal_group) 1026 highlight_set_ctermul(int idx, int color, int is_normal_group)
996 { 1027 {
997 HL_TABLE()[idx].sg_cterm_ul = color + 1; 1028 HL_TABLE()[idx].sg_cterm_ul = color + 1;
998 if (is_normal_group) 1029 if (is_normal_group)
999 { 1030 hl_set_ctermul_normal_group(color);
1000 cterm_normal_ul_color = color + 1;
1001 #ifdef FEAT_GUI
1002 // Don't do this if the GUI is used.
1003 if (!gui.in_use && !gui.starting)
1004 #endif
1005 {
1006 set_must_redraw(UPD_CLEAR);
1007 if (termcap_active && color >= 0)
1008 term_ul_color(color);
1009 }
1010 }
1011 } 1031 }
1012 1032
1013 /* 1033 /*
1014 * Set the cterm fg/bg/ul color for the highlight group at 'idx'. 1034 * Set the cterm fg/bg/ul color for the highlight group at 'idx'.
1015 * 'key' is one of 'CTERMFG' or 'CTERMBG' or 'CTERMUL'. 1035 * 'key' is one of 'CTERMFG' or 'CTERMBG' or 'CTERMUL'.
1032 { 1052 {
1033 int color; 1053 int color;
1034 long i; 1054 long i;
1035 int off; 1055 int off;
1036 1056
1037 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) 1057 if (init && (HL_TABLE()[idx].sg_set & SG_CTERM))
1038 { 1058 return FALSE;
1039 if (!init) 1059
1040 HL_TABLE()[idx].sg_set |= SG_CTERM; 1060 if (!init)
1041 1061 HL_TABLE()[idx].sg_set |= SG_CTERM;
1042 // When setting the foreground color, and previously the "bold" 1062
1043 // flag was set for a light color, reset it now 1063 // When setting the foreground color, and previously the "bold"
1044 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold) 1064 // flag was set for a light color, reset it now
1045 { 1065 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold)
1066 {
1067 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
1068 HL_TABLE()[idx].sg_cterm_bold = FALSE;
1069 }
1070
1071 if (VIM_ISDIGIT(*arg))
1072 color = atoi((char *)arg);
1073 else if (STRICMP(arg, "fg") == 0)
1074 {
1075 if (cterm_normal_fg_color)
1076 color = cterm_normal_fg_color - 1;
1077 else
1078 {
1079 emsg(_(e_fg_color_unknown));
1080 return FALSE;
1081 }
1082 }
1083 else if (STRICMP(arg, "bg") == 0)
1084 {
1085 if (cterm_normal_bg_color > 0)
1086 color = cterm_normal_bg_color - 1;
1087 else
1088 {
1089 emsg(_(e_bg_color_unknown));
1090 return FALSE;
1091 }
1092 }
1093 else if (STRICMP(arg, "ul") == 0)
1094 {
1095 if (cterm_normal_ul_color > 0)
1096 color = cterm_normal_ul_color - 1;
1097 else
1098 {
1099 emsg(_(e_ul_color_unknown));
1100 return FALSE;
1101 }
1102 }
1103 else
1104 {
1105 int bold = MAYBE;
1106
1107 // reduce calls to STRICMP a bit, it can be slow
1108 off = TOUPPER_ASC(*arg);
1109 for (i = ARRAY_LENGTH(color_names); --i >= 0; )
1110 if (off == color_names[i][0]
1111 && STRICMP(arg + 1, color_names[i] + 1) == 0)
1112 break;
1113 if (i < 0)
1114 {
1115 semsg(_(e_color_name_or_number_not_recognized_str), key_start);
1116 return FALSE;
1117 }
1118
1119 color = lookup_color(i, key[5] == 'F', &bold);
1120
1121 // set/reset bold attribute to get light foreground
1122 // colors (on some terminals, e.g. "linux")
1123 if (bold == TRUE)
1124 {
1125 HL_TABLE()[idx].sg_cterm |= HL_BOLD;
1126 HL_TABLE()[idx].sg_cterm_bold = TRUE;
1127 }
1128 else if (bold == FALSE)
1046 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; 1129 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
1047 HL_TABLE()[idx].sg_cterm_bold = FALSE; 1130 }
1048 } 1131
1049 1132 // Add one to the argument, to avoid zero. Zero is used for
1050 if (VIM_ISDIGIT(*arg)) 1133 // "NONE", then "color" is -1.
1051 color = atoi((char *)arg); 1134 if (key[5] == 'F')
1052 else if (STRICMP(arg, "fg") == 0) 1135 highlight_set_ctermfg(idx, color, is_normal_group);
1053 { 1136 else if (key[5] == 'B')
1054 if (cterm_normal_fg_color) 1137 highlight_set_ctermbg(idx, color, is_normal_group);
1055 color = cterm_normal_fg_color - 1; 1138 else // ctermul
1056 else 1139 highlight_set_ctermul(idx, color, is_normal_group);
1057 {
1058 emsg(_(e_fg_color_unknown));
1059 return FALSE;
1060 }
1061 }
1062 else if (STRICMP(arg, "bg") == 0)
1063 {
1064 if (cterm_normal_bg_color > 0)
1065 color = cterm_normal_bg_color - 1;
1066 else
1067 {
1068 emsg(_(e_bg_color_unknown));
1069 return FALSE;
1070 }
1071 }
1072 else if (STRICMP(arg, "ul") == 0)
1073 {
1074 if (cterm_normal_ul_color > 0)
1075 color = cterm_normal_ul_color - 1;
1076 else
1077 {
1078 emsg(_(e_ul_color_unknown));
1079 return FALSE;
1080 }
1081 }
1082 else
1083 {
1084 int bold = MAYBE;
1085
1086 // reduce calls to STRICMP a bit, it can be slow
1087 off = TOUPPER_ASC(*arg);
1088 for (i = ARRAY_LENGTH(color_names); --i >= 0; )
1089 if (off == color_names[i][0]
1090 && STRICMP(arg + 1, color_names[i] + 1) == 0)
1091 break;
1092 if (i < 0)
1093 {
1094 semsg(_(e_color_name_or_number_not_recognized_str), key_start);
1095 return FALSE;
1096 }
1097
1098 color = lookup_color(i, key[5] == 'F', &bold);
1099
1100 // set/reset bold attribute to get light foreground
1101 // colors (on some terminals, e.g. "linux")
1102 if (bold == TRUE)
1103 {
1104 HL_TABLE()[idx].sg_cterm |= HL_BOLD;
1105 HL_TABLE()[idx].sg_cterm_bold = TRUE;
1106 }
1107 else if (bold == FALSE)
1108 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
1109 }
1110
1111 // Add one to the argument, to avoid zero. Zero is used for
1112 // "NONE", then "color" is -1.
1113 if (key[5] == 'F')
1114 highlight_set_ctermfg(idx, color, is_normal_group);
1115 else if (key[5] == 'B')
1116 highlight_set_ctermbg(idx, color, is_normal_group);
1117 else // ctermul
1118 highlight_set_ctermul(idx, color, is_normal_group);
1119 }
1120 1140
1121 return TRUE; 1141 return TRUE;
1122 } 1142 }
1123 1143
1124 #if defined(FEAT_GUI) || defined(FEAT_EVAL) 1144 #if defined(FEAT_GUI) || defined(FEAT_EVAL)
1140 long i; 1160 long i;
1141 # endif 1161 # endif
1142 char_u **namep; 1162 char_u **namep;
1143 int did_change = FALSE; 1163 int did_change = FALSE;
1144 1164
1165 if (init && (HL_TABLE()[idx].sg_set & SG_GUI))
1166 return FALSE;
1167
1145 namep = &HL_TABLE()[idx].sg_gui_fg_name; 1168 namep = &HL_TABLE()[idx].sg_gui_fg_name;
1146 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) 1169 if (!init)
1147 { 1170 HL_TABLE()[idx].sg_set |= SG_GUI;
1148 if (!init)
1149 HL_TABLE()[idx].sg_set |= SG_GUI;
1150 1171
1151 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1172 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1152 // In GUI guifg colors are only used when recognized 1173 // In GUI guifg colors are only used when recognized
1153 i = color_name2handle(arg); 1174 i = color_name2handle(arg);
1154 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) 1175 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT)
1155 { 1176 {
1156 HL_TABLE()[idx].sg_gui_fg = i; 1177 HL_TABLE()[idx].sg_gui_fg = i;
1157 # endif 1178 # endif
1158 if (*namep == NULL || STRCMP(*namep, arg) != 0) 1179 if (*namep == NULL || STRCMP(*namep, arg) != 0)
1159 { 1180 {
1160 vim_free(*namep); 1181 vim_free(*namep);
1161 if (STRCMP(arg, "NONE") != 0) 1182 if (STRCMP(arg, "NONE") != 0)
1162 *namep = vim_strsave(arg); 1183 *namep = vim_strsave(arg);
1163 else 1184 else
1164 *namep = NULL; 1185 *namep = NULL;
1165 did_change = TRUE; 1186 did_change = TRUE;
1166 } 1187 }
1167 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1188 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1168 # ifdef FEAT_GUI_X11 1189 # ifdef FEAT_GUI_X11
1169 if (is_menu_group && gui.menu_fg_pixel != i) 1190 if (is_menu_group && gui.menu_fg_pixel != i)
1170 { 1191 {
1171 gui.menu_fg_pixel = i; 1192 gui.menu_fg_pixel = i;
1172 *do_colors = TRUE; 1193 *do_colors = TRUE;
1173 } 1194 }
1174 if (is_scrollbar_group && gui.scroll_fg_pixel != i) 1195 if (is_scrollbar_group && gui.scroll_fg_pixel != i)
1175 { 1196 {
1176 gui.scroll_fg_pixel = i; 1197 gui.scroll_fg_pixel = i;
1177 *do_colors = TRUE; 1198 *do_colors = TRUE;
1178 } 1199 }
1179 # ifdef FEAT_BEVAL_GUI 1200 # ifdef FEAT_BEVAL_GUI
1180 if (is_tooltip_group && gui.tooltip_fg_pixel != i) 1201 if (is_tooltip_group && gui.tooltip_fg_pixel != i)
1181 { 1202 {
1182 gui.tooltip_fg_pixel = i; 1203 gui.tooltip_fg_pixel = i;
1183 *do_colors = TRUE; 1204 *do_colors = TRUE;
1184 } 1205 }
1185 # endif 1206 # endif
1186 # endif 1207 # endif
1187 } 1208 }
1188 # endif 1209 # endif
1189 }
1190 1210
1191 return did_change; 1211 return did_change;
1192 } 1212 }
1193 1213
1194 /* 1214 /*
1209 int i; 1229 int i;
1210 # endif 1230 # endif
1211 char_u **namep; 1231 char_u **namep;
1212 int did_change = FALSE; 1232 int did_change = FALSE;
1213 1233
1234 if (init && (HL_TABLE()[idx].sg_set & SG_GUI))
1235 return FALSE;
1236
1214 namep = &HL_TABLE()[idx].sg_gui_bg_name; 1237 namep = &HL_TABLE()[idx].sg_gui_bg_name;
1215 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) 1238 if (!init)
1216 { 1239 HL_TABLE()[idx].sg_set |= SG_GUI;
1217 if (!init)
1218 HL_TABLE()[idx].sg_set |= SG_GUI;
1219 1240
1220 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1241 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1221 // In GUI guibg colors are only used when recognized 1242 // In GUI guibg colors are only used when recognized
1222 i = color_name2handle(arg); 1243 i = color_name2handle(arg);
1223 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) 1244 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT)
1224 { 1245 {
1225 HL_TABLE()[idx].sg_gui_bg = i; 1246 HL_TABLE()[idx].sg_gui_bg = i;
1226 # endif 1247 # endif
1227 if (*namep == NULL || STRCMP(*namep, arg) != 0) 1248 if (*namep == NULL || STRCMP(*namep, arg) != 0)
1228 { 1249 {
1229 vim_free(*namep); 1250 vim_free(*namep);
1230 if (STRCMP(arg, "NONE") != 0) 1251 if (STRCMP(arg, "NONE") != 0)
1231 *namep = vim_strsave(arg); 1252 *namep = vim_strsave(arg);
1232 else 1253 else
1233 *namep = NULL; 1254 *namep = NULL;
1234 did_change = TRUE; 1255 did_change = TRUE;
1235 } 1256 }
1236 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1257 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1237 # ifdef FEAT_GUI_X11 1258 # ifdef FEAT_GUI_X11
1238 if (is_menu_group && gui.menu_bg_pixel != i) 1259 if (is_menu_group && gui.menu_bg_pixel != i)
1239 { 1260 {
1240 gui.menu_bg_pixel = i; 1261 gui.menu_bg_pixel = i;
1241 *do_colors = TRUE; 1262 *do_colors = TRUE;
1242 } 1263 }
1243 if (is_scrollbar_group && gui.scroll_bg_pixel != i) 1264 if (is_scrollbar_group && gui.scroll_bg_pixel != i)
1244 { 1265 {
1245 gui.scroll_bg_pixel = i; 1266 gui.scroll_bg_pixel = i;
1246 *do_colors = TRUE; 1267 *do_colors = TRUE;
1247 } 1268 }
1248 # ifdef FEAT_BEVAL_GUI 1269 # ifdef FEAT_BEVAL_GUI
1249 if (is_tooltip_group && gui.tooltip_bg_pixel != i) 1270 if (is_tooltip_group && gui.tooltip_bg_pixel != i)
1250 { 1271 {
1251 gui.tooltip_bg_pixel = i; 1272 gui.tooltip_bg_pixel = i;
1252 *do_colors = TRUE; 1273 *do_colors = TRUE;
1253 } 1274 }
1254 # endif 1275 # endif
1255 # endif 1276 # endif
1256 } 1277 }
1257 # endif 1278 # endif
1258 }
1259 1279
1260 return did_change; 1280 return did_change;
1261 } 1281 }
1262 1282
1263 /* 1283 /*
1271 int i; 1291 int i;
1272 # endif 1292 # endif
1273 int did_change = FALSE; 1293 int did_change = FALSE;
1274 char_u **namep; 1294 char_u **namep;
1275 1295
1296 if (init && (HL_TABLE()[idx].sg_set & SG_GUI))
1297 return FALSE;
1298
1276 namep = &HL_TABLE()[idx].sg_gui_sp_name; 1299 namep = &HL_TABLE()[idx].sg_gui_sp_name;
1277 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) 1300 if (!init)
1278 { 1301 HL_TABLE()[idx].sg_set |= SG_GUI;
1279 if (!init)
1280 HL_TABLE()[idx].sg_set |= SG_GUI;
1281 1302
1282 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1303 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1283 // In GUI guisp colors are only used when recognized 1304 // In GUI guisp colors are only used when recognized
1284 i = color_name2handle(arg); 1305 i = color_name2handle(arg);
1285 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) 1306 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT)
1286 { 1307 {
1287 HL_TABLE()[idx].sg_gui_sp = i; 1308 HL_TABLE()[idx].sg_gui_sp = i;
1288 # endif 1309 # endif
1289 if (*namep == NULL || STRCMP(*namep, arg) != 0) 1310 if (*namep == NULL || STRCMP(*namep, arg) != 0)
1290 { 1311 {
1291 vim_free(*namep); 1312 vim_free(*namep);
1292 if (STRCMP(arg, "NONE") != 0) 1313 if (STRCMP(arg, "NONE") != 0)
1293 *namep = vim_strsave(arg); 1314 *namep = vim_strsave(arg);
1294 else 1315 else
1295 *namep = NULL; 1316 *namep = NULL;
1296 did_change = TRUE; 1317 did_change = TRUE;
1297 } 1318 }
1298 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) 1319 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1299 } 1320 }
1300 # endif 1321 # endif
1301 }
1302 1322
1303 return did_change; 1323 return did_change;
1304 } 1324 }
1305 #endif 1325 #endif
1306 1326
1993 int do_tooltip) 2013 int do_tooltip)
1994 { 2014 {
1995 int idx; 2015 int idx;
1996 2016
1997 idx = syn_name2id(name) - 1; 2017 idx = syn_name2id(name) - 1;
1998 if (idx >= 0) 2018 if (idx < 0)
1999 { 2019 return FALSE;
2000 gui_do_one_color(idx, do_menu, do_tooltip); 2020
2001 2021 gui_do_one_color(idx, do_menu, do_tooltip);
2002 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) 2022
2003 *fgp = HL_TABLE()[idx].sg_gui_fg; 2023 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR)
2004 else if (use_norm) 2024 *fgp = HL_TABLE()[idx].sg_gui_fg;
2005 *fgp = gui.def_norm_pixel; 2025 else if (use_norm)
2006 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) 2026 *fgp = gui.def_norm_pixel;
2007 *bgp = HL_TABLE()[idx].sg_gui_bg; 2027 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR)
2008 else if (use_norm) 2028 *bgp = HL_TABLE()[idx].sg_gui_bg;
2009 *bgp = gui.def_back_pixel; 2029 else if (use_norm)
2010 return TRUE; 2030 *bgp = gui.def_back_pixel;
2011 } 2031 return TRUE;
2012 return FALSE;
2013 } 2032 }
2014 2033
2015 /* 2034 /*
2016 * Get the font of the "Normal" group. 2035 * Get the font of the "Normal" group.
2017 * Returns "" when it's not found or not set. 2036 * Returns "" when it's not found or not set.
2040 hl_set_font_name(char_u *font_name) 2059 hl_set_font_name(char_u *font_name)
2041 { 2060 {
2042 int id; 2061 int id;
2043 2062
2044 id = syn_name2id((char_u *)"Normal"); 2063 id = syn_name2id((char_u *)"Normal");
2045 if (id > 0) 2064 if (id <= 0)
2046 { 2065 return;
2047 vim_free(HL_TABLE()[id - 1].sg_font_name); 2066
2048 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name); 2067 vim_free(HL_TABLE()[id - 1].sg_font_name);
2049 } 2068 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name);
2050 } 2069 }
2051 2070
2052 /* 2071 /*
2053 * Set background color for "Normal" group. Called by gui_set_bg_color() 2072 * Set background color for "Normal" group. Called by gui_set_bg_color()
2054 * when the color is known. 2073 * when the color is known.
2057 hl_set_bg_color_name( 2076 hl_set_bg_color_name(
2058 char_u *name) // must have been allocated 2077 char_u *name) // must have been allocated
2059 { 2078 {
2060 int id; 2079 int id;
2061 2080
2062 if (name != NULL) 2081 if (name == NULL)
2063 { 2082 return;
2064 id = syn_name2id((char_u *)"Normal"); 2083
2065 if (id > 0) 2084 id = syn_name2id((char_u *)"Normal");
2066 { 2085 if (id <= 0)
2067 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name); 2086 return;
2068 HL_TABLE()[id - 1].sg_gui_bg_name = name; 2087
2069 } 2088 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name);
2070 } 2089 HL_TABLE()[id - 1].sg_gui_bg_name = name;
2071 } 2090 }
2072 2091
2073 /* 2092 /*
2074 * Set foreground color for "Normal" group. Called by gui_set_fg_color() 2093 * Set foreground color for "Normal" group. Called by gui_set_fg_color()
2075 * when the color is known. 2094 * when the color is known.
2078 hl_set_fg_color_name( 2097 hl_set_fg_color_name(
2079 char_u *name) // must have been allocated 2098 char_u *name) // must have been allocated
2080 { 2099 {
2081 int id; 2100 int id;
2082 2101
2083 if (name != NULL) 2102 if (name == NULL)
2084 { 2103 return;
2085 id = syn_name2id((char_u *)"Normal"); 2104
2086 if (id > 0) 2105 id = syn_name2id((char_u *)"Normal");
2087 { 2106 if (id <= 0)
2088 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name); 2107 return;
2089 HL_TABLE()[id - 1].sg_gui_fg_name = name; 2108
2090 } 2109 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name);
2091 } 2110 HL_TABLE()[id - 1].sg_gui_fg_name = name;
2092 } 2111 }
2093 2112
2094 /* 2113 /*
2095 * Return the handle for a font name. 2114 * Return the handle for a font name.
2096 * Returns NOFONT when failed. 2115 * Returns NOFONT when failed.
2971 char_u *ts; 2990 char_u *ts;
2972 int i; 2991 int i;
2973 2992
2974 if (got_int) 2993 if (got_int)
2975 return FALSE; 2994 return FALSE;
2976 if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) 2995
2977 { 2996 if (type == LIST_STRING ? (sarg == NULL) : (iarg == 0))
2978 ts = buf; 2997 return didh;
2979 if (type == LIST_INT) 2998
2980 sprintf((char *)buf, "%d", iarg - 1); 2999 ts = buf;
2981 else if (type == LIST_STRING) 3000 if (type == LIST_INT)
2982 ts = sarg; 3001 sprintf((char *)buf, "%d", iarg - 1);
2983 else // type == LIST_ATTR 3002 else if (type == LIST_STRING)
2984 { 3003 ts = sarg;
2985 buf[0] = NUL; 3004 else // type == LIST_ATTR
2986 for (i = 0; hl_attr_table[i] != 0; ++i) 3005 {
3006 buf[0] = NUL;
3007 for (i = 0; hl_attr_table[i] != 0; ++i)
3008 {
3009 if (iarg & hl_attr_table[i])
2987 { 3010 {
2988 if (iarg & hl_attr_table[i]) 3011 if (buf[0] != NUL)
2989 { 3012 vim_strcat(buf, (char_u *)",", MAX_ATTR_LEN);
2990 if (buf[0] != NUL) 3013 vim_strcat(buf, (char_u *)hl_name_table[i], MAX_ATTR_LEN);
2991 vim_strcat(buf, (char_u *)",", MAX_ATTR_LEN); 3014 iarg &= ~hl_attr_table[i]; // don't want "inverse"
2992 vim_strcat(buf, (char_u *)hl_name_table[i], MAX_ATTR_LEN);
2993 iarg &= ~hl_attr_table[i]; // don't want "inverse"
2994 }
2995 } 3015 }
2996 } 3016 }
2997 3017 }
2998 (void)syn_list_header(didh, 3018
2999 (int)(vim_strsize(ts) + STRLEN(name) + 1), id); 3019 (void)syn_list_header(didh,
3000 didh = TRUE; 3020 (int)(vim_strsize(ts) + STRLEN(name) + 1), id);
3001 if (!got_int) 3021 didh = TRUE;
3002 { 3022 if (!got_int)
3003 if (*name != NUL) 3023 {
3004 { 3024 if (*name != NUL)
3005 msg_puts_attr(name, HL_ATTR(HLF_D)); 3025 {
3006 msg_puts_attr("=", HL_ATTR(HLF_D)); 3026 msg_puts_attr(name, HL_ATTR(HLF_D));
3007 } 3027 msg_puts_attr("=", HL_ATTR(HLF_D));
3008 msg_outtrans(ts); 3028 }
3009 } 3029 msg_outtrans(ts);
3010 } 3030 }
3011 return didh; 3031 return didh;
3012 } 3032 }
3013 3033
3014 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO) 3034 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO)
3378 { 3398 {
3379 char_u *name; 3399 char_u *name;
3380 int id = 0; 3400 int id = 0;
3381 3401
3382 name = vim_strnsave(linep, len); 3402 name = vim_strnsave(linep, len);
3383 if (name != NULL) 3403 if (name == NULL)
3384 { 3404 return 0;
3385 id = syn_name2id(name); 3405
3386 vim_free(name); 3406 id = syn_name2id(name);
3387 } 3407 vim_free(name);
3388 return id; 3408 return id;
3389 } 3409 }
3390 3410
3391 /* 3411 /*
3392 * Find highlight group name in the table and return its ID. 3412 * Find highlight group name in the table and return its ID.
3925 xp->xp_context = EXPAND_HIGHLIGHT; 3945 xp->xp_context = EXPAND_HIGHLIGHT;
3926 xp->xp_pattern = arg; 3946 xp->xp_pattern = arg;
3927 include_link = 2; 3947 include_link = 2;
3928 include_default = 1; 3948 include_default = 1;
3929 3949
3950 if (*arg == NUL)
3951 return;
3952
3930 // (part of) subcommand already typed 3953 // (part of) subcommand already typed
3931 if (*arg != NUL) 3954 p = skiptowhite(arg);
3932 { 3955 if (*p == NUL)
3956 return;
3957
3958 // past "default" or group name
3959 include_default = 0;
3960 if (STRNCMP("default", arg, p - arg) == 0)
3961 {
3962 arg = skipwhite(p);
3963 xp->xp_pattern = arg;
3933 p = skiptowhite(arg); 3964 p = skiptowhite(arg);
3934 if (*p != NUL) // past "default" or group name 3965 }
3935 { 3966 if (*p == NUL)
3936 include_default = 0; 3967 return;
3937 if (STRNCMP("default", arg, p - arg) == 0) 3968
3938 { 3969 // past group name
3939 arg = skipwhite(p); 3970 include_link = 0;
3940 xp->xp_pattern = arg; 3971 if (arg[1] == 'i' && arg[0] == 'N')
3941 p = skiptowhite(arg); 3972 highlight_list();
3942 } 3973 if (STRNCMP("link", arg, p - arg) == 0
3943 if (*p != NUL) // past group name 3974 || STRNCMP("clear", arg, p - arg) == 0)
3944 { 3975 {
3945 include_link = 0; 3976 xp->xp_pattern = skipwhite(p);
3946 if (arg[1] == 'i' && arg[0] == 'N') 3977 p = skiptowhite(xp->xp_pattern);
3947 highlight_list(); 3978 if (*p != NUL) // past first group name
3948 if (STRNCMP("link", arg, p - arg) == 0 3979 {
3949 || STRNCMP("clear", arg, p - arg) == 0) 3980 xp->xp_pattern = skipwhite(p);
3950 { 3981 p = skiptowhite(xp->xp_pattern);
3951 xp->xp_pattern = skipwhite(p); 3982 }
3952 p = skiptowhite(xp->xp_pattern); 3983 }
3953 if (*p != NUL) // past first group name 3984 if (*p != NUL) // past group name(s)
3954 { 3985 xp->xp_context = EXPAND_NOTHING;
3955 xp->xp_pattern = skipwhite(p);
3956 p = skiptowhite(xp->xp_pattern);
3957 }
3958 }
3959 if (*p != NUL) // past group name(s)
3960 xp->xp_context = EXPAND_NOTHING;
3961 }
3962 }
3963 }
3964 } 3986 }
3965 3987
3966 /* 3988 /*
3967 * List highlighting matches in a nice way. 3989 * List highlighting matches in a nice way.
3968 */ 3990 */