patch 9.0.1991: no cmdline completion for setting the font
Problem: no cmdline completion for setting the font
Solution: enable it on Win32 and GTK builds
Add guifont cmdline completion (for Windows and GTK)
For Windows, auto-complete will only suggest monospace fonts as that's
the only types allowed. Will also suggest font options after the colon,
including suggesting the current font size for convenience, and misc
charset and quality options like `cANSI` and `qCLEARTYPE`.
For GTK, auto-complete will suggest only monospace fonts for `guifont`
but will include all fonts for `guifontwide`. The completion code
doesn't currently suggest the current font size, as the GTK guifont
format does not have a clear delimiter (':' for other platforms).
closes: #13264
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim
index acc72f8..e7f7c6d 100644
--- a/src/testdir/test_gui.vim
+++ b/src/testdir/test_gui.vim
@@ -580,6 +580,56 @@
endif
endfunc
+func Test_expand_guifont()
+ if has('gui_win32')
+ let guifont_saved = &guifont
+ let guifontwide_saved = &guifontwide
+
+ " Test recalling existing option, and suggesting current font size
+ set guifont=Courier\ New:h11:cANSI
+ call assert_equal('Courier\ New:h11:cANSI', getcompletion('set guifont=', 'cmdline')[0])
+ call assert_equal('h11', getcompletion('set guifont=Lucida\ Console:', 'cmdline')[0])
+
+ " Test auto-completion working for font names
+ call assert_equal(['Courier\ New'], getcompletion('set guifont=Couri*ew$', 'cmdline'))
+ call assert_equal(['Courier\ New'], getcompletion('set guifontwide=Couri*ew$', 'cmdline'))
+
+ " Make sure non-monospace fonts are filtered out
+ call assert_equal([], getcompletion('set guifont=Arial', 'cmdline'))
+ call assert_equal([], getcompletion('set guifontwide=Arial', 'cmdline'))
+
+ " Test auto-completion working for font options
+ call assert_notequal(-1, index(getcompletion('set guifont=Courier\ New:', 'cmdline'), 'b'))
+ call assert_equal(['cDEFAULT'], getcompletion('set guifont=Courier\ New:cD*T', 'cmdline'))
+ call assert_equal(['qCLEARTYPE'], getcompletion('set guifont=Courier\ New:qC*TYPE', 'cmdline'))
+
+ let &guifontwide = guifontwide_saved
+ let &guifont = guifont_saved
+ elseif has('gui_gtk')
+ let guifont_saved = &guifont
+ let guifontwide_saved = &guifontwide
+
+ " Test recalling default and existing option
+ set guifont=
+ call assert_equal('Monospace\ 10', getcompletion('set guifont=', 'cmdline')[0])
+ set guifont=Monospace\ 9
+ call assert_equal('Monospace\ 9', getcompletion('set guifont=', 'cmdline')[0])
+
+ " Test auto-completion working for font names
+ call assert_equal(['Monospace'], getcompletion('set guifont=Mono*pace$', 'cmdline'))
+ call assert_equal(['Monospace'], getcompletion('set guifontwide=Mono*pace$', 'cmdline'))
+
+ " Make sure non-monospace fonts are filtered out only in '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
+ else
+ call assert_equal([], getcompletion('set guifont=', 'cmdline'))
+ endif
+endfunc
+
func Test_set_guiligatures()
CheckX11BasedGui