Skip to content

Commit

Permalink
feat: cursorline and cursorcolumn automatically disabled in insert mo…
Browse files Browse the repository at this point in the history
…de. Can be configured
  • Loading branch information
tummetott committed Feb 12, 2023
1 parent 0135b7d commit 983fb8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
16 changes: 10 additions & 6 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ require('reticle').setup {
cursorcolumn = true,
},

-- Disable the cursorline and cursorcolumn in insert mode. Default is true
disable_in_insert = false

-- By default, nvim highlights the cursorline number only when the cursorline setting is
-- switched on. When enabeling the following setting, the cursorline number
-- of every window is always highlighted, regardless of the setting
always_show_cl_number = true,

-- Define filetypes where the cursorline / cursorcolumn is always on,
-- regardless of the global setting
always = {
Expand Down Expand Up @@ -207,11 +215,6 @@ require('reticle').setup {
'lspinfo',
},
},

-- By default, nvim highlights the cursorline number only when the cursorline setting is
-- switched on. When enabeling the following setting, the cursorline number
-- of every window is always highlighted, regardless of the setting
always_show_cl_number = true,
}
```

Expand All @@ -226,6 +229,8 @@ The default configuration of `reticle.nvim` looks as following:
cursorline = true,
cursorcolumn = true,
},
disable_in_insert = true,
always_show_cl_number = false,
always = {
cursorline = {},
cursorcolumn = {},
Expand All @@ -245,7 +250,6 @@ The default configuration of `reticle.nvim` looks as following:
cursorline = {},
cursorcolumn = {},
},
always_show_cl_number = false,
}
```

Expand Down
3 changes: 2 additions & 1 deletion lua/reticle/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local defaults = {
cursorline = true,
cursorcolumn = true,
},
disable_in_insert = true,
always_show_cl_number = false,
always = {
cursorline = {},
cursorcolumn = {},
Expand All @@ -24,7 +26,6 @@ local defaults = {
cursorline = {},
cursorcolumn = {},
},
always_show_cl_number = false,
}

M.init = function(user_conf)
Expand Down
29 changes: 14 additions & 15 deletions lua/reticle/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local settings = nil -- We update this value once the config is parsed
local autocmd = vim.api.nvim_create_autocmd
local augroup = vim.api.nvim_create_augroup
local contains = vim.tbl_contains
local vim_enter = true
local enabled = { cursorline = false, cursorcolumn = false }

-- This wrapper function sets a window local option for the focused window
Expand Down Expand Up @@ -85,18 +84,8 @@ end

local on_enter = function()
local window = vim.api.nvim_get_current_win()
-- When first entering vim, we must retrieve the initial cursorline and
-- cursorcolumn setting and init our plugin state
if vim_enter then
enabled.cursorline = vim.wo.cursorline
enabled.cursorcolumn = vim.wo.cursorcolumn
update_option_on_enter('cursorline', window)
update_option_on_enter('cursorcolumn', window)
vim_enter = false
else
deferred_update_option_on_enter('cursorline', window)
deferred_update_option_on_enter('cursorcolumn', window)
end
deferred_update_option_on_enter('cursorline', window)
deferred_update_option_on_enter('cursorcolumn', window)
end

local on_leave = function()
Expand All @@ -123,12 +112,18 @@ local on_option_change = function(state)
end

local register_autocmds = function()
local enter_events = { 'WinEnter', 'BufWinEnter' }
local leave_events = { 'WinLeave' }
if settings.disable_in_insert then
table.insert(enter_events, 'InsertLeave')
table.insert(leave_events, 'InsertEnter')
end
local group = augroup('Reticle', { clear = true })
autocmd({ 'WinEnter', 'BufWinEnter' }, {
autocmd(enter_events, {
callback = function() on_enter() end,
group = group,
})
autocmd('WinLeave', {
autocmd(leave_events, {
callback = function() on_leave() end,
group = group,
})
Expand All @@ -142,6 +137,10 @@ end
M.setup = function(user_config)
conf.init(user_config)
settings = conf.settings
-- When first entering vim, we must retrieve the initial cursorline and
-- cursorcolumn setting and init our plugin state
enabled.cursorline = vim.wo.cursorline
enabled.cursorcolumn = vim.wo.cursorcolumn
register_autocmds()
end

Expand Down

0 comments on commit 983fb8b

Please sign in to comment.