Skip to content

Commit 05dd36d

Browse files
authored
Merge pull request #229 from Isrothy/persistent
Persistent
2 parents f9a94ce + 227f6d6 commit 05dd36d

File tree

8 files changed

+154
-66
lines changed

8 files changed

+154
-66
lines changed

README.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ vim.g.neominimap = {
184184
-- Path to the log file
185185
log_path = vim.fn.stdpath("data") .. "/neominimap.log", ---@type string
186186

187-
-- Minimap will not be created for buffers of these types
187+
-- Minimaps will not be created for buffers of these filetypes
188188
---@type string[]
189189
exclude_filetypes = {
190190
"help",
191191
"bigfile", -- For Snacks.nvim
192192
},
193193

194-
-- Minimap will not be created for buffers of these types
194+
-- Minimaps will not be created for buffers of these buftypes
195195
---@type string[]
196196
exclude_buftypes = {
197197
"nofile",
@@ -201,38 +201,42 @@ vim.g.neominimap = {
201201
"prompt",
202202
},
203203

204-
-- When false is returned, the minimap will not be created for this buffer
204+
-- When this function returns false, the minimap will not be created for this buffer.
205205
---@type fun(bufnr: integer): boolean
206206
buf_filter = function()
207207
return true
208208
end,
209209

210-
-- When false is returned, the minimap will not be created for this window
210+
-- When this function returns false, the minimap will not be created for this window.
211211
---@type fun(winid: integer): boolean
212212
win_filter = function()
213213
return true
214214
end,
215215

216-
-- When false is returned, the minimap will not be created for this tab
216+
-- When this function returns false, the minimap will not be created for this tab.
217217
---@type fun(tabid: integer): boolean
218218
tab_filter = function()
219219
return true
220220
end,
221221

222-
223222
-- How many columns a dot should span
224223
x_multiplier = 4, ---@type integer
225224

226225
-- How many rows a dot should span
227226
y_multiplier = 1, ---@type integer
228227

228+
buffer = {
229+
-- When true, the minimap will be recreated when you delete the buffer.
230+
-- When false, the minimap will be disabled for the current buffer when you delete the minimap buffer.
231+
persist = true, ---@type boolean
232+
},
233+
234+
229235
---@alias Neominimap.Config.LayoutType "split" | "float"
230236

231237
--- Either `split` or `float`
232-
--- When layout is set to `float`,
233-
--- the minimap will be created in floating windows attached to all suitable windows
234-
--- When layout is set to `split`,
235-
--- the minimap will be created in one split window
238+
--- When layout is set to `float`, minimaps will be created in floating windows attached to all suitable windows.
239+
--- When layout is set to `split`, the minimap will be created in one split window per tab.
236240
layout = "float", ---@type Neominimap.Config.LayoutType
237241

238242
--- Used when `layout` is set to `split`
@@ -242,17 +246,15 @@ vim.g.neominimap = {
242246
-- Always fix the width of the split window
243247
fix_width = false, ---@type boolean
244248

245-
-- split mode:
246-
-- left is an alias for topleft - leftmost vertical split, full height
247-
-- right is an alias for botright - rightmost vertical split, full height
248-
-- aboveleft - left split in current window
249-
-- rightbelow - right split in current window
250-
---@alias Neominimap.Config.SplitDirection "left" | "right" |
251-
--- "topleft" | "botright" | "aboveleft" | "rightbelow"
249+
---@alias Neominimap.Config.SplitDirection "left" | "right" | "topleft" | "botright" | "aboveleft" | "rightbelow"
252250
direction = "right", ---@type Neominimap.Config.SplitDirection
253251

254-
---Automatically close the split window when it is the last window
252+
--- Automatically close the split window when it is the last window.
255253
close_if_last_window = false, ---@type boolean
254+
255+
--- When true, the split window will be recreated when you close it.
256+
--- When false, the minimap will be disabled for the current tab when you close the minimap window.
257+
persist = true, ---@type boolean
256258
},
257259

258260
--- Used when `layout` is set to `float`
@@ -274,20 +276,23 @@ vim.g.neominimap = {
274276
--- Accepts all usual border style options (e.g., "single", "double")
275277
--- @type string | string[] | [string, string][]
276278
window_border = "single",
279+
280+
-- When true, the floating window will be recreated when you close it.
281+
-- When false, the minimap will be disabled for the current tab when you close the minimap window.
282+
persist = true, ---@type boolean
277283
},
278284

279-
-- For performance issue, when text changed,
280-
-- minimap is refreshed after a certain delay
285+
-- For performance, when text changes, the minimap is refreshed after a certain delay.
281286
-- Set the delay in milliseconds
282287
delay = 200, ---@type integer
283288

284289
-- Sync the cursor position with the minimap
285290
sync_cursor = true, ---@type boolean
286291

287292
click = {
288-
-- Enable mouse click on minimap
293+
-- Enable mouse click on the minimap
289294
enabled = false, ---@type boolean
290-
-- Automatically switch focus to minimap when clicked
295+
-- Automatically switch focus to the minimap when clicked
291296
auto_switch_focus = true, ---@type boolean
292297
},
293298

@@ -352,18 +357,18 @@ vim.g.neominimap = {
352357
},
353358

354359
fold = {
355-
-- Considering fold when rendering minimap
360+
-- Consider folds when rendering the minimap
356361
enabled = true, ---@type boolean
357362
},
358363

359-
---Overrite the default winopt
364+
--- Override the default window options
360365
---@param opt vim.wo
361-
---@param winid integer the window id of the source window, NOT minimap window
366+
---@param winid integer the window id of the source window, NOT the minimap window
362367
winopt = function(opt, winid) end,
363368

364-
---Overrite the default bufopt
369+
--- Override the default buffer options
365370
---@param opt vim.bo
366-
---@param bufnr integer the buffer id of the source buffer, NOT minimap buffer
371+
---@param bufnr integer the buffer id of the source buffer, NOT the minimap buffer
367372
bufopt = function(opt, bufnr) end,
368373

369374
---@type Neominimap.Map.Handler[]
@@ -660,18 +665,18 @@ neominimap components:
660665
```lua
661666
local neominimap = require("neominimap.statusline")
662667
local minimap_extension = {
663-
sections = {
664-
lualine_c = {
665-
neominimap.fullname,
666-
},
667-
lualine_z = {
668-
neominimap.position,
669-
"progress",
668+
sections = {
669+
lualine_c = {
670+
neominimap.fullname,
671+
},
672+
lualine_z = {
673+
neominimap.position,
674+
"progress",
675+
},
670676
},
671-
},
672-
filetypes = { "neominimap" },
677+
filetypes = { "neominimap" },
673678
}
674-
require('lualine').setup { extensions = { minimap_extension } }
679+
require("lualine").setup({ extensions = { minimap_extension } })
675680
```
676681

677682
### Using the Default Lualine Extension
@@ -680,7 +685,7 @@ Alternatively, you can use the default settings provided by the plugin:
680685

681686
```lua
682687
local minimap_extension = require("neominimap.statusline").lualine_default
683-
require('lualine').setup { extensions = { minimap_extension } }
688+
require("lualine").setup({ extensions = { minimap_extension } })
684689
```
685690

686691
The default Lualine extension provided by the plugin is structured as follows:

lua/neominimap/buffer/autocmds.lua

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,47 @@ M.on_buf_new = function(args)
2323
end
2424

2525
M.on_buf_unload = function(args)
26+
local config = require("neominimap.config")
2627
local logger = require("neominimap.logger")
2728
logger.log(string.format("BufUnload event triggered for buffer %d.", args.buf), vim.log.levels.TRACE)
2829
local bufnr = tonumber(args.buf)
29-
vim.schedule(function()
30-
logger.log(string.format("Wiping out minimap for buffer %d.", bufnr), vim.log.levels.TRACE)
31-
---@cast bufnr integer
32-
require("neominimap.buffer.internal").delete_minimap_buffer(bufnr)
33-
logger.log(string.format("Minimap buffer wiped out for buffer %d.", bufnr), vim.log.levels.TRACE)
34-
end)
30+
if not bufnr then
31+
return
32+
end
33+
local buffer_map = require("neominimap.buffer.buffer_map")
34+
local sbufnr = buffer_map.get_source_bufnr(bufnr)
35+
if sbufnr then
36+
logger.log("This is a minimap buffer", vim.log.levels.TRACE)
37+
if config.buffer.persist then
38+
logger.log("Not deleting minimap buffer for source buffer.", vim.log.levels.TRACE)
39+
vim.schedule(function()
40+
logger.log(
41+
string.format("Refreshing minimap buffer for source buffer %d.", sbufnr),
42+
vim.log.levels.TRACE
43+
)
44+
require("neominimap.buffer.internal").refresh_minimap_buffer(sbufnr)
45+
logger.log(
46+
string.format("Minimap buffer refreshed for source buffer %d.", sbufnr),
47+
vim.log.levels.TRACE
48+
)
49+
end)
50+
else
51+
logger.log("Deleting minimap buffer for source buffer.", vim.log.levels.TRACE)
52+
local var = require("neominimap.variables")
53+
var.b[sbufnr].enabled = false
54+
vim.schedule(function()
55+
logger.log(string.format("Deleting minimap buffer for source buffer %d.", sbufnr), vim.log.levels.TRACE)
56+
require("neominimap.buffer.internal").delete_minimap_buffer(sbufnr)
57+
logger.log(string.format("Minimap buffer deleted for source buffer %d.", sbufnr), vim.log.levels.TRACE)
58+
end)
59+
end
60+
else
61+
vim.schedule(function()
62+
logger.log(string.format("Wiping out minimap for buffer %d.", bufnr), vim.log.levels.TRACE)
63+
require("neominimap.buffer.internal").delete_minimap_buffer(bufnr)
64+
logger.log(string.format("Minimap buffer wiped out for buffer %d.", bufnr), vim.log.levels.TRACE)
65+
end)
66+
end
3567
end
3668

3769
M.on_text_change = function(args)

lua/neominimap/buffer/buffer_map.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ M.get_source_bufnr = function(mbufnr)
1919
return nil
2020
end
2121

22+
--- Check if current buffer is a minimap buffer
23+
---@param bufnr integer
24+
---@return boolean
25+
M.is_minimap_buffer = function(bufnr)
26+
return M.get_source_bufnr[bufnr] ~= nil
27+
end
28+
2229
--- Return the minimap buffer number attached to the given buffer
2330
---@param bufnr integer
2431
---@return integer?

lua/neominimap/config/internal.lua

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ local M = {
1212
-- Path to the log file
1313
log_path = vim.fn.stdpath("data") .. "/neominimap.log", ---@type string
1414

15-
-- Minimap will not be created for buffers of these types
15+
-- Minimaps will not be created for buffers of these filetypes
1616
---@type string[]
1717
exclude_filetypes = {
1818
"help",
1919
"bigfile", -- For Snacks.nvim
2020
},
2121

22-
-- Minimap will not be created for buffers of these types
22+
-- Minimaps will not be created for buffers of these buftypes
2323
---@type string[]
2424
exclude_buftypes = {
2525
"nofile",
@@ -29,19 +29,19 @@ local M = {
2929
"prompt",
3030
},
3131

32-
-- When false is returned, the minimap will not be created for this buffer
32+
-- When this function returns false, the minimap will not be created for this buffer.
3333
---@type fun(bufnr: integer): boolean
3434
buf_filter = function()
3535
return true
3636
end,
3737

38-
-- When false is returned, the minimap will not be created for this window
38+
-- When this function returns false, the minimap will not be created for this window.
3939
---@type fun(winid: integer): boolean
4040
win_filter = function()
4141
return true
4242
end,
4343

44-
-- When false is returned, the minimap will not be created for this tab
44+
-- When this function returns false, the minimap will not be created for this tab.
4545
---@type fun(tabid: integer): boolean
4646
tab_filter = function()
4747
return true
@@ -53,13 +53,17 @@ local M = {
5353
-- How many rows a dot should span
5454
y_multiplier = 1, ---@type integer
5555

56+
buffer = {
57+
-- When true, the minimap will be recreated when you delete the buffer.
58+
-- When false, the minimap will be disabled for the current buffer when you delete the minimap buffer.
59+
persist = true, ---@type boolean
60+
},
61+
5662
---@alias Neominimap.Config.LayoutType "split" | "float"
5763

5864
--- Either `split` or `float`
59-
--- When layout is set to `float`,
60-
--- the minimap will be created in floating windows attached to all suitable windows
61-
--- When layout is set to `split`,
62-
--- the minimap will be created in one split window
65+
--- When layout is set to `float`, minimaps will be created in floating windows attached to all suitable windows.
66+
--- When layout is set to `split`, the minimap will be created in one split window per tab.
6367
layout = "float", ---@type Neominimap.Config.LayoutType
6468

6569
--- Used when `layout` is set to `split`
@@ -72,8 +76,12 @@ local M = {
7276
---@alias Neominimap.Config.SplitDirection "left" | "right" | "topleft" | "botright" | "aboveleft" | "rightbelow"
7377
direction = "right", ---@type Neominimap.Config.SplitDirection
7478

75-
---Automatically close the split window when it is the last window
79+
--- Automatically close the split window when it is the last window.
7680
close_if_last_window = false, ---@type boolean
81+
82+
--- When true, the split window will be recreated when you close it.
83+
--- When false, the minimap will be disabled for the current tab when you close the minimap window.
84+
persist = true, ---@type boolean
7785
},
7886

7987
--- Used when `layout` is set to `float`
@@ -95,20 +103,23 @@ local M = {
95103
--- Accepts all usual border style options (e.g., "single", "double")
96104
--- @type string | string[] | [string, string][]
97105
window_border = "single",
106+
107+
-- When true, the floating window will be recreated when you close it.
108+
-- When false, the minimap will be disabled for the current window when you close the minimap window.
109+
persist = true, ---@type boolean
98110
},
99111

100-
-- For performance issue, when text changed,
101-
-- minimap is refreshed after a certain delay
112+
-- For performance, when text changes, the minimap is refreshed after a certain delay.
102113
-- Set the delay in milliseconds
103114
delay = 200, ---@type integer
104115

105116
-- Sync the cursor position with the minimap
106117
sync_cursor = true, ---@type boolean
107118

108119
click = {
109-
-- Enable mouse click on minimap
120+
-- Enable mouse click on the minimap
110121
enabled = false, ---@type boolean
111-
-- Automatically switch focus to minimap when clicked
122+
-- Automatically switch focus to the minimap when clicked
112123
auto_switch_focus = true, ---@type boolean
113124
},
114125

@@ -173,18 +184,18 @@ local M = {
173184
},
174185

175186
fold = {
176-
-- Considering fold when rendering minimap
187+
-- Consider folds when rendering the minimap
177188
enabled = true, ---@type boolean
178189
},
179190

180-
---Overrite the default winopt
191+
--- Override the default window options
181192
---@param opt vim.wo
182-
---@param winid integer the window id of the source window, NOT minimap window
193+
---@param winid integer the window id of the source window, NOT the minimap window
183194
winopt = function(opt, winid) end,
184195

185-
---Overrite the default bufopt
196+
--- Override the default buffer options
186197
---@param opt vim.bo
187-
---@param bufnr integer the buffer id of the source buffer, NOT minimap buffer
198+
---@param bufnr integer the buffer id of the source buffer, NOT the minimap buffer
188199
bufopt = function(opt, bufnr) end,
189200

190201
---@type Neominimap.Map.Handler[]

0 commit comments

Comments
 (0)