comparison src/menu.c @ 31728:238ca27dbfd2 v9.0.1196

patch 9.0.1196: code is indented more than necessary Commit: https://github.com/vim/vim/commit/e8575988969579f9e1439181ae338b2ff74054a8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Jan 14 12:32:28 2023 +0000 patch 9.0.1196: 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 #11813)
author Bram Moolenaar <Bram@vim.org>
date Sat, 14 Jan 2023 13:45:04 +0100
parents 082f526cfb96
children bea4ebf594c6
comparison
equal deleted inserted replaced
31727:2b50a7f0feec 31728:238ca27dbfd2
1761 char *mode_chars = menu_mode_chars[idx]; 1761 char *mode_chars = menu_mode_chars[idx];
1762 int mode_chars_len = (int)strlen(mode_chars); 1762 int mode_chars_len = (int)strlen(mode_chars);
1763 int i; 1763 int i;
1764 1764
1765 p = vim_strnsave(name, len + mode_chars_len); 1765 p = vim_strnsave(name, len + mode_chars_len);
1766 if (p != NULL) 1766 if (p == NULL)
1767 { 1767 return NULL;
1768 mch_memmove(p + 5 + mode_chars_len, p + 5, (size_t)(len - 4)); 1768
1769 for (i = 0; i < mode_chars_len; ++i) 1769 mch_memmove(p + 5 + mode_chars_len, p + 5, (size_t)(len - 4));
1770 p[5 + i] = menu_mode_chars[idx][i]; 1770 for (i = 0; i < mode_chars_len; ++i)
1771 } 1771 p[5 + i] = menu_mode_chars[idx][i];
1772 return p; 1772 return p;
1773 } 1773 }
1774 1774
1775 #if defined(FEAT_GUI) || defined(PROTO) 1775 #if defined(FEAT_GUI) || defined(PROTO)
1776 /* 1776 /*
2006 FOR_ALL_MENUS(menu) 2006 FOR_ALL_MENUS(menu)
2007 if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) 2007 if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0)
2008 break; 2008 break;
2009 2009
2010 // Only show a popup when it is defined and has entries 2010 // Only show a popup when it is defined and has entries
2011 if (menu != NULL && menu->children != NULL) 2011 if (menu == NULL || menu->children == NULL)
2012 { 2012 return;
2013
2013 # if defined(FEAT_GUI) 2014 # if defined(FEAT_GUI)
2014 if (gui.in_use) 2015 if (gui.in_use)
2015 { 2016 {
2016 // Update the menus now, in case the MenuPopup autocommand did 2017 // Update the menus now, in case the MenuPopup autocommand did
2017 // anything. 2018 // anything.
2018 gui_update_menus(0); 2019 gui_update_menus(0);
2019 gui_mch_show_popupmenu(menu); 2020 gui_mch_show_popupmenu(menu);
2020 } 2021 }
2021 # endif 2022 # endif
2022 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU) 2023 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
2023 else 2024 else
2024 # endif 2025 # endif
2025 # if defined(FEAT_TERM_POPUP_MENU) 2026 # if defined(FEAT_TERM_POPUP_MENU)
2026 pum_show_popupmenu(menu); 2027 pum_show_popupmenu(menu);
2027 # endif 2028 # endif
2028 }
2029 } 2029 }
2030 #endif 2030 #endif
2031 2031
2032 #if defined(FEAT_GUI) || defined(PROTO) 2032 #if defined(FEAT_GUI) || defined(PROTO)
2033 2033
2253 char_u *tbuf; 2253 char_u *tbuf;
2254 int t; 2254 int t;
2255 vimmenu_T menuarg; 2255 vimmenu_T menuarg;
2256 2256
2257 tbuf = alloc(5 + (unsigned int)STRLEN(tearpath)); 2257 tbuf = alloc(5 + (unsigned int)STRLEN(tearpath));
2258 if (tbuf != NULL) 2258 if (tbuf == NULL)
2259 { 2259 return;
2260 tbuf[0] = K_SPECIAL; 2260
2261 tbuf[1] = K_SECOND(K_TEAROFF); 2261 tbuf[0] = K_SPECIAL;
2262 tbuf[2] = K_THIRD(K_TEAROFF); 2262 tbuf[1] = K_SECOND(K_TEAROFF);
2263 STRCPY(tbuf + 3, tearpath); 2263 tbuf[2] = K_THIRD(K_TEAROFF);
2264 STRCAT(tbuf + 3, "\r"); 2264 STRCPY(tbuf + 3, tearpath);
2265 2265 STRCAT(tbuf + 3, "\r");
2266 STRCAT(tearpath, "."); 2266
2267 STRCAT(tearpath, TEAR_STRING); 2267 STRCAT(tearpath, ".");
2268 2268 STRCAT(tearpath, TEAR_STRING);
2269 // Priority of tear-off is always 1 2269
2270 t = pri_tab[pri_idx + 1]; 2270 // Priority of tear-off is always 1
2271 pri_tab[pri_idx + 1] = 1; 2271 t = pri_tab[pri_idx + 1];
2272 pri_tab[pri_idx + 1] = 1;
2272 2273
2273 #ifdef FEAT_TOOLBAR 2274 #ifdef FEAT_TOOLBAR
2274 menuarg.iconfile = NULL; 2275 menuarg.iconfile = NULL;
2275 menuarg.iconidx = -1; 2276 menuarg.iconidx = -1;
2276 menuarg.icon_builtin = FALSE; 2277 menuarg.icon_builtin = FALSE;
2277 #endif 2278 #endif
2278 menuarg.noremap[0] = REMAP_NONE; 2279 menuarg.noremap[0] = REMAP_NONE;
2279 menuarg.silent[0] = TRUE; 2280 menuarg.silent[0] = TRUE;
2280 2281
2281 menuarg.modes = MENU_ALL_MODES; 2282 menuarg.modes = MENU_ALL_MODES;
2282 add_menu_path(tearpath, &menuarg, pri_tab, tbuf, FALSE); 2283 add_menu_path(tearpath, &menuarg, pri_tab, tbuf, FALSE);
2283 2284
2284 menuarg.modes = MENU_TIP_MODE; 2285 menuarg.modes = MENU_TIP_MODE;
2285 add_menu_path(tearpath, &menuarg, pri_tab, 2286 add_menu_path(tearpath, &menuarg, pri_tab,
2286 (char_u *)_("Tear off this menu"), FALSE); 2287 (char_u *)_("Tear off this menu"), FALSE);
2287 2288
2288 pri_tab[pri_idx + 1] = t; 2289 pri_tab[pri_idx + 1] = t;
2289 vim_free(tbuf); 2290 vim_free(tbuf);
2290 }
2291 } 2291 }
2292 2292
2293 /* 2293 /*
2294 * Recursively destroy tearoff items 2294 * Recursively destroy tearoff items
2295 */ 2295 */
2787 // Now try again while ignoring '&' characters. 2787 // Now try again while ignoring '&' characters.
2788 i = name[len]; 2788 i = name[len];
2789 name[len] = NUL; 2789 name[len] = NUL;
2790 dname = menu_text(name, NULL, NULL); 2790 dname = menu_text(name, NULL, NULL);
2791 name[len] = i; 2791 name[len] = i;
2792 if (dname != NULL) 2792 if (dname == NULL)
2793 { 2793 return NULL;
2794 for (i = 0; i < menutrans_ga.ga_len; ++i) 2794
2795 if (STRICMP(dname, tp[i].from_noamp) == 0) 2795 for (i = 0; i < menutrans_ga.ga_len; ++i)
2796 { 2796 if (STRICMP(dname, tp[i].from_noamp) == 0)
2797 vim_free(dname); 2797 {
2798 return tp[i].to; 2798 vim_free(dname);
2799 } 2799 return tp[i].to;
2800 vim_free(dname); 2800 }
2801 } 2801 vim_free(dname);
2802 2802
2803 return NULL; 2803 return NULL;
2804 } 2804 }
2805 2805
2806 /* 2806 /*