Store extended colors in v:colornames dict.#8502
Conversation
Problem solved: Remembering RGB colors is difficult. Solution: Allow user to (re-)define new color names.
|
I'll leave this open for others to give comments. The code can probably go in src/highlight.c, instead of adding a new colornames.c file. |
Codecov Report
@@ Coverage Diff @@
## master #8502 +/- ##
==========================================
+ Coverage 89.70% 89.94% +0.24%
==========================================
Files 149 146 -3
Lines 167979 166975 -1004
==========================================
- Hits 150679 150189 -490
+ Misses 17300 16786 -514
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
runtime/doc/eval.txt
Outdated
| *v:colornames* | ||
| v:colornames A dictionary that maps color names to hex color strings. These | ||
| color names can be used with the |highlight-guifg| and | ||
| |highlight-guibg| parameters. The dictionary is provided only |
There was a problem hiding this comment.
|highlight-guisp| is missing.
|
What would be the expected outcome when the user does something like: or something of the sort? I understand that it wouldn't change anything for a colorscheme using those special names that is already sourced but what if you remove all those names and source that colorscheme again? I guess we are expecting that list to be an explicit part of colorschemes, a bit like with Another question: suppose users source two colorschemes that use that mechanism, shouldn't we devise something that clears |
Thanks for the feedback @romainl. Since
...
The last script to write before a
In theory a script could clear the dictionary using normal vimscript: This would cause havoc for the rgb.txt colors since those are only loaded once. Outside of debugging, I'm not sure of a reason to clear the dictionary though since any script that might clear it would be able to overwrite an existing entry the script wanted to control. We could easily make the code re-load the rgb.txt colors anytime one is not found if we foresee good reasons people might clear the dictionary. |
Sounds good. I will move the |
So what happens, with an existing highlighting command, when I change the color definition later?
Hm, does it make sense to check, that the dictionary contains at least xxx entries? Or that at least the default colors (whatever they are...) are always defined? |
Nothing changes at that time. The only time the highlight table is updated is when the
Personally, I don't think so. That would be one way to retain the current behavior (rgb.txt colors cannot be unloaded once they are loaded in the current implementation). However, I find the new malleability of those colors to be a benefit. I hope to be able to more easily override the definition of those colors (my eyes benefit from higher saturation). It would take considerable intent to decide to clear the |
|
I think what would be good to have is a section in the help where the
use of v:colornames is explained, with examples.
This should cover both personal use, e.g. setting v:colornames in your
.vimrc or another file under ~/.vim, and use with plugins and syntax
files for various filetypes.
Once we have that we can decide if just having one dictionary for the
whole of Vim, which can be changed any time, is a good solution.
It might be that we need a more complicated solution, e.g. a list of
dictionaries, so that plugins can add and remove their own set.
…--
I AM THANKFUL...
...for the clothes that fit a little too snug because it
means I have more than enough to eat.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
Problem solved: Remembering RGB colors is difficult.
Solution: Allow user to (re-)define new color names.
This is a follow-up to a previous pull request (#8426). The aim is the same but
this implementation tries to follow @brammool's suggestion to use a builtin dictionary to make manipulation
and examination of the color table more natural.
One point of friction with this approach relates to the casing of color names. The names loaded from rgb.txt
are converted to lowercase when they are read into the table. The lookups are also done in lowercase. This
satisfies all of the existing mixed-case uses of the color names. However, it could be slightly confusing for
users accustomed to the casing found in rgb.txt. It should be apparent upon examination of the dictionary,
such as with
let v:colornames.The color lookup will accommodate numeric values in
v:colornamesbut the expectation is to use hex colorstrings. The hex strings only require decoding when used in conjunction with a
highlightcommand, so thecost is minimal and the usability improvement is substantial.