summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlin Mr <almr.oss@outlook.com>2024-03-20 20:26:23 +0100
committerChristian Brabandt <cb@256bit.org>2024-03-20 20:27:26 +0100
commit6d1d18084b7b04ab7fd73331ce59e99b6dd9ad72 (patch)
treefe2cf6f3ebefe1deb47986702f687aa1f8009779
parent978178823b7c62a0249411f3d1f584f8a3144c5d (diff)
runtime(colors): don't unnecessarily reload v:colornames dict
fixes: #14234 closes: #14235 Signed-off-by: Alin Mr <almr.oss@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/colors/lists/default.vim49
-rw-r--r--runtime/doc/eval.txt6
2 files changed, 41 insertions, 14 deletions
diff --git a/runtime/colors/lists/default.vim b/runtime/colors/lists/default.vim
index 073a0da11b..c8df0c9167 100644
--- a/runtime/colors/lists/default.vim
+++ b/runtime/colors/lists/default.vim
@@ -1,5 +1,5 @@
" Maintainer: Drew Vogel <dvogel@sidejump.org>
-" Last Change: 2023 Apr 19
+" Last Change: 2024 Mar 20
"
" Replaced rgb.txt as the source of de facto standard color names. This is
" sourced each time the colorscheme command is run. It is also sourced each
@@ -13,7 +13,38 @@
let s:keepcpo = &cpo
set cpo&vim
-call extend(v:colornames, {
+function! s:Cleanup()
+ let &cpo = s:keepcpo
+ unlet s:keepcpo
+endfunction
+
+function! s:AddColors(cnames) abort
+ call extend(v:colornames, a:cnames, 'keep')
+
+ " all keys should be in lower case, convert keys that are not yet
+ let len_after = len(v:colornames)
+ if len_after == len(a:cnames)
+ " after extend(): v:colornames has all the keys of default_cnames
+ " checked: v:colornames also has no extra keys
+ " => keys are the same, and keys(default_cnames) are known to be ok
+ return
+ endif
+
+ for [key, val] in items(filter(copy(v:colornames), { key -> key =~ '\u'}))
+ call remove(v:colornames, key)
+ if !has_key(v:colornames, tolower(key))
+ call extend(v:colornames, {tolower(key): val}, 'keep')
+ endif
+ endfor
+endfunction
+
+if exists('s:default_cnames')
+ call s:AddColors(s:default_cnames)
+ call s:Cleanup()
+ finish
+endif
+
+let s:default_cnames = {
\ 'snow': '#fffafa',
\ 'ghost white': '#f8f8ff',
\ 'ghostwhite': '#f8f8ff',
@@ -802,17 +833,9 @@ call extend(v:colornames, {
\ 'rebeccapurple': '#663399',
\ 'silver': '#c0c0c0',
\ 'teal': '#008080'
- \ }, 'keep')
-
-" all keys should be in lower case, convert keys that are not yet
-for [key, val] in items(filter(copy(v:colornames), { key -> key =~ '\u'}))
- call remove(v:colornames, key)
- if !has_key(v:colornames, tolower(key))
- call extend(v:colornames, {tolower(key): val}, 'keep')
- endif
-endfor
+ \ }
-let &cpo = s:keepcpo
-unlet s:keepcpo
+call s:AddColors(s:default_cnames)
+call s:Cleanup()
"vim: sw=4
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index e3a9f20136..f2ff3a883f 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt* For Vim version 9.1. Last change: 2024 Feb 08
+*eval.txt* For Vim version 9.1. Last change: 2024 Mar 20
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2076,6 +2076,10 @@ v:colornames A dictionary that maps color names to hex color strings. These
both automatically load all `colors/lists/default.vim` color
scripts.
+ You can make changes to that file, but make sure to add new
+ keys instead of updating existing ones, otherwise Vim will skip
+ loading the file (thinking is hasn't been changed).
+
*v:completed_item* *completed_item-variable*
v:completed_item
|Dictionary| containing the |complete-items| for the most