Skip to content

Commit ed12b53

Browse files
authored
ref: when using colorizer.reload_on_save, but existing buffer options (#137)
* ref: when using colorizer.reload_on_save, but existing buffer options if available
1 parent 174a537 commit ed12b53

File tree

5 files changed

+17
-37
lines changed

5 files changed

+17
-37
lines changed

doc/colorizer.txt

-10
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ Provides configuration options and utilities for setting up colorizer.
415415
LUA API *colorizer.config-lua-api*
416416

417417
Functions: ~
418-
|reset_cache| - Reset the cache for buffer options.
419-
420418
|set_bo_value| - Set options for a specific buffer or file type.
421419

422420
|apply_alias_options| - Parse and apply alias options to the user options.
@@ -436,14 +434,6 @@ Tables: ~
436434
|ud_opts| - Configuration options for the `setup` function.
437435

438436

439-
reset_cache() *colorizer.config.reset_cache*
440-
Reset the cache for buffer options.
441-
442-
Called from colorizer.setup
443-
444-
445-
446-
447437
set_bo_value({bo_type}, {val}, {ud_opts}) *colorizer.config.set_bo_value*
448438
Set options for a specific buffer or file type.
449439

doc/modules/colorizer.config.html

-19
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ <h1>Module <code>colorizer.config</code></h1>
6969

7070
<h2><a href="#Functions">Functions</a></h2>
7171
<table class="function_list">
72-
<tr>
73-
<td class="name" nowrap><a href="#reset_cache">reset_cache ()</a></td>
74-
<td class="summary">Reset the cache for buffer options.</td>
75-
</tr>
7672
<tr>
7773
<td class="name" nowrap><a href="#set_bo_value">set_bo_value (bo_type, val, ud_opts)</a></td>
7874
<td class="summary">Set options for a specific buffer or file type.</td>
@@ -117,21 +113,6 @@ <h2><a href="#Tables">Tables</a></h2>
117113
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
118114

119115
<dl class="function">
120-
<dt>
121-
<a name = "reset_cache"></a>
122-
<strong>reset_cache ()</strong>
123-
</dt>
124-
<dd>
125-
Reset the cache for buffer options.
126-
Called from colorizer.setup
127-
128-
129-
130-
131-
132-
133-
134-
</dd>
135116
<dt>
136117
<a name = "set_bo_value"></a>
137118
<strong>set_bo_value (bo_type, val, ud_opts)</strong>

lua/colorizer.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ function M.reload_on_save(pattern)
253253
colorizer_state.buffer_reload = buffer_reload
254254

255255
vim.schedule(function()
256-
M.attach_to_buffer()
256+
-- mimic bo_type_setup() function within colorizer.setup
257+
local bo_type = "filetype"
258+
local ud_opts = config.get_bo_options(bo_type, vim.bo.buftype, vim.bo.filetype)
259+
M.attach_to_buffer(evt.buf, ud_opts, bo_type)
257260
vim.notify(
258261
"Colorizer reloaded with updated options from " .. evt.match,
259262
vim.log.levels.INFO
@@ -461,12 +464,11 @@ function M.setup(opts)
461464
require("colorizer.matcher").reset_cache()
462465
require("colorizer.parser.names").reset_cache()
463466
require("colorizer.buffer").reset_cache()
464-
require("colorizer.config").reset_cache()
465467

466468
local s = config.get_setup_options(opts)
467469

468470
-- Setup the buffer with the correct options
469-
local function setup(bo_type)
471+
local function bo_type_setup(bo_type)
470472
local filetype = vim.bo.filetype
471473
local buftype = vim.bo.buftype
472474
local bufnr = utils.bufme()
@@ -532,10 +534,10 @@ function M.setup(opts)
532534
callback = function()
533535
if s.lazy_load then
534536
vim.schedule(function()
535-
setup(bo_type)
537+
bo_type_setup(bo_type)
536538
end)
537539
else
538-
setup(bo_type)
540+
bo_type_setup(bo_type)
539541
end
540542
end,
541543
})

lua/colorizer/config.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ end
9898
local options_cache
9999
--- Reset the cache for buffer options.
100100
-- Called from colorizer.setup
101-
function M.reset_cache()
101+
local function init_cache()
102102
options_cache = { buftype = {}, filetype = {} }
103103
end
104+
105+
local function init_config()
106+
init_options()
107+
init_cache()
108+
end
104109
do
105-
M.reset_cache()
110+
init_config()
106111
end
107112

108113
--- Validate user options and set defaults.
@@ -251,7 +256,7 @@ end
251256
---@param opts table|nil: Configuration options for colorizer.
252257
---@return table: Final settings after merging user and default options.
253258
function M.get_setup_options(opts)
254-
init_options()
259+
init_config()
255260
opts = opts or {}
256261
opts.user_default_options = opts.user_default_options or plugin_user_default_options
257262
opts.user_default_options = M.apply_alias_options(opts.user_default_options)

test/expect.lua

+2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ DeepSkyBlue DeepSkyBlue2
8282
DEEPSKYBLUE DEEPSKYBLUE3
8383
8484
Extra names:
85+
From function defined in `user_default_options`
8586
oniViolet oniViolet2 crystalBlue springViolet1 springViolet2 springBlue
8687
lightBlue waveAqua2
8788
8889
Custom names with non-alphanumeric characters:
90+
From table in filetype definiton (lua)
8991
one_two three=four five@six seven!eight nine!!ten
9092
NOTE: TODO: WARN: FIX: .
9193
NOTE:

0 commit comments

Comments
 (0)