Mercurial > vim
comparison src/menu.c @ 15470:55ccc2d353bd v8.1.0743
patch 8.1.0743: giving error messages is not flexible
commit https://github.com/vim/vim/commit/f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 13 23:38:42 2019 +0100
patch 8.1.0743: giving error messages is not flexible
Problem: Giving error messages is not flexible.
Solution: Add semsg(). Change argument from "char_u *" to "char *", also
for msg() and get rid of most MSG macros. (Ozaki Kiichi, closes
#3302) Also make emsg() accept a "char *" argument. Get rid of
an enormous number of type casts.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Jan 2019 23:45:08 +0100 |
parents | 6012cc6936f7 |
children | dd725a8ab112 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
272 #endif | 272 #endif |
273 | 273 |
274 menu_path = arg; | 274 menu_path = arg; |
275 if (*menu_path == '.') | 275 if (*menu_path == '.') |
276 { | 276 { |
277 EMSG2(_(e_invarg2), menu_path); | 277 semsg(_(e_invarg2), menu_path); |
278 goto theend; | 278 goto theend; |
279 } | 279 } |
280 | 280 |
281 map_to = menu_translate_tab_and_shift(arg); | 281 map_to = menu_translate_tab_and_shift(arg); |
282 | 282 |
288 show_menus(menu_path, modes); | 288 show_menus(menu_path, modes); |
289 goto theend; | 289 goto theend; |
290 } | 290 } |
291 else if (*map_to != NUL && (unmenu || enable != MAYBE)) | 291 else if (*map_to != NUL && (unmenu || enable != MAYBE)) |
292 { | 292 { |
293 EMSG(_(e_trailing)); | 293 emsg(_(e_trailing)); |
294 goto theend; | 294 goto theend; |
295 } | 295 } |
296 #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON)) | 296 #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON)) |
297 old_menu_height = gui.menu_height; | 297 old_menu_height = gui.menu_height; |
298 # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) | 298 # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) |
513 if (dname == NULL) | 513 if (dname == NULL) |
514 goto erret; | 514 goto erret; |
515 if (*dname == NUL) | 515 if (*dname == NUL) |
516 { | 516 { |
517 /* Only a mnemonic or accelerator is not valid. */ | 517 /* Only a mnemonic or accelerator is not valid. */ |
518 EMSG(_("E792: Empty menu name")); | 518 emsg(_("E792: Empty menu name")); |
519 goto erret; | 519 goto erret; |
520 } | 520 } |
521 | 521 |
522 /* See if it's already there */ | 522 /* See if it's already there */ |
523 lower_pri = menup; | 523 lower_pri = menup; |
531 if (menu_name_equal(name, menu) || menu_name_equal(dname, menu)) | 531 if (menu_name_equal(name, menu) || menu_name_equal(dname, menu)) |
532 { | 532 { |
533 if (*next_name == NUL && menu->children != NULL) | 533 if (*next_name == NUL && menu->children != NULL) |
534 { | 534 { |
535 if (!sys_menu) | 535 if (!sys_menu) |
536 EMSG(_("E330: Menu path must not lead to a sub-menu")); | 536 emsg(_("E330: Menu path must not lead to a sub-menu")); |
537 goto erret; | 537 goto erret; |
538 } | 538 } |
539 if (*next_name != NUL && menu->children == NULL | 539 if (*next_name != NUL && menu->children == NULL |
540 #ifdef FEAT_GUI_W32 | 540 #ifdef FEAT_GUI_W32 |
541 && addtearoff | 541 && addtearoff |
542 #endif | 542 #endif |
543 ) | 543 ) |
544 { | 544 { |
545 if (!sys_menu) | 545 if (!sys_menu) |
546 EMSG(_(e_notsubmenu)); | 546 emsg(_(e_notsubmenu)); |
547 goto erret; | 547 goto erret; |
548 } | 548 } |
549 break; | 549 break; |
550 } | 550 } |
551 menup = &menu->next; | 551 menup = &menu->next; |
570 | 570 |
571 if (menu == NULL) | 571 if (menu == NULL) |
572 { | 572 { |
573 if (*next_name == NUL && parent == NULL) | 573 if (*next_name == NUL && parent == NULL) |
574 { | 574 { |
575 EMSG(_("E331: Must not add menu items directly to menu bar")); | 575 emsg(_("E331: Must not add menu items directly to menu bar")); |
576 goto erret; | 576 goto erret; |
577 } | 577 } |
578 | 578 |
579 if (menu_is_separator(dname) && *next_name != NUL) | 579 if (menu_is_separator(dname) && *next_name != NUL) |
580 { | 580 { |
581 EMSG(_("E332: Separator cannot be part of a menu path")); | 581 emsg(_("E332: Separator cannot be part of a menu path")); |
582 goto erret; | 582 goto erret; |
583 } | 583 } |
584 | 584 |
585 /* Not already there, so lets add it */ | 585 /* Not already there, so lets add it */ |
586 menu = (vimmenu_T *)alloc_clear((unsigned)sizeof(vimmenu_T)); | 586 menu = (vimmenu_T *)alloc_clear((unsigned)sizeof(vimmenu_T)); |
865 { | 865 { |
866 if (*p != NUL) | 866 if (*p != NUL) |
867 { | 867 { |
868 if (menu->children == NULL) | 868 if (menu->children == NULL) |
869 { | 869 { |
870 EMSG(_(e_notsubmenu)); | 870 emsg(_(e_notsubmenu)); |
871 return FAIL; | 871 return FAIL; |
872 } | 872 } |
873 if (menu_nable_recurse(menu->children, p, modes, enable) | 873 if (menu_nable_recurse(menu->children, p, modes, enable) |
874 == FAIL) | 874 == FAIL) |
875 return FAIL; | 875 return FAIL; |
890 } | 890 } |
891 menu = menu->next; | 891 menu = menu->next; |
892 } | 892 } |
893 if (*name != NUL && *name != '*' && menu == NULL) | 893 if (*name != NUL && *name != '*' && menu == NULL) |
894 { | 894 { |
895 EMSG2(_(e_nomenu), name); | 895 semsg(_(e_nomenu), name); |
896 return FAIL; | 896 return FAIL; |
897 } | 897 } |
898 | 898 |
899 #ifdef FEAT_GUI | 899 #ifdef FEAT_GUI |
900 /* Want to update menus now even if mode not changed */ | 900 /* Want to update menus now even if mode not changed */ |
931 if (*name == NUL || menu_name_equal(name, menu)) | 931 if (*name == NUL || menu_name_equal(name, menu)) |
932 { | 932 { |
933 if (*p != NUL && menu->children == NULL) | 933 if (*p != NUL && menu->children == NULL) |
934 { | 934 { |
935 if (!silent) | 935 if (!silent) |
936 EMSG(_(e_notsubmenu)); | 936 emsg(_(e_notsubmenu)); |
937 return FAIL; | 937 return FAIL; |
938 } | 938 } |
939 if ((menu->modes & modes) != 0x0) | 939 if ((menu->modes & modes) != 0x0) |
940 { | 940 { |
941 #if defined(FEAT_GUI_W32) & defined(FEAT_TEAROFF) | 941 #if defined(FEAT_GUI_W32) & defined(FEAT_TEAROFF) |
953 return FAIL; | 953 return FAIL; |
954 } | 954 } |
955 else if (*name != NUL) | 955 else if (*name != NUL) |
956 { | 956 { |
957 if (!silent) | 957 if (!silent) |
958 EMSG(_(e_menuothermode)); | 958 emsg(_(e_menuothermode)); |
959 return FAIL; | 959 return FAIL; |
960 } | 960 } |
961 | 961 |
962 /* | 962 /* |
963 * When name is empty, we are removing all menu items for the given | 963 * When name is empty, we are removing all menu items for the given |
983 if (*name != NUL) | 983 if (*name != NUL) |
984 { | 984 { |
985 if (menu == NULL) | 985 if (menu == NULL) |
986 { | 986 { |
987 if (!silent) | 987 if (!silent) |
988 EMSG2(_(e_nomenu), name); | 988 semsg(_(e_nomenu), name); |
989 return FAIL; | 989 return FAIL; |
990 } | 990 } |
991 | 991 |
992 | 992 |
993 /* Recalculate modes for menu based on the new updated children */ | 993 /* Recalculate modes for menu based on the new updated children */ |
1121 if (menu_name_equal(name, menu)) | 1121 if (menu_name_equal(name, menu)) |
1122 { | 1122 { |
1123 /* Found menu */ | 1123 /* Found menu */ |
1124 if (*p != NUL && menu->children == NULL) | 1124 if (*p != NUL && menu->children == NULL) |
1125 { | 1125 { |
1126 EMSG(_(e_notsubmenu)); | 1126 emsg(_(e_notsubmenu)); |
1127 vim_free(path_name); | 1127 vim_free(path_name); |
1128 return FAIL; | 1128 return FAIL; |
1129 } | 1129 } |
1130 else if ((menu->modes & modes) == 0x0) | 1130 else if ((menu->modes & modes) == 0x0) |
1131 { | 1131 { |
1132 EMSG(_(e_menuothermode)); | 1132 emsg(_(e_menuothermode)); |
1133 vim_free(path_name); | 1133 vim_free(path_name); |
1134 return FAIL; | 1134 return FAIL; |
1135 } | 1135 } |
1136 break; | 1136 break; |
1137 } | 1137 } |
1138 menu = menu->next; | 1138 menu = menu->next; |
1139 } | 1139 } |
1140 if (menu == NULL) | 1140 if (menu == NULL) |
1141 { | 1141 { |
1142 EMSG2(_(e_nomenu), name); | 1142 semsg(_(e_nomenu), name); |
1143 vim_free(path_name); | 1143 vim_free(path_name); |
1144 return FAIL; | 1144 return FAIL; |
1145 } | 1145 } |
1146 name = p; | 1146 name = p; |
1147 parent = menu; | 1147 parent = menu; |
2398 break; | 2398 break; |
2399 // case MENU_INDEX_TIP: cannot happen | 2399 // case MENU_INDEX_TIP: cannot happen |
2400 default: | 2400 default: |
2401 mode = (char_u *)"Normal"; | 2401 mode = (char_u *)"Normal"; |
2402 } | 2402 } |
2403 EMSG2(_("E335: Menu not defined for %s mode"), mode); | 2403 semsg(_("E335: Menu not defined for %s mode"), mode); |
2404 } | 2404 } |
2405 } | 2405 } |
2406 | 2406 |
2407 /* | 2407 /* |
2408 * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and | 2408 * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and |
2428 case 's': mode_idx = MENU_INDEX_SELECT; break; | 2428 case 's': mode_idx = MENU_INDEX_SELECT; break; |
2429 case 'o': mode_idx = MENU_INDEX_OP_PENDING; break; | 2429 case 'o': mode_idx = MENU_INDEX_OP_PENDING; break; |
2430 case 't': mode_idx = MENU_INDEX_TERMINAL; break; | 2430 case 't': mode_idx = MENU_INDEX_TERMINAL; break; |
2431 case 'i': mode_idx = MENU_INDEX_INSERT; break; | 2431 case 'i': mode_idx = MENU_INDEX_INSERT; break; |
2432 case 'c': mode_idx = MENU_INDEX_CMDLINE; break; | 2432 case 'c': mode_idx = MENU_INDEX_CMDLINE; break; |
2433 default: EMSG2(_(e_invarg2), arg); | 2433 default: semsg(_(e_invarg2), arg); |
2434 return; | 2434 return; |
2435 } | 2435 } |
2436 arg = skipwhite(arg + 2); | 2436 arg = skipwhite(arg + 2); |
2437 } | 2437 } |
2438 | 2438 |
2451 { | 2451 { |
2452 if (menu_name_equal(name, menu)) | 2452 if (menu_name_equal(name, menu)) |
2453 { | 2453 { |
2454 if (*p == NUL && menu->children != NULL) | 2454 if (*p == NUL && menu->children != NULL) |
2455 { | 2455 { |
2456 EMSG(_("E333: Menu path must lead to a menu item")); | 2456 emsg(_("E333: Menu path must lead to a menu item")); |
2457 gave_emsg = TRUE; | 2457 gave_emsg = TRUE; |
2458 menu = NULL; | 2458 menu = NULL; |
2459 } | 2459 } |
2460 else if (*p != NUL && menu->children == NULL) | 2460 else if (*p != NUL && menu->children == NULL) |
2461 { | 2461 { |
2462 EMSG(_(e_notsubmenu)); | 2462 emsg(_(e_notsubmenu)); |
2463 menu = NULL; | 2463 menu = NULL; |
2464 } | 2464 } |
2465 break; | 2465 break; |
2466 } | 2466 } |
2467 menu = menu->next; | 2467 menu = menu->next; |
2473 } | 2473 } |
2474 vim_free(saved_name); | 2474 vim_free(saved_name); |
2475 if (menu == NULL) | 2475 if (menu == NULL) |
2476 { | 2476 { |
2477 if (!gave_emsg) | 2477 if (!gave_emsg) |
2478 EMSG2(_("E334: Menu not found: %s"), arg); | 2478 semsg(_("E334: Menu not found: %s"), arg); |
2479 return; | 2479 return; |
2480 } | 2480 } |
2481 | 2481 |
2482 // Found the menu, so execute. | 2482 // Found the menu, so execute. |
2483 execute_menu(eap, menu, mode_idx); | 2483 execute_menu(eap, menu, mode_idx); |
2565 { | 2565 { |
2566 if (menu->children == NULL) | 2566 if (menu->children == NULL) |
2567 { | 2567 { |
2568 /* found a menu item instead of a sub-menu */ | 2568 /* found a menu item instead of a sub-menu */ |
2569 if (*p == NUL) | 2569 if (*p == NUL) |
2570 EMSG(_("E336: Menu path must lead to a sub-menu")); | 2570 emsg(_("E336: Menu path must lead to a sub-menu")); |
2571 else | 2571 else |
2572 EMSG(_(e_notsubmenu)); | 2572 emsg(_(e_notsubmenu)); |
2573 menu = NULL; | 2573 menu = NULL; |
2574 goto theend; | 2574 goto theend; |
2575 } | 2575 } |
2576 if (*p == NUL) /* found a full match */ | 2576 if (*p == NUL) /* found a full match */ |
2577 goto theend; | 2577 goto theend; |
2586 menu = menu->children; | 2586 menu = menu->children; |
2587 name = p; | 2587 name = p; |
2588 } | 2588 } |
2589 | 2589 |
2590 if (menu == NULL) | 2590 if (menu == NULL) |
2591 EMSG(_("E337: Menu not found - check menu names")); | 2591 emsg(_("E337: Menu not found - check menu names")); |
2592 theend: | 2592 theend: |
2593 vim_free(saved_name); | 2593 vim_free(saved_name); |
2594 return menu; | 2594 return menu; |
2595 } | 2595 } |
2596 #endif | 2596 #endif |
2652 arg = menu_skip_part(arg); | 2652 arg = menu_skip_part(arg); |
2653 to = skipwhite(arg); | 2653 to = skipwhite(arg); |
2654 *arg = NUL; | 2654 *arg = NUL; |
2655 arg = menu_skip_part(to); | 2655 arg = menu_skip_part(to); |
2656 if (arg == to) | 2656 if (arg == to) |
2657 EMSG(_(e_invarg)); | 2657 emsg(_(e_invarg)); |
2658 else | 2658 else |
2659 { | 2659 { |
2660 if (ga_grow(&menutrans_ga, 1) == OK) | 2660 if (ga_grow(&menutrans_ga, 1) == OK) |
2661 { | 2661 { |
2662 tp = (menutrans_T *)menutrans_ga.ga_data; | 2662 tp = (menutrans_T *)menutrans_ga.ga_data; |