From fcd5797563e5ff4c30aeaa41a6a2173810bc4602 Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Sat, 26 Sep 2020 02:29:34 -0700 Subject: [PATCH] Bundle vimtutor with MacVim and provide Help menu item to open it MacVim has previously not included vimtutor, meaning the user had to obtain it elsewhere. Change the build scripts to copy it over to the app bundle so that it's under MacVim.app/Contents/bin just like `mvim` etc. Also, provide a Help menu item to open vimtutor. The menu action will also make sure to override the PATH first to prevent accidentally opening other installed MacVim/Vim versions since vimtutor works by searching PATH instead of explicitly passing in the Vim executable path. Also, make all Help menu items work in terminal mode as well as an easy fix. --- runtime/doc/usr_01.txt | 3 +++ runtime/menu.vim | 21 +++++++++++++++++++ src/MacVim/MMAppController.m | 2 +- src/MacVim/MacVim.xcodeproj/project.pbxproj | 23 ++++++++++++++++++++- src/testdir/test_gui.vim | 1 + 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/runtime/doc/usr_01.txt b/runtime/doc/usr_01.txt index 23eb304c2e..5a2f55e166 100644 --- a/runtime/doc/usr_01.txt +++ b/runtime/doc/usr_01.txt @@ -118,6 +118,9 @@ On Unix, if Vim has been properly installed, you can start it from the shell: On MS-Windows you can find it in the Program/Vim menu. Or execute vimtutor.bat in the $VIMRUNTIME directory. +On MacVim, you can run `vimtutor` from the shell, or select "Vim Tutor" in the +Help menu. + This will make a copy of the tutor file, so that you can edit it without the risk of damaging the original. There are a few translated versions of the tutor. To find out if yours is diff --git a/runtime/menu.vim b/runtime/menu.vim index 8520c4f385..597183bfaf 100644 --- a/runtime/menu.vim +++ b/runtime/menu.vim @@ -99,9 +99,17 @@ endif " Help menu if has("gui_macvim") an 9999.1 &Help.MacVim\ Help :h gui_mac + tln 9999.1 &Help.MacVim\ Help :h gui_mac an 9999.2 Help.MacVim\ Website an 9999.3 &Help.-sep0- endif +if has("gui_macvim") + " Run vimtutor in GUI mode. Need to make sure to override the PATH so we use + " this app instead of accidentally opening another installed Vim/MacVim. + an 9999.5 &Help.Vim\ Tutor :silent !PATH="$VIM/../../bin":/usr/bin:/bin:/usr/sbin:/sbin $VIM/../../bin/vimtutor -g& + tln 9999.5 &Help.Vim\ Tutor :silent !PATH="$VIM/../../bin":/usr/bin:/bin:/usr/sbin:/sbin $VIM/../../bin/vimtutor -g& + an 9999.6 &Help.-sep-vim-tutor- +endif an 9999.10 &Help.&Overview :help an 9999.20 &Help.&User\ Manual :help usr_toc an 9999.30 &Help.&How-To\ Links :help how-to @@ -115,6 +123,19 @@ an 9999.75 &Help.-sep2- an 9999.80 &Help.&Version :version an 9999.90 &Help.&About :intro +tln 9999.10 &Help.&Overview :help +tln 9999.20 &Help.&User\ Manual :help usr_toc +tln 9999.30 &Help.&How-To\ Links :help how-to +tln 9999.40 &Help.&Find\.\.\. :call Helpfind() +tln 9999.45 &Help.-sep1- +tln 9999.50 &Help.&Credits :help credits +tln 9999.60 &Help.Co&pying :help copying +tln 9999.70 &Help.&Sponsor/Register :help sponsor +tln 9999.70 &Help.O&rphans :help kcc +tln 9999.75 &Help.-sep2- +tln 9999.80 &Help.&Version :version +tln 9999.90 &Help.&About :intro + fun! s:Helpfind() if !exists("g:menutrans_help_dialog") let g:menutrans_help_dialog = "Enter a command or word to find help on:\n\nPrepend i_ for Input mode commands (e.g.: i_CTRL-X)\nPrepend c_ for command-line editing commands (e.g.: c_)\nPrepend ' for an option name (e.g.: 'shiftwidth')" diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 1b17048b53..f16f63d96e 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -906,7 +906,7 @@ - (void)refreshMainMenu // of Screen" to the Window menu, and on repeated calls it will keep adding // the same item over and over again, without resolving for duplicates. Using // copies help keep the source menu clean. - NSMenu *mainMenu = [currentMainMenu copy]; + NSMenu *mainMenu = [[currentMainMenu copy] autorelease]; // If the new menu has a "Recent Files" dummy item, then swap the real item // for the dummy. We are forced to do this since Cocoa initializes the diff --git a/src/MacVim/MacVim.xcodeproj/project.pbxproj b/src/MacVim/MacVim.xcodeproj/project.pbxproj index 4725bb7938..472d156040 100644 --- a/src/MacVim/MacVim.xcodeproj/project.pbxproj +++ b/src/MacVim/MacVim.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -840,6 +840,7 @@ 1D1C31F00EFFBFD6003FE9A5 /* Make Document Icons */, 528DA6671426D456003380F1 /* Copy Scripts */, 52283AB71EBA200C00A6F6B9 /* Copy mvim scripts */, + 90C052E1251E889500E2D81E /* Copy vimtutor */, ); buildRules = ( ); @@ -1003,6 +1004,26 @@ shellScript = "# Copy all the locale translation files from the po folder to\n# runtime/lang//LC_MESSAGES/vim.mo. Need to do this because unlike normal\n# Vim, MacVim is distributed as a standalone app package and therefore we don't\n# want to install these files to a global location (e.g.\n# /usr/local/share/locale/). This is similar to how Windows installation\n# (po/Make_mvc.mak) works.\ncd \"${SRCROOT}\"/..\nmake macvim-install-languages DEST_LANG=\"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/vim/runtime/lang\"\n"; showEnvVarsInLog = 0; }; + 90C052E1251E889500E2D81E /* Copy vimtutor */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Copy vimtutor"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "BINPATH=$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/bin\nmkdir -p \"${BINPATH}\"\ncp -a \"${SRCROOT}/../vimtutor\" \"${BINPATH}/vimtutor\"\ncp -a \"${SRCROOT}/../gvimtutor\" \"${BINPATH}/gvimtutor\"\nchmod 755 \"${BINPATH}/vimtutor\"\nchmod 755 \"${BINPATH}/gvimtutor\"\ncd \"${BINPATH}\"\nln -fs gvimtutor mvimtutor \n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim index 0405d5cd8f..55f57ceb7b 100644 --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -744,6 +744,7 @@ func Test_menu() " Check deleting menu doesn't cause trouble. aunmenu Help + tlunmenu Help call assert_fails('menu Help', 'E329:') endfunc