@@ -33,8 +33,11 @@ local options = {
3333 },
3434}
3535
36+ --- @type integer ?
37+ local augroup_id = nil
38+
3639--- @return ModicatorOptions
37- M .get_options = function ()
40+ function M .get_options ()
3841 return options
3942end
4043
@@ -115,7 +118,7 @@ local function mode_name_from_mode(mode)
115118end
116119
117120--- @param mode string
118- M .hl_name_from_mode = function (mode )
121+ function M .hl_name_from_mode (mode )
119122 local mode_name = mode_name_from_mode (mode )
120123 return mode_name .. ' Mode'
121124end
@@ -183,10 +186,9 @@ local function set_highlight_groups()
183186 update_mode ()
184187end
185188
186- --- Set the foreground and background color of 'CursorLineNr'. Accepts any
187- --- highlight definition map that `vim.api.nvim_set_hl()` does.
188- --- @param hl_name string
189- M .set_cursor_line_highlight = function (hl_name )
189+ --- Set the foreground and background color of 'CursorLineNr'
190+ --- @param hl_name string Name of mode highlight group
191+ function M .set_cursor_line_highlight (hl_name )
190192 local hl_group = require (' modicator.utils' ).get_highlight (hl_name )
191193 local hl = vim .tbl_extend (' force' , options .highlights .defaults , hl_group )
192194 if options .highlights .use_cursorline_background == true then
@@ -195,14 +197,15 @@ M.set_cursor_line_highlight = function(hl_name)
195197 end
196198 api .nvim_set_hl (0 , ' CursorLineNr' , hl )
197199
198- local is_register_executing = vim .fn .reg_executing () ~= " "
200+ local register_is_executing = vim .fn .reg_executing () ~= " "
199201
200202 -- Workaround for https://github.com/neovim/neovim/issues/25851
201- if not vim .o .lazyredraw and not is_register_executing then
203+ if not vim .o .lazyredraw and not register_is_executing then
202204 vim .cmd .redraw ()
203205 end
204206end
205207
208+ --- @return integer augroup Augroup ID
206209local function create_autocmds ()
207210 local augroup = api .nvim_create_augroup (' Modicator' , {})
208211 -- NOTE: VimEnter loads after user's configuration is loaded
@@ -221,17 +224,36 @@ local function create_autocmds()
221224 callback = set_highlight_groups ,
222225 group = augroup ,
223226 })
227+
228+ return augroup
229+ end
230+
231+ --- Enable Modicator
232+ function M .enable ()
233+ set_highlight_groups ()
234+
235+ api .nvim_set_hl (0 , ' CursorLineNr' , { link = ' NormalMode' })
236+
237+ augroup_id = create_autocmds ()
238+ end
239+
240+ --- Disable Modicator
241+ function M .disable ()
242+ if augroup_id then
243+ api .nvim_del_augroup_by_id (augroup_id )
244+ augroup_id = nil
245+ end
246+
247+ require (' modicator.backup' ).restore_default_cursorline_hl ()
224248end
225249
226250--- @param opts ModicatorOptions ?
227251function M .setup (opts )
228252 options = vim .tbl_deep_extend (' force' , options , opts or {})
229253
230- set_highlight_groups ()
231-
232- vim .api .nvim_set_hl (0 , ' CursorLineNr' , { link = ' NormalMode' })
254+ require (' modicator.backup' ).backup_default_cursorline_hl ()
233255
234- create_autocmds ()
256+ M . enable ()
235257end
236258
237259return M
0 commit comments