[vim/vim] Store extended colors in v:colornames dict. (#8761)

72 views
Skip to first unread message

Drew Vogel

unread,
Aug 15, 2021, 4:32:43 PM8/15/21
to vim/vim, Subscribed

Problem solved: Remembering RGB colors is difficult.
Solution: Allow user to (re-)define new color names.

This patch is a follow-up to the discussion on #8502.

A central question in that discussion was how users would put the new v:colornames dict to use and whether a single shared dict was appropriate. My own opinion is that a single shared dict is simultaneously the most approachable and the most usable. I've extended my previous work in an attempt to demonstrate why I think that is the case.

  • I've expanded the documentation with examples of how to update the dict in different scenarios.
  • I've created a proof-of-concept vim-colorwheel plugin that demonstrates how users might collaborate on color schemes using this shared dict.
  • I've fully removed the rgb.txt file while retaining the same list of colors.
    • That special case file has been replaced with a more generic color list script convention. In order to guard against users mistakenly thinking they should remove colors from v:colornames, the rgb.txt colors are put into a default color list, which is re-executed when a user would have expected the rgb.txt colors to be valid.
    • I've updated the Haiku color code to use the common gui color code. I've built this on Haiku and conducted simple manual tests but I don't have much expertise with Haiku, so it is possible I've missed some nuance there.

Finally, the color name code has been moved into highlight.c as suggested by @brammool. Thanks to Bram, @chrisbra, and @romainl for the helpful feedback on the last PR. I'm looking forward to any feedback you all have on this update/alternative.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/8761

Commit Summary

  • Store extended colors in v:colornames dict.

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

codecov[bot]

unread,
Aug 16, 2021, 1:35:59 AM8/16/21
to vim/vim, Subscribed

Codecov Report

Merging #8761 (c07d147) into master (b033ee2) will decrease coverage by 87.69%.
The diff coverage is 1.31%.

Current head c07d147 differs from pull request most recent head 0241aa1. Consider uploading reports for the commit 0241aa1 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@

##           master    #8761       +/-   ##

===========================================

- Coverage   90.15%    2.46%   -87.70%     

===========================================

  Files         151      149        -2     

  Lines      170639   165393     -5246     

===========================================

- Hits       153839     4073   -149766     

- Misses      16800   161320   +144520     
Flag Coverage Δ
huge-clang-none ?
huge-gcc-none ?
huge-gcc-testgui ?
huge-gcc-unittests 2.46% <1.31%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
src/highlight.c 7.62% <0.00%> (-82.85%) ⬇️
src/memline.c 0.00% <ø> (-88.77%) ⬇️
src/term.c 0.00% <ø> (-83.30%) ⬇️
src/userfunc.c 0.18% <0.00%> (-95.10%) ⬇️
src/version.c 0.86% <ø> (-91.48%) ⬇️
src/vim9compile.c 0.00% <0.00%> (-93.81%) ⬇️
src/evalvars.c 5.18% <100.00%> (-91.30%) ⬇️
src/float.c 0.00% <0.00%> (-99.22%) ⬇️
src/gui_gtk_f.c 0.00% <0.00%> (-97.54%) ⬇️
src/sound.c 0.00% <0.00%> (-97.12%) ⬇️
... and 144 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 b033ee2...0241aa1. Read the comment docs.

Drew Vogel

unread,
Sep 14, 2021, 11:06:20 AM9/14/21
to vim/vim, Subscribed

@chrisbra I finally had a chance to fix the test failures on this branch. Mind approving the test run again?


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Christian Brabandt

unread,
Sep 14, 2021, 11:07:38 AM9/14/21
to vim/vim, Subscribed

of course!


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Sep 14, 2021, 11:31:48 PM9/14/21
to vim/vim, Push

@dvogel pushed 1 commit.

  • 0c40041 Store extended colors in v:colornames dict.


You are receiving this because you are subscribed to this thread.

View it on GitHub.

Bram Moolenaar

unread,
Sep 15, 2021, 8:27:27 AM9/15/21
to vim/vim, Subscribed

For default.vim, instead of calling has_key() for every entry, you can use extend(v:colornames, {dict with values}, 'keep')
That should be much faster.

I notice that the loopup in rgb_table[] just uses a linear search. A binary search would be much better.
It is unrelated to v:colornames, could leave this as a todo item.

Otherwise, I'll leave this open for remarks. Is using v:colornames the best solution?


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Sep 17, 2021, 12:07:54 AM9/17/21
to vim/vim, Subscribed

My original motivation for using has_key in default.vim was to remain vi compatible. I'd be fine using extend there however I tried it recently and it is significantly slower, to the point of causing the CI jobs to time out: https://github.com/dvogel/vim/actions/runs/1238981661.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Sep 18, 2021, 4:03:23 PM9/18/21
to vim/vim, Push

@dvogel pushed 1 commit.

  • 8454eb9 Use extend() in runtime/colors/lists/default.vim


You are receiving this because you are subscribed to this thread.

View it on GitHub.

Drew Vogel

unread,
Sep 18, 2021, 4:07:21 PM9/18/21
to vim/vim, Subscribed

I've pushed an additional commit that requires uses extend for better performance. The trade-off is that the default colors now require vi-incompatible line continuations. This was at the heart of why the tests were hanging with my first attempt to use extend the Test_background_foreground test relies on the color ivory. Launching that test in nocompatible mode allows it to run without hanging the test suite.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Bram Moolenaar

unread,
Sep 21, 2021, 2:00:48 PM9/21/21
to vim/vim, Subscribed

See the runtime files for examples of how the 'cpo' option is changed and restored to allow for line continuation. Basically:

let s:cpo_save = &cpo
set cpo&vim

commands

let &cpo = s:cpo_save
unlet s:cpo_save


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Sep 22, 2021, 12:09:42 AM9/22/21
to vim/vim, Push

@dvogel pushed 1 commit.

  • 4f56a12 Temporarily set cpo in default color list.


You are receiving this because you are subscribed to this thread.

View it on GitHub.

Bram Moolenaar

unread,
Sep 22, 2021, 4:57:26 AM9/22/21
to vim/vim, Subscribed

Setting and restoring 'cpo' will also be needed in csscolors.vim


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Sep 26, 2021, 9:40:54 AM9/26/21
to vim/vim, Push

@dvogel pushed 1 commit.

  • 5adc3a2 Add compatibility steps to csscolors.vim


You are receiving this because you are subscribed to this thread.

View it on GitHub.

Bram Moolenaar

unread,
Oct 23, 2021, 4:48:27 PM10/23/21
to vim/vim, Subscribed

Drew - have you looked into fixing the line continuation?


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Oct 23, 2021, 5:07:23 PM10/23/21
to vim/vim, Subscribed

Yeah the color lists included in the patch all use the line continuations with the compatibility flag save/restore pattern you suggested. I haven't had a chance to look into the merge conflicts that arose from the refactor of the highlighting code yet.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Drew Vogel

unread,
Oct 23, 2021, 5:17:35 PM10/23/21
to vim/vim, Subscribed

Looks like it was just a conflict due to a tiny comment correction I made. I've rebased this branch atop the master branch, squashing my commits in the process.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Bram Moolenaar

unread,
Oct 24, 2021, 3:35:52 PM10/24/21
to vim/vim, Subscribed

Closed #8761 via e30d102.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.

Reply all
Reply to author
Forward
0 new messages