Skip to content

Commit d57e1f0

Browse files
committed
feat: add documentation
1 parent b156d4e commit d57e1f0

File tree

8 files changed

+270
-43
lines changed

8 files changed

+270
-43
lines changed

.editorconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ end_of_line = lf
66
indent_style = tab
77
insert_final_newline = true
88
trim_trailing_whitespace = true
9-
10-
[*.lua]
11-
indent_size = 3
12-
indent_style = tab

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ clean: clear_dependencies
1616
.PHONY: test
1717
test: install_dependencies
1818
$(NVIM_HEADLESS) -c "call Test()"
19+
20+
.PHONY: docs
21+
docs:
22+
@echo "Generating documentation..."
23+
@nvim --headless --noplugin -u ./scripts/minimal-init.lua -c "luafile scripts/minidoc.lua" -c "qa!"
24+
25+
.PHONY: clean
26+
clean:
27+
@echo "Removing temporary directories..."
28+
@rm -rf "/tmp/nvim/site/pack/test/start/mini.doc"

doc/modes.txt

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
*modes.nvim* Prismatic line decorations for the adventurous vim user
2+
*Modes*
3+
4+
MIT License Copyright (c) mvllow
5+
6+
==============================================================================
7+
8+
Features:
9+
10+
- Highlight UI elements based on the current mode.
11+
12+
# Setup ~
13+
14+
Modes setup can be called with your `config` table to modify default
15+
behaviour.
16+
17+
See |Modes.config| for `config` options and default values.
18+
19+
------------------------------------------------------------------------------
20+
*default_config*
21+
`default_config`
22+
Module config
23+
24+
Default values:
25+
>lua
26+
local default_config = {
27+
colors = {},
28+
line_opacity = {
29+
copy = 0.15,
30+
delete = 0.15,
31+
change = 0.15,
32+
format = 0.15,
33+
insert = 0.15,
34+
visual = 0.15,
35+
},
36+
set_cursor = true,
37+
set_cursorline = true,
38+
set_number = true,
39+
set_signcolumn = true,
40+
ignore = {
41+
'NvimTree',
42+
'lspinfo',
43+
'packer',
44+
'checkhealth',
45+
'help',
46+
'man',
47+
'TelescopePrompt',
48+
'TelescopeResults',
49+
'!minifiles',
50+
},
51+
}
52+
local winhighlight = {
53+
default = {
54+
CursorLine = 'CursorLine',
55+
CursorLineNr = 'CursorLineNr',
56+
CursorLineSign = 'CursorLineSign',
57+
CursorLineFold = 'CursorLineFold',
58+
Visual = 'Visual',
59+
},
60+
copy = {
61+
CursorLine = 'ModesCopyCursorLine',
62+
CursorLineNr = 'ModesCopyCursorLineNr',
63+
CursorLineSign = 'ModesCopyCursorLineSign',
64+
CursorLineFold = 'ModesCopyCursorLineFold',
65+
},
66+
delete = {
67+
CursorLine = 'ModesDeleteCursorLine',
68+
CursorLineNr = 'ModesDeleteCursorLineNr',
69+
CursorLineSign = 'ModesDeleteCursorLineSign',
70+
CursorLineFold = 'ModesDeleteCursorLineFold',
71+
},
72+
change = {
73+
CursorLine = 'ModesChangeCursorLine',
74+
CursorLineNr = 'ModesChangeCursorLineNr',
75+
CursorLineSign = 'ModesChangeCursorLineSign',
76+
CursorLineFold = 'ModesChangeCursorLineFold',
77+
},
78+
format = {
79+
CursorLine = 'ModesFormatCursorLine',
80+
CursorLineNr = 'ModesFormatCursorLineNr',
81+
CursorLineSign = 'ModesFormatCursorLineSign',
82+
CursorLineFold = 'ModesFormatCursorLineFold',
83+
},
84+
insert = {
85+
CursorLine = 'ModesInsertCursorLine',
86+
CursorLineNr = 'ModesInsertCursorLineNr',
87+
CursorLineSign = 'ModesInsertCursorLineSign',
88+
CursorLineFold = 'ModesInsertCursorLineFold',
89+
},
90+
visual = {
91+
CursorLine = 'ModesVisualCursorLine',
92+
CursorLineNr = 'ModesVisualCursorLineNr',
93+
CursorLineSign = 'ModesVisualCursorLineSign',
94+
CursorLineFold = 'ModesVisualCursorLineFold',
95+
Visual = 'ModesVisualVisual',
96+
},
97+
}
98+
local colors = {}
99+
local blended_colors = {}
100+
local in_ignored_buffer = function()
101+
if type(config.ignore) == 'function' then
102+
return config.ignore()
103+
end
104+
return not vim.tbl_contains(config.ignore, '!' .. vim.bo.filetype)
105+
and (vim.api.nvim_get_option_value('buftype', { buf = 0 }) ~= '' -- not a normal buffer
106+
or not vim.api.nvim_get_option_value('buflisted', { buf = 0 }) -- unlisted buffer
107+
or vim.tbl_contains(config.ignore, vim.bo.filetype))
108+
end
109+
110+
H.reset = function()
111+
H.highlight('default')
112+
vim.cmd.redraw()
113+
end
114+
115+
H.restore = function()
116+
local scene = H.get_scene()
117+
H.highlight(scene)
118+
end
119+
120+
<
121+
------------------------------------------------------------------------------
122+
*H.highlight()*
123+
`H.highlight`({scene})
124+
highlights
125+
Parameters ~
126+
{scene} '`(default)`'|'copy'|'delete'|'change'|'format'|'insert'|'visual'
127+
128+
------------------------------------------------------------------------------
129+
*Modes.setup()*
130+
`Modes.setup`({opts})
131+
Module setup
132+
133+
Parameters ~
134+
{config} `(table|nil)` Module config table. See |Modes.config|.
135+
136+
Usage ~
137+
`require('modes').setup({})` (replace `{}` with your `config` table)
138+
139+
140+
vim:tw=78:ts=8:noet:ft=help:norl:

