@@ -2376,9 +2376,24 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
23762376 if (idx == MENU_INDEX_INVALID || eap == NULL )
23772377 idx = MENU_INDEX_NORMAL ;
23782378
2379- if (menu -> strings [idx ] != NULL && menu -> strings [idx ][0 ] != NUL
2380- && (menu -> modes & (1 << idx )))
2379+ if (menu -> strings [idx ] != NULL && (menu -> modes & (1 << idx )))
23812380 {
2381+ #ifdef FEAT_GUI_MACVIM
2382+ // When a menu is bound to <Nop>, we let :emenu fall through to execute
2383+ // the associated macaction (if one exists) instead. Otherwise, we
2384+ // simply execute the associated Vim command. Note that if you
2385+ // physically press the menu item (or the associated shortcut key), the
2386+ // macaction is always invoked even if the menu isn't bound to <Nop>.
2387+ if (menu -> mac_action != NULL && menu -> strings [idx ] != NULL && menu -> strings [idx ][0 ] == NUL )
2388+ {
2389+ // Count on the fact taht ex_macaction() only looks at eap->arg.
2390+ old_arg = eap -> arg ;
2391+ eap -> arg = menu -> mac_action ;
2392+ ex_macaction (eap );
2393+ eap -> arg = old_arg ;
2394+ }
2395+ #endif // FEAT_GUI_MACVIM
2396+
23822397 // When executing a script or function execute the commands right now.
23832398 // Also for the window toolbar.
23842399 // Otherwise put them in the typeahead buffer.
@@ -2425,20 +2440,6 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
24252440 default :
24262441 mode = (char_u * )"Normal" ;
24272442 }
2428- #ifdef FEAT_GUI_MACVIM
2429- if (menu -> mac_action != NULL && menu -> strings [idx ][0 ] == NUL )
2430- {
2431- // This allows us to bind a menu to an action without mapping to
2432- // anything so that pressing the menu's key equivalent and typing
2433- // ":emenu ..." does the same thing. (HACK: We count on the fact
2434- // that ex_macaction() only looks at eap->arg.)
2435- old_arg = eap -> arg ;
2436- eap -> arg = menu -> mac_action ;
2437- ex_macaction (eap );
2438- eap -> arg = old_arg ;
2439- }
2440- else
2441- #endif // FEAT_GUI_MACVIM
24422443 semsg (_ (e_menu_not_defined_for_str_mode ), mode );
24432444 }
24442445}
0 commit comments