macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.53k stars 685 forks source link

Support fixing "menu not found" error when started through mvim with default menus disabled. #1231

Closed jpetrie closed 2 years ago

jpetrie commented 2 years ago

While investigating issue #1230, I added let did_install_default_menus = 1 to my .vimrc. This disables the generation of Vim's default menus, per gui.txt. It also causes an error to be generated when using mvim to start MacVim from the Terminal:

Error detected while processing /Users/Josh/Documents/Dotfiles/vim/vimrc[6]../Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim[25]../Applications/MacVim.app/Contents/Resources/vim/runtime/filetype.vim[2366]../Applications/MacVim.app/Contents/Resources/vim/runtime/menu.vim:
line 1306:
E334: Menu not found: File.New\ Window

When did_install_default_menus is used this way, menu.vim's calls to macmenu fail to find any menus, since they were never generated. This change introduces a similar global variable, did_install_default_mac_menus that can be set similarly to skip the macmenu calls and avoid the errors. This more easily supports the use-case where somebody wants to completely redefine the menu structure, which isn't common, but is what led me down this rabbit hole in the first place.

I considered a few other approaches. They all have pros and cons, this seemed like the simplest overall:

I explicitly did not update delmenu.vim to reset the new variable. It would be more correct to do so, but would create an upstream merge conflict for no appreciable benefit: if menu.vim is resourced at runtime, macmenu has no effect anyway. That could be fixed, but that's a much bigger change.

This is a fairly niche change, so I'm entirely convinced it's worth pulling in, but I did the work so I figured I'd see what folks thought.

ychin commented 2 years ago

Hi @jpetrie sorry I did not get around to reviewing this PR. Can you reopen it? (Edit: i just reopened it)

I think we have a simpler change that we could make though: just move all the macm (macmenu) calls to be within the did_install_default_menus block.

This way we don't have to move the setting of did_install_default_menus till later. It still makes merging from upstream slightly harder since the macmenu call will be somewhere in the middle of the file instead of all the way in the end but I think it's unlikely it's going to cause issues. menu.vim isn't a frequently updated file anyway, and a giant chunk of code addition like this is easy to merge and resolve.

We would also not have to define a new variable which seems much cleaner to me.

ychin commented 2 years ago

Ok I just did the change that I mentioned. Should be fixed now.