diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index ebf75f2d4f..0fdf8d5562 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3873,7 +3873,9 @@ A jump table for the options with a short description can be found at |Q_op|. In non-native fullscreen mode, MacVim can be configured to either show all the content filling up the whole screen, or only use part of the screen to show the content, centered. This option controls the size - of the Vim control as well as the color of the unused screen area. + of the Vim control as well as the color of the unused screen area. It + is a comma-separated list of values as follows: + value effect ~ maxvert When entering fullscreen, 'lines' is set to the maximum number of lines fitting on the screen in fullscreen mode. If unset, diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index b0cc5b0cd6..ea30b75d9f 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -30,8 +30,10 @@ // Enabled when files passed on command line should not be added to MRU. static BOOL MMNoMRU = NO; -static NSString *MMDefaultFontName = @"Menlo Regular"; +static NSString *MMDefaultFontName = @"Menlo-Regular"; static int MMDefaultFontSize = 11; +static char *MMDefaultFontStr = "Menlo-Regular:h11"; +static char *MMDefaultFontSizeStr = "h11"; static int MMMinFontSize = 6; static int MMMaxFontSize = 100; @@ -1153,6 +1155,48 @@ return NOFONT; } +/** + * Cmdline expansion for setting 'guifont' / 'guifontwide'. Will enumerate + * through all fonts for completion. When setting 'guifont' it will only show + * monospace fonts as it's unlikely other fonts would be useful. + */ + void +gui_mch_expand_font(optexpand_T *args, void *param, int (*add_match)(char_u *val)) +{ + expand_T *xp = args->oe_xp; + int wide = *(int *)param; + + if (args->oe_include_orig_val && *args->oe_opt_value == NUL && !wide) + { + // If guifont is empty, and we want to fill in the orig value, suggest + // the default so the user can modify it. + if (add_match((char_u *)MMDefaultFontStr) != OK) + return; + } + + if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') + { + // Fill in the existing font size to help switching only font family + char_u *colon = vim_strchr(p_guifont, ':'); + if (colon != NULL) + add_match(colon + 1); + else + add_match((char_u*)MMDefaultFontSizeStr); + return; + } + + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + NSArray *availableFonts; + if (wide) + availableFonts = [fontManager availableFonts]; + else + availableFonts = [fontManager availableFontNamesWithTraits:NSFixedPitchFontMask]; + for (NSString *font in availableFonts) { + if (add_match((char_u*)[font UTF8String]) != OK) + return; + } +} + // -- Scrollbars ------------------------------------------------------------ // NOTE: Even though scrollbar identifiers are 'long' we tacitly assume that diff --git a/src/optiondefs.h b/src/optiondefs.h index 2c08ec867f..d27d0c381d 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -1175,9 +1175,9 @@ static struct vimoption options[] = {(char_u *)NULL, (char_u *)0L} #endif SCTX_INIT}, - {"fuoptions", "fuopt", P_STRING|P_COMMA|P_NODUP|P_VI_DEF, + {"fuoptions", "fuopt", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_COLON, #ifdef FEAT_FULLSCREEN - (char_u *)&p_fuoptions, PV_NONE, did_set_fuoptions, NULL, + (char_u *)&p_fuoptions, PV_NONE, did_set_fuoptions, expand_set_fuoptions, {(char_u *)"maxvert,maxhorz", (char_u *)0L} #else (char_u *)NULL, PV_NONE, NULL, NULL, diff --git a/src/optionstr.c b/src/optionstr.c index 992734c53a..ca3f7aa633 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -849,7 +849,7 @@ expand_set_opt_generic( return ret; } -# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) +# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM) static garray_T *expand_cb_ga; static optexpand_T *expand_cb_args; @@ -2351,7 +2351,7 @@ expand_set_guifont(optexpand_T *args, int *numMatches, char_u ***matches) if (!gui.in_use) return FAIL; -# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) +# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM) char_u **varp = (char_u **)args->oe_varp; int wide = (varp == &p_guifontwide); @@ -4259,6 +4259,45 @@ did_set_fuoptions(optset_T *args UNUSED) return e_invalid_argument; return NULL; } + + static char_u * +get_fuopt_background_value(expand_T *xp, int idx) +{ + // "background:" supports '#' for expicit RGB color, or highlight names. + if (idx == 0) + return (char_u *)"#"; + return get_highlight_name(xp, idx - 1); +} + + int +expand_set_fuoptions(optexpand_T *args, int *numMatches, char_u ***matches) +{ + expand_T *xp = args->oe_xp; + + if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') + { + // Within "background:", we have a subgroup of possible options. + int bg_len = STRLEN("background:"); + if (xp->xp_pattern - args->oe_set_arg >= bg_len && + STRNCMP(xp->xp_pattern - bg_len, "background:", bg_len) == 0) + { + return expand_set_opt_generic( + args, + get_fuopt_background_value, + numMatches, + matches); + } + return FAIL; + } + + static char *(p_fuopt_values[]) = {"maxvert", "maxhorz", "background:", NULL}; + return expand_set_opt_string( + args, + p_fuopt_values, + ARRAY_LENGTH(p_fuopt_values) - 1, + numMatches, + matches); +} #endif #pragma endregion MacVim specific options diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 8e47a4db32..869727d044 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -40,6 +40,7 @@ GuiFont gui_mch_get_font(char_u *name, int giveErrorIfMissing); char_u *gui_mch_get_fontname(GuiFont font, char_u *name); int gui_mch_init_font(char_u *font_name, int fontset); void gui_mch_set_font(GuiFont font); +void gui_mch_expand_font(optexpand_T *args, void *param, int (*add_match)(char_u *val)); int gui_mch_adjust_charheight(void); int gui_mch_adjust_charwidth(void); void gui_mch_beep(void); diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro index 8a74eb27c0..e6eeb0ba73 100644 --- a/src/proto/optionstr.pro +++ b/src/proto/optionstr.pro @@ -156,6 +156,7 @@ int expand_set_foldclose(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_foldmethod(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_foldopen(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_formatoptions(optexpand_T *args, int *numMatches, char_u ***matches); +int expand_set_fuoptions(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_guifont(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_guioptions(optexpand_T *args, int *numMatches, char_u ***matches); int expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches); diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim index cbe3e54b46..a8f44f75ac 100644 --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -623,6 +623,28 @@ func Test_expand_guifont() call assert_equal([], getcompletion('set guifont=Sans$', 'cmdline')) call assert_equal(['Sans'], getcompletion('set guifontwide=Sans$', 'cmdline')) + let &guifontwide = guifontwide_saved + let &guifont = guifont_saved + elseif has('gui_macvim') + let guifont_saved = &guifont + let guifontwide_saved = &guifontwide + + " Test recalling default and existing option, and suggesting current font + " size + set guifont= + call assert_equal('Menlo-Regular:h11', getcompletion('set guifont=', 'cmdline')[0]) + set guifont=Monaco:h12 + call assert_equal('Monaco:h12', getcompletion('set guifont=', 'cmdline')[0]) + call assert_equal('h12', getcompletion('set guifont=Menlo\ Italic:', 'cmdline')[0]) + + " Test auto-completion working for font names + call assert_equal(['Menlo-Regular'], getcompletion('set guifont=Menl*lar$', 'cmdline')) + call assert_equal(['Menlo-Regular'], getcompletion('set guifontwide=Menl*lar$', 'cmdline')) + + " Make sure non-monospace fonts are filtered out only in 'guifont' + call assert_equal([], getcompletion('set guifont=Hel*tica$', 'cmdline')) + call assert_equal(['Helvetica'], getcompletion('set guifontwide=Hel*tica$', 'cmdline')) + let &guifontwide = guifontwide_saved let &guifont = guifont_saved else diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim index 9e21625b9b..e062985d9a 100644 --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -568,6 +568,13 @@ func Test_set_completion_string_values() \ '') call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline')) + " + " MacVim options + " + call assert_equal(getcompletion('set fuoptions+=', 'cmdline')[0], 'maxvert') + call assert_equal(getcompletion('set fuoptions+=maxvert,background:', 'cmdline')[0], '#') + call assert_equal(getcompletion('set fuoptions+=maxvert,background:No*ext', 'cmdline')[0], 'NonText') + " " Test flag lists "