https://github.com/vim/vim/pull/9039
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
Merging #9039 (69441db) into master (844fb64) will decrease coverage by
87.64%.
The diff coverage is0.00%.
@@ Coverage Diff @@ ## master #9039 +/- ## =========================================== - Coverage 90.10% 2.45% -87.65% =========================================== Files 151 149 -2 Lines 169669 166354 -3315 =========================================== - Hits 152879 4085 -148794 - Misses 16790 162269 +145479
| Flag | Coverage Δ | |
|---|---|---|
| huge-clang-none | ? |
|
| huge-gcc-none | ? |
|
| huge-gcc-testgui | ? |
|
| huge-gcc-unittests | 2.45% <0.00%> (-0.01%) |
⬇️ |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/evalfunc.c | 0.00% <ø> (-96.51%) |
⬇️ |
| src/highlight.c | 6.88% <0.00%> (-83.88%) |
⬇️ |
| src/float.c | 0.00% <0.00%> (-99.22%) |
⬇️ |
| src/gui_gtk_f.c | 0.00% <0.00%> (-97.43%) |
⬇️ |
| src/crypt_zip.c | 0.00% <0.00%> (-97.06%) |
⬇️ |
| src/cmdhist.c | 0.00% <0.00%> (-97.00%) |
⬇️ |
| src/sha256.c | 0.00% <0.00%> (-96.94%) |
⬇️ |
| src/evalbuffer.c | 0.00% <0.00%> (-96.92%) |
⬇️ |
| src/textprop.c | 0.00% <0.00%> (-96.84%) |
⬇️ |
| src/match.c | 0.00% <0.00%> (-96.76%) |
⬇️ |
| ... and 139 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 844fb64...69441db. Read the comment docs.
In the list of functions "hlset()" has "set highlight group attributes", thus "hlget()" should say "get highlight group attributes".
When the name is specified, it should be clear that it returns a list with that entry. The "returns an empty list" paragraph can be moved up, so that the main info about what is returned is in one place.
Otherwise it looks OK to me. Perhaps the info about "cleared" should say a bit more. Like hlexists() mentions that a name can exist without highlighting defined for it, it doesn't actually need to be cleared.
In the list of functions "hlset()" has "set highlight group attributes", thus "hlget()" should say "get highlight group attributes".
When the name is specified, it should be clear that it returns a list with that entry. The "returns an empty list" paragraph can be moved up, so that the main info about what is returned is in one place.
Otherwise it looks OK to me. Perhaps the info about "cleared" should say a bit more. Like hlexists() mentions that a name can exist without highlighting defined for it, it doesn't actually need to be cleared.
I'll leave this for a day for anybody to comment.
—
You are receiving this because you commented.
@romainl commented on this pull request.
> + The 'term', 'cterm' and 'gui' items in the above Dictionary
+ have a dictionary value with the following optional boolean
+ items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
+ 'reverse', 'inverse' and 'strikethrough'.
+
+
+ Example(s): >
+ :echo hlget()
+ :echo hlget('ModeMsg')
+<
+ Can also be used as a |method|: >
+ GetName()->hlget()
+<
+ *hlset()*
+hlset({list})
+ Set the attributes of a List of highlight groups. If a
"Sets"
—
You are receiving this because you commented.
> @@ -6716,6 +6718,81 @@ hlexists({name}) *hlexists()*
Can also be used as a |method|: >
GetName()->hlexists()
+<
+ *hlget()*
+hlget([{name}])
[{name}] gives the impression that one must pass a potentially empty list to the function, which is not the case.
—
You are receiving this because you commented.
@lacygoill commented on this pull request.
> @@ -6716,6 +6718,81 @@ hlexists({name}) *hlexists()*
Can also be used as a |method|: >
GetName()->hlexists()
+<
+ *hlget()*
+hlget([{name}])
[{name}] gives the impression that one must pass a potentially empty list to the function, which is not the case.
That has always bothered me as well, but that's the convention used in the help everywhere else.
{foo} means that foo is a placeholder name (i.e. not to be taken literally, but replaced with a relevant name).
And the surrounding square brackets mean that the parameter is optional.
We can read the same [{name}] for getfontname():
https://github.com/vim/vim/blob/2446ec9b567ce2b72bd06d121f200f40bbdc8a84/runtime/doc/eval.txt#L5787
sign_getdefined():
https://github.com/vim/vim/blob/2446ec9b567ce2b72bd06d121f200f40bbdc8a84/runtime/doc/sign.txt#L423
sign_undefine():
https://github.com/vim/vim/blob/2446ec9b567ce2b72bd06d121f200f40bbdc8a84/runtime/doc/sign.txt#L650
—
You are receiving this because you commented.
@yegappan commented on this pull request.
> @@ -6716,6 +6718,81 @@ hlexists({name}) *hlexists()*
Can also be used as a |method|: >
GetName()->hlexists()
+<
+ *hlget()*
+hlget([{name}])
Yes. That is the convention used in the help files. The optional argument is surrounded by square brackets.
—
You are receiving this because you commented.
@romainl commented on this pull request.
> + term term attributes. See |highlight-term|.
+
+ The 'term', 'cterm' and 'gui' items in the above Dictionary
+ have a dictionary value with the following optional boolean
+ items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
+ 'reverse', 'inverse' and 'strikethrough'.
+
+ Example(s): >
+ :echo hlget()
+ :echo hlget('ModeMsg')
+<
+ Can also be used as a |method|: >
+ GetName()->hlget()
+<
+hlset({list}) *hlset()*
+ Create or modify the attributes of a List of highlight groups.
"Creates or modifies" to follow the "Returns" above.
—
You are receiving this because you commented.
hlget('SpecialKey') outputs a list with a single dictionary item:
./src/vim -Nu NONE --cmd 'echo hlget("SpecialKey") | qa!'
[{'id': 1, 'ctermfg': '4', 'name': 'SpecialKey', 'term': {'bold': v:true}, 'guifg': 'Blue'}]
^^ ^^
What matters is the dictionary. Wouldn't it make more sense to drop the list?
./src/vim -Nu NONE --cmd 'echo hlget("SpecialKey") | qa!'
{'id': 1, 'ctermfg': '4', 'name': 'SpecialKey', 'term': {'bold': v:true}, 'guifg': 'Blue'}
^ ^
Rationale: it's easier to read this:
:echo hlget('SpecialKey').ctermfg
Than this:
:echo hlget('SpecialKey')[0].ctermfg
^^^
what's this for?
Unless there are cases where hlget('Name') can return more than 1 dictionary? Are there?
And if the highlight group does not exist, we could return an empty dictionary, instead of an empty list.
Similarly, could hlset() accept a dictionary – in addition to a list – when we only want to set 1 highlight group?
—
You are receiving this because you commented.
Could hlget() accept an extra optional boolean parameter to make it automatically resolve links?
:echo hlget('Group', v:true)[0]
^----^
Otherwise, we might have to use a while loop which makes the code more verbose:
vim9script hlset([{name: 'A', linksto: 'B'}]) hlset([{name: 'B', linksto: 'C'}]) hlset([{'ctermfg': '4', 'name': 'C', 'term': {'bold': v:true}, 'guifg': 'Blue'}]) var hl: dict<any> = hlget('A')[0] while hl->has_key('linksto') hl = hlget(hl.linksto)->get(0, {}) endwhile echo hl
{'id': 56, 'ctermfg': '4', 'name': 'C', 'term': {'bold': true}, 'guifg': 'Blue'}
—
You are receiving this because you commented.
For the return value: it is much better if the function always returns the same type, not a list with one call and a dictionary with another. That you get a list with one entry (or an empty list if not found) is easy to deal with.
—
You are receiving this because you commented.
hlget('SpecialKey')outputs a list with a single dictionary item:
What matters is the dictionary. Wouldn't it make more sense to drop the list?
As Bram mentioned in his reply, it is better to use the same return type for both
a single highlight group and for all the highlight groups.
Unless there are cases where
hlget('Name')can return more than 1 dictionary? Are there?
The hlget('Name') call will always return a single dictionary.
And if the highlight group does not exist, we could return an empty dictionary, instead of an empty list.
Similarly, could
hlset()accept a dictionary – in addition to a list – when we only want to set 1 highlight group?
Similar to the return value, it is better to always accept a single type for
a argument. We do have some existing functions that accept different types
for the argument and this caused problems with the Vim9 type checks.
—
You are receiving this because you commented.
@yegappan could you outline your plans for your hlrefactor branch?
As we are working on modernising the built-in colorscheme under the vim/colorschemes umbrella it might be interesting for us to know what you have in store regarding syntax highlighting.
Thanks.
—
You are receiving this because you commented.
@yegappan could you outline your plans for your
hlrefactorbranch?
As we are working on modernising the built-in colorscheme under the vim/colorschemes umbrella it might be interesting for us to know what you have in store regarding syntax highlighting.
—
You are receiving this because you are subscribed to this thread.
Are you looking for built-in functions to manage with syntax highlighting?
Not particularly, I was just being nosy.
Thank you again.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub.
Could
hlget()accept an extra optional boolean parameter to make it automatically resolve links?
—
You are receiving this because you are subscribed to this thread.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub.
To clear a highlight group with :highlight, we need to choose one of 3 Ex commands, depending on how it was defined.
If it's defined with its own attributes, then we need :highlight clear:
highlight MyGroup ctermbg=green guibg=green highlight clear MyGroup highlight MyGroup
MyGroup xxx cleared
If it's linked to another highlight group, then we need to link it to NONE:
highlight default link MyGroup ErrorMsg highlight link MyGroup NONE highlight MyGroup
MyGroup xxx cleared
Actually, :highlight clear might work too, but only if the group was defined without the default argument.
If it's defined with its own attributes and is linked to another highlight group, we need to first clear it, then reset its link to NONE (the order of the commands matters):
highlight MyGroup ctermbg=green guibg=green highlight! default link MyGroup ErrorMsg highlight clear MyGroup highlight link MyGroup NONE highlight MyGroup
MyGroup xxx cleared
That's a lot of info. Using hlset() instead of :highlight does not simplify the operation:
highlight MyGroup ctermbg=green guibg=green highlight! default link MyGroup ErrorMsg call hlset([{'name': 'MyGroup', 'cleared': v:true, 'linksto': 'NONE'}]) highlight MyGroup
MyGroup xxx ctermbg=10 guibg=green
We need 2 invocations of hlset() to be sure the group is cleared:
highlight MyGroup ctermbg=green guibg=green highlight! default link MyGroup ErrorMsg call hlset([{'name': 'MyGroup', 'cleared': v:true}]) call hlset([{'name': 'MyGroup', 'linksto': 'NONE'}]) highlight MyGroup
MyGroup xxx cleared
I think the first hlset() invocation fails to clear the group because it first removes the link then clears it (causing the link to be restored because of default). When both the cleared and linksto keys are present, wouldn't it make more sense for hlset() to process cleared before linksto?
—
You are receiving this because you are subscribed to this thread.
Thank you very much for the quick PR, I'm going to test it as soon as I can.
I noticed two other possible issues for which I would like your opinion.
Issue 1: hlset() can't emulate the bang of :highlight!.
Issue 2: hlget() does not give any information for the default argument of a linked highlight group.
With regards to issue 1:
vim9script highlight MyGroup ctermbg=green hlset([{name: 'MyGroup', linksto: 'ErrorMsg'}]) highlight MyGroup
MyGroup xxx ctermbg=10
Notice that the link was not installed. I think that's because hlset() operates like :highlight by default; not like :highlight!. I've read :help hlget() and :help hlset(), but couldn't find any key allowing us to emulate the bang.
This means that there exists an operation that :highlight can perform but not hlset():
vim9script highlight MyGroup ctermbg=green highlight! link MyGroup ErrorMsg highlight MyGroup
MyGroup xxx ctermbg=10
links to ErrorMsg
Shouldn't hlset() provide all the features of :highlight?
With regards to issue 2:
vim9script [{name: 'MyGroup', linksto: 'ErrorMsg'}]->hlset()
highlight clear MyGroup highlight MyGroup
MyGroup xxx cleared
Notice that MyGroup has been cleared. This means that when hlset() defines a group with a link, it does not use default. How are we supposed to tell hlset() that we do want default? Shouldn't it accept a boolean key like default_link?
If you consider all of this as valid, I can open separate issues; let me know. Thank you again for your work on these very useful functions.
—
You are receiving this because you commented.
Thank you very much for the quick PR, I'm going to test it as soon as I can.
I noticed two other possible issues for which I would like your opinion.
Issue 1:
hlset()can't emulate the bang of:highlight!.
Issue 2:hlget()does not give any information for thedefaultargument of a linked highlight group.
—
You are receiving this because you are subscribed to this thread.
Thank you very much for the quick fix. Everything works fine with maybe one exception. The default key is still absent from the output of hlget().
vim9script [{name: 'MyGroup', linksto: 'ErrorMsg', default: true}]->hlset() echo hlget('MyGroup')->get(0, {})->has_key('default')
0
This matters if we want to create an exact duplicate of an existing highlight group, and maybe slightly alter one of its attribute. For example:
vim9scripthighlight default link MyGroup ErrorMsg
var hg_save: list<dict<any>> = hlget('MyGroup') var dup: string = 'Duplicate' hg_save[0]->extend({'name': dup}) hg_save->hlset() highlight clear Duplicate highlight Duplicate
Duplicate xxx cleared
Notice that Duplicate is cleared. This means that when it was created by hlset(), the latter did not use default; otherwise, the link would have been automatically restored just like here:
vim9scripthighlight default link MyGroup ErrorMsg
highlight clear MyGroup highlight MyGroup
MyGroup xxx links to ErrorMsg
I think the issue comes from hlget() which still does not tell us whether MyGroup is linked to ErrorMsg with default or not. It would help if the output of hlget() included default: true or default: false for a linked group:
vim9script [{name: 'MyGroup', linksto: 'ErrorMsg', default: true}]->hlset() echo hlget('MyGroup')
[{'id': 54, 'linksto': 'ErrorMsg', 'default': true, 'name': 'MyGroup'}]
^-------------^
—
You are receiving this because you commented.
Thank you very much for the quick fix. Everything works fine with maybe one exception. The
defaultkey is still absent from the output ofhlget().
—
You are receiving this because you are subscribed to this thread.
I have updated the PR to return the default setting for links.
Thank you very much. I've just tested the PR, and everything works as expected.
—
You are receiving this because you commented.
Interestingly enough, :highlight is faster than hlset():
vim9script var time = reltime() def Func() for i: number in range(100'000) highlight ErrorMsg term=standout ctermfg=253 ctermbg=168 guifg=#dadada guibg=#d75f87 endfor enddef Func() (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run Func()')->setline(1)
0.343 seconds to run Func()
vim9script var time = reltime() def Func() for i: number in range(100'000) [{ name: 'ErrorMsg', ctermfg: '253', ctermbg: '168', guibg: '#d75f87', guifg: '#dadada', term: {standout: true}, }]->hlset() endfor enddef Func() (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run Func()')->setline(1)
0.511 seconds to run Func()
The discrepancy is more pronounced at the script level:
vim9script var time = reltime() for i in range(100'000) highlight ErrorMsg term=standout ctermfg=253 ctermbg=168 guifg=#dadada guibg=#d75f87 endfor (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run the script')->setline(1)
0.523 seconds to run the script
vim9script var time = reltime() for i: number in range(100'000) [{ name: 'ErrorMsg', ctermfg: '253', ctermbg: '168', guibg: '#d75f87', guifg: '#dadada', term: {standout: true}, }]->hlset() endfor (reltime(time)->reltimestr()->matchstr('.*\..\{,3}') .. ' seconds to run the script')->setline(1)
1.268 seconds to run the script
Log for hlset().
Log for :highlight.
—
You are receiving this because you are subscribed to this thread.