doc/tags

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
H.highlight() modes.txt /*H.highlight()*
2+
Modes modes.txt /*Modes*
3+
Modes.setup() modes.txt /*Modes.setup()*
4+
default_config modes.txt /*default_config*
5+
modes.nvim modes.txt /*modes.nvim*

lua/modes.lua

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
local utils = require('modes.utils')
1+
--- *modes.nvim* Prismatic line decorations for the adventurous vim user
2+
--- *Modes*
3+
---
4+
--- MIT License Copyright (c) mvllow
5+
---
6+
--- ==============================================================================
7+
---
8+
--- Features:
9+
---
10+
--- - Highlight UI elements based on the current mode.
11+
---
12+
--- # Setup ~
13+
---
14+
--- Modes setup can be called with your `config` table to modify default
15+
--- behaviour.
16+
---
17+
--- See |Modes.config| for `config` options and default values.
18+
19+
---@alias Scene 'copy'|'delete'|'insert'|'normal'|'replace'|'visual'
20+
21+
local Modes = {}
22+
local H = {}
223

3-
local M = {}
424
local config = {}
25+
local utils = require('modes.utils')
26+
27+
--- Module config
28+
---
29+
--- Default values:
30+
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
531
local default_config = {
632
colors = {},
733
line_opacity = {
@@ -28,6 +54,8 @@ local default_config = {
2854
'!minifiles',
2955
},
3056
}
57+
--minidoc_afterlines_end
58+
--
3159
local winhighlight = {
3260
default = {
3361
CursorLine = 'CursorLine',
@@ -81,24 +109,24 @@ local in_ignored_buffer = function()
81109
return config.ignore()
82110
end
83111
return not vim.tbl_contains(config.ignore, '!' .. vim.bo.filetype)
84-
and (vim.api.nvim_get_option_value('buftype', { buf = 0 }) ~= '' -- not a normal buffer
85-
or not vim.api.nvim_get_option_value('buflisted', { buf = 0 }) -- unlisted buffer
86-
or vim.tbl_contains(config.ignore, vim.bo.filetype))
112+
and (vim.api.nvim_get_option_value('buftype', { buf = 0 }) ~= '' -- not a normal buffer
113+
or not vim.api.nvim_get_option_value('buflisted', { buf = 0 }) -- unlisted buffer
114+
or vim.tbl_contains(config.ignore, vim.bo.filetype))
87115
end
88116

89-
M.reset = function()
90-
M.highlight('default')
117+
H.reset = function()
118+
H.highlight('default')
91119
vim.cmd.redraw()
92120
end
93121

94-
M.restore = function()
95-
local scene = M.get_scene()
96-
M.highlight(scene)
122+
H.restore = function()
123+
local scene = H.get_scene()
124+
H.highlight(scene)
97125
end
98126

99127
---Update highlights
100128
---@param scene 'default'|'copy'|'delete'|'change'|'format'|'insert'|'visual'
101-
M.highlight = function(scene)
129+
H.highlight = function(scene)
102130
if in_ignored_buffer() then
103131
return
104132
end
@@ -122,7 +150,7 @@ M.highlight = function(scene)
122150
if not config.set_number then
123151
winhl_map.CursorLineNr = nil
124152
elseif not config.set_cursorline then
125-
local detected_scene = M.get_scene()
153+
local detected_scene = H.get_scene()
126154
if scene == 'default' and detected_scene == 'visual' then
127155
winhl_map.CursorLineNr = 'ModesVisualUnfocusedCursorLineNr'
128156
end
@@ -167,7 +195,7 @@ M.highlight = function(scene)
167195
end
168196
end
169197

170-
M.get_scene = function()
198+
H.get_scene = function()
171199
local mode = vim.api.nvim_get_mode().mode
172200
if mode:match('[iR]') then
173201
return 'insert'
@@ -179,7 +207,7 @@ M.get_scene = function()
179207
return 'default'
180208
end
181209

182-
M.define = function()
210+
H.define = function()
183211
colors = {
184212
bg = config.colors.bg or utils.get_bg('Normal', 'Normal'),
185213
copy = config.colors.copy or utils.get_bg('ModesCopy', '#f5c359'),
@@ -278,7 +306,7 @@ M.define = function()
278306
end
279307
end
280308

281-
M.enable_managed_ui = function()
309+
H.enable_managed_ui = function()
282310
if in_ignored_buffer() then
283311
if config.set_cursorline then
284312
vim.o.cursorline = false
@@ -294,11 +322,11 @@ M.enable_managed_ui = function()
294322
vim.opt.guicursor:append('r-o:ModesOperator')
295323
end
296324

297-
M.restore()
325+
H.restore()
298326
end
299327
end
300328

301-
M.disable_managed_ui = function()
329+
H.disable_managed_ui = function()
302330
if config.set_cursorline then
303331
vim.o.cursorline = false
304332
end
@@ -315,10 +343,15 @@ M.disable_managed_ui = function()
315343
vim.o.guicursor = cursor
316344
end
317345

318-
M.reset()
346+
H.reset()
319347
end
320348

321-
M.setup = function(opts)
349+
--- Module setup
350+
---
351+
---@param config table|nil Module config table. See |Modes.config|.
352+
---
353+
---@usage `require('modes').setup({})` (replace `{}` with your `config` table)
354+
Modes.setup = function(opts)
322355
opts = vim.tbl_extend('keep', opts or {}, default_config)
323356
if opts.focus_only then
324357
vim.notify(
@@ -352,13 +385,13 @@ M.setup = function(opts)
352385
}
353386
end
354387

355-
M.define()
356-
M.enable_managed_ui() -- ensure enabled initially
388+
H.define()
389+
H.enable_managed_ui() -- ensure enabled initially
357390

358391
---Reset normal highlight
359392
vim.api.nvim_create_autocmd('ModeChanged', {
360393
pattern = '*:n,*:ni*',
361-
callback = M.reset,
394+
callback = H.reset,
362395
})
363396

364397
---Set operator highlights
@@ -367,52 +400,52 @@ M.setup = function(opts)
367400
callback = function()
368401
local operator = vim.v.operator
369402
if operator == 'y' then
370-
M.highlight('copy')
403+
H.highlight('copy')
371404
elseif operator == 'd' then
372-
M.highlight('delete')
405+
H.highlight('delete')
373406
elseif operator == 'c' then
374-
M.highlight('change')
407+
H.highlight('change')
375408
elseif operator:match('[=!><g]') then
376-
M.highlight('format')
409+
H.highlight('format')
377410
end
378411
end,
379412
})
380413

381414
---Set highlights when colorscheme changes
382415
vim.api.nvim_create_autocmd('ColorScheme', {
383416
pattern = '*',
384-
callback = M.define,
417+
callback = H.define,
385418
})
386419

387420
---Set insert highlight
388421
vim.api.nvim_create_autocmd('InsertEnter', {
389422
pattern = '*',
390423
callback = function()
391-
M.highlight('insert')
424+
H.highlight('insert')
392425
end,
393426
})
394427

395428
---Set visual highlight
396429
vim.api.nvim_create_autocmd('ModeChanged', {
397430
pattern = '*:[vVsS\x16\x13]',
398431
callback = function()
399-
M.highlight('visual')
432+
H.highlight('visual')
400433
end,
401434
})
402435

403436
---Enable managed UI for current window
404437
vim.api.nvim_create_autocmd({ 'WinEnter', 'FocusGained' }, {
405438
pattern = '*',
406439
callback = function()
407-
vim.schedule(M.enable_managed_ui)
440+
vim.schedule(H.enable_managed_ui)
408441
end,
409442
})
410443

411444
---Disable managed UI
412445
vim.api.nvim_create_autocmd({ 'WinLeave', 'FocusLost' }, {
413446
pattern = '*',
414-
callback = M.disable_managed_ui,
447+
callback = H.disable_managed_ui,
415448
})
416449
end
417450

418-
return M
451+
return Modes

0 commit comments

Comments
 (0)