Skip to content

Conversation

@ychin
Copy link
Contributor

@ychin ychin commented Oct 4, 2023

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).

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).
@ychin
Copy link
Contributor Author

ychin commented Oct 4, 2023

Windows:
guifont_autocomplete_1
guifont_autocomplete_2

@ychin
Copy link
Contributor Author

ychin commented Oct 4, 2023

GTK (note that the fonts I'm completing in guifontwide are not monospaced fonts):

image image

@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #13264 (4ef6cd4) into master (b74ebfc) will increase coverage by 3.82%.
The diff coverage is 71.29%.

@@            Coverage Diff             @@
##           master   #13264      +/-   ##
==========================================
+ Coverage   78.33%   82.15%   +3.82%     
==========================================
  Files         150      160      +10     
  Lines      153287   196256   +42969     
  Branches    39519    43974    +4455     
==========================================
+ Hits       120076   161234   +41158     
- Misses      20932    22137    +1205     
- Partials    12279    12885     +606     
Flag Coverage Δ
huge-clang-Array 82.79% <61.97%> (?)
linux 82.79% <61.97%> (?)
mingw-x64-HUGE 76.71% <1.28%> (-0.04%) ⬇️
mingw-x86-HUGE 77.25% <80.76%> (+<0.01%) ⬆️
windows 78.33% <80.76%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/os_mswin.c 51.89% <89.18%> (+1.47%) ⬆️
src/gui_gtk_x11.c 51.50% <45.83%> (ø)
src/optionstr.c 90.62% <70.21%> (+0.96%) ⬆️

... and 148 files with indirect coverage changes

@ychin
Copy link
Contributor Author

ychin commented Oct 4, 2023

Code coverage is complaining a lot of lines aren't testing. Most of them are due to guards around not being able to allocate memory. I'm following the pattern that I see in other areas in Vim's codebase and making sure to check against allocation results, but I don't know if there are good ways to test such situations.

@yegappan
Copy link
Member

yegappan commented Oct 4, 2023

Code coverage is complaining a lot of lines aren't testing. Most of them are due to guards around not being able to allocate memory. I'm following the pattern that I see in other areas in Vim's codebase and making sure to check against allocation results, but I don't know if there are good ways to test such situations.

You can use the test_alloc_fail() function to test for allocation failures. To use this function,
you need to add an ID in alloc_id_T and use the alloc_id() function for memory allocation.

@ychin
Copy link
Contributor Author

ychin commented Oct 4, 2023

You can use the test_alloc_fail() function to test for allocation failures. To use this function,
you need to add an ID in alloc_id_T and use the alloc_id() function for memory allocation.

Hmm that seems like a lot of work though. As in, the pattern that I see (and therefore follow) usually call vim_strsave / alloc or some other generic ways to get an allocated buffer and then NULL-check to protect against memory allocation issues. Only a few are tagged with an alloc ID.

@yegappan
Copy link
Member

yegappan commented Oct 4, 2023

You can use the test_alloc_fail() function to test for allocation failures. To use this function,
you need to add an ID in alloc_id_T and use the alloc_id() function for memory allocation.

Hmm that seems like a lot of work though. As in, the pattern that I see (and therefore follow) usually call vim_strsave / alloc or some other generic ways to get an allocated buffer and then NULL-check to protect against memory allocation issues. Only a few are tagged with an alloc ID.

Bram initially added the basic infrastructure (in 7.4.1058 and 7.4.1073) for testing memory
allocation failures. I used this infra in the features that I developed (quickfix, signs,
and tag stack) and used this in a few other places. As you said there are still a large
number of other places where this is not used yet. But this is the only mechanism
available currently to test memory allocation failures.

Relevant patches:
Patch 7.4.1058
Patch 7.4.1073
Patch 8.1.0519
Patch 8.1.0614
Patch 8.2.4474

@ychin
Copy link
Contributor Author

ychin commented Oct 4, 2023

Right. That's useful context to know. It feels to me this is quite manual and difficult to roll out across the board as it requires exhaustively tagging all your allocation, and testing each feature against it.

FWIW I think sometimes test coverage % could be a fickle thing. I'm working on another PR to fix cmdline expansion code related to escaping commas and spaces, and there are some tests that while technically "cover" the lines in question by getting the code to visit that code path (therefore increasing the code coverage %), do not actually test that the underlying behavior (it will be fixed in my PR) works.

@ychin
Copy link
Contributor Author

ychin commented Oct 5, 2023

As an aside, if you look at the change, in GTK Linux, if you don't have a guifont set, if you do :set guifont=<Tab> it will automatically suggest the default font "Monospace 10" for the user so they can adjust it. In Windows I decided not to implement this feature because I really hate the default Fixedsys font and the default font size is tiny on a modern monitor as it's set to pixels rather than points (maybe it's time to come up with a better default?) and not sure if there's any value in auto-filling the default. It can be changed of course.

@chrisbra
Copy link
Member

chrisbra commented Oct 5, 2023

thanks!

@chrisbra chrisbra closed this in 290b887 Oct 5, 2023
@ychin ychin deleted the cmdline-expansion-guifont branch October 5, 2023 21:31
chrisbra pushed a commit to chrisbra/vim that referenced this pull request Oct 7, 2023
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: vim#13264

Signed-off-by: Christian Brabandt <[email protected]>
Co-authored-by: Yee Cheng Chin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants