diff options
Diffstat (limited to 'src/nvim/menu.c')
-rw-r--r-- | src/nvim/menu.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 57116170aa..2a18b08d8d 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -5,29 +5,41 @@ // GUI/Motif support by Robert Webb #include <assert.h> -#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> #include <string.h> #include "nvim/ascii.h" #include "nvim/autocmd.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/garray.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/highlight_defs.h" #include "nvim/keycodes.h" +#include "nvim/macros.h" +#include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/menu.h" +#include "nvim/menu_defs.h" #include "nvim/message.h" +#include "nvim/option_defs.h" #include "nvim/popupmenu.h" -#include "nvim/screen.h" +#include "nvim/pos.h" #include "nvim/state.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/ui.h" +#include "nvim/undo_defs.h" #include "nvim/vim.h" -#include "nvim/window.h" #define MENUDEPTH 10 // maximum depth of menus @@ -45,7 +57,7 @@ static char e_nomenu[] = N_("E329: No menu \"%s\""); static bool menu_is_winbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return (STRNCMP(name, "WinBar", 6) == 0); + return (strncmp(name, "WinBar", 6) == 0); } static vimmenu_T **get_root_menu(const char *const name) @@ -77,17 +89,17 @@ void ex_menu(exarg_T *eap) arg = eap->arg; for (;;) { - if (STRNCMP(arg, "<script>", 8) == 0) { + if (strncmp(arg, "<script>", 8) == 0) { noremap = REMAP_SCRIPT; arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<silent>", 8) == 0) { + if (strncmp(arg, "<silent>", 8) == 0) { silent = true; arg = skipwhite(arg + 8); continue; } - if (STRNCMP(arg, "<special>", 9) == 0) { + if (strncmp(arg, "<special>", 9) == 0) { // Ignore obsolete "<special>" modifier. arg = skipwhite(arg + 9); continue; @@ -97,7 +109,7 @@ void ex_menu(exarg_T *eap) // Locate an optional "icon=filename" argument // TODO(nvim): Currently this is only parsed. Should expose it to UIs. - if (STRNCMP(arg, "icon=", 5) == 0) { + if (strncmp(arg, "icon=", 5) == 0) { arg += 5; while (*arg != NUL && *arg != ' ') { if (*arg == '\\') { @@ -140,10 +152,10 @@ void ex_menu(exarg_T *eap) pri_tab[MENUDEPTH] = -1; // mark end of the table // Check for "disable" or "enable" argument. - if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { + if (strncmp(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { enable = kTrue; arg = skipwhite(arg + 6); - } else if (STRNCMP(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { + } else if (strncmp(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { enable = kFalse; arg = skipwhite(arg + 7); } @@ -905,10 +917,10 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for } if (!ascii_iswhite(*p)) { - if (STRNCMP(arg, "enable", 6) == 0 + if (strncmp(arg, "enable", 6) == 0 && (arg[6] == NUL || ascii_iswhite(arg[6]))) { p = arg + 6; - } else if (STRNCMP(arg, "disable", 7) == 0 + } else if (strncmp(arg, "disable", 7) == 0 && (arg[7] == NUL || ascii_iswhite(arg[7]))) { p = arg + 7; } else { @@ -949,7 +961,7 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for if (after_dot > arg) { size_t path_len = (size_t)(after_dot - arg); path_name = xmalloc(path_len); - STRLCPY(path_name, arg, path_len); + xstrlcpy(path_name, arg, path_len); } name = path_name; while (name != NULL && *name) { @@ -1064,9 +1076,9 @@ char *get_menu_names(expand_T *xp, int idx) if (menu->modes & expand_modes) { if (menu->children != NULL) { if (should_advance) { - STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN); + xstrlcpy(tbuffer, menu->en_dname, TBUFFER_LEN); } else { - STRLCPY(tbuffer, menu->dname, TBUFFER_LEN); + xstrlcpy(tbuffer, menu->dname, TBUFFER_LEN); if (menu->en_dname == NULL) { should_advance = true; } @@ -1327,7 +1339,7 @@ static char *menu_text(const char *str, int *mnemonic, char **actext) break; } if (mnemonic != NULL && p[1] != '&') { - *mnemonic = (char_u)p[1]; + *mnemonic = (uint8_t)p[1]; } STRMOVE(p, p + 1); p = p + 1; @@ -1350,14 +1362,14 @@ bool menu_is_menubar(const char *const name) bool menu_is_popup(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return STRNCMP(name, "PopUp", 5) == 0; + return strncmp(name, "PopUp", 5) == 0; } // Return true if "name" is a toolbar menu name. bool menu_is_toolbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return STRNCMP(name, "ToolBar", 7) == 0; + return strncmp(name, "ToolBar", 7) == 0; } /// Return true if the name is a menu separator identifier: Starts and ends @@ -1432,15 +1444,17 @@ void show_popupmenu(void) vimmenu_T *menu; for (menu = root_menu; menu != NULL; menu = menu->next) { - if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) { + if (strncmp("PopUp", menu->name, 5) == 0 && strncmp(menu->name + 5, mode, mode_len) == 0) { break; } } // Only show a popup when it is defined and has entries - if (menu != NULL && menu->children != NULL) { - pum_show_popupmenu(menu); + if (menu == NULL || menu->children == NULL) { + return; } + + pum_show_popupmenu(menu); } /// Execute "menu". Use by ":emenu" and the window toolbar. @@ -1520,7 +1534,7 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx) ex_normal_busy++; if (save_current_state(&save_state)) { - exec_normal_cmd((char_u *)menu->strings[idx], menu->noremap[idx], + exec_normal_cmd(menu->strings[idx], menu->noremap[idx], menu->silent[idx]); } restore_current_state(&save_state); @@ -1716,7 +1730,7 @@ void ex_menutranslate(exarg_T *eap) } // ":menutrans clear": clear all translations. - if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { + if (strncmp(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS); // Delete all "menutrans_" global variables. |