Skip to content

Commit

Permalink
Merge pull request #138 from Isrothy/fix-width
Browse files Browse the repository at this point in the history
feat: Allow to fix minimap width
  • Loading branch information
Isrothy authored Aug 22, 2024
2 parents fae141f + ff71476 commit 3030e8d
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 89 deletions.
102 changes: 35 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Show search results:

</details>

Float window layout:
Show minimaps in float windows:

<details>
<summary>Click to expand</summary>
Expand All @@ -69,7 +69,7 @@ Float window layout:

</details>

Split window layout:
Show minimaps in a split window:

<details>
<summary>Click to expand</summary>
Expand All @@ -93,22 +93,14 @@ Split window layout:

## Dependencies

<details>
<summary>Click to expand</summary>

- A font that supports dispalys **Braille Patterns** Unicode block
- Optional: [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) for highlighting
- Optional: [gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim) for Git integration

</details>

## Installation

With Lazy:

<details>
<summary>Click to expand</summary>

```lua
---@module "neominimap.config.meta"
{
Expand All @@ -118,34 +110,34 @@ With Lazy:
lazy = false, -- NOTE: NO NEED to Lazy load
-- Optional
keys = {
-- Global Minimap Controls
{ "<leader>nm", "<cmd>Neominimap toggle<cr>", desc = "Toggle global minimap" },
{ "<leader>no", "<cmd>Neominimap on<cr>", desc = "Enable global minimap" },
{ "<leader>nc", "<cmd>Neominimap off<cr>", desc = "Disable global minimap" },
{ "<leader>nr", "<cmd>Neominimap refresh<cr>", desc = "Refresh global minimap" },

-- Window-Specific Minimap Controls
{ "<leader>nwt", "<cmd>Neominimap winToggle<cr>", desc = "Toggle minimap for current window" },
{ "<leader>nwr", "<cmd>Neominimap winRefresh<cr>", desc = "Refresh minimap for current window" },
{ "<leader>nwo", "<cmd>Neominimap winOn<cr>", desc = "Enable minimap for current window" },
{ "<leader>nwc", "<cmd>Neominimap winOff<cr>", desc = "Disable minimap for current window" },

-- Tab-Specific Minimap Controls
{ "<leader>ntt", "<cmd>Neominimap tabToggle<cr>", desc = "Toggle minimap for current tab" },
{ "<leader>ntr", "<cmd>Neominimap tabRefresh<cr>", desc = "Refresh minimap for current tab" },
{ "<leader>nto", "<cmd>Neominimap tabOn<cr>", desc = "Enable minimap for current tab" },
{ "<leader>ntc", "<cmd>Neominimap tabOff<cr>", desc = "Disable minimap for current tab" },

-- Buffer-Specific Minimap Controls
{ "<leader>nbt", "<cmd>Neominimap bufToggle<cr>", desc = "Toggle minimap for current buffer" },
{ "<leader>nbr", "<cmd>Neominimap bufRefresh<cr>", desc = "Refresh minimap for current buffer" },
{ "<leader>nbo", "<cmd>Neominimap bufOn<cr>", desc = "Enable minimap for current buffer" },
{ "<leader>nbc", "<cmd>Neominimap bufOff<cr>", desc = "Disable minimap for current buffer" },

---Focus Controls
{ "<leader>nf", "<cmd>Neominimap focus<cr>", desc = "Focus on minimap" },
{ "<leader>nu", "<cmd>Neominimap unfocus<cr>", desc = "Unfocus minimap" },
{ "<leader>ns", "<cmd>Neominimap toggleFocus<cr>", desc = "Switch focus on minimap" },
-- Global Minimap Controls
{ "<leader>nm", "<cmd>Neominimap toggle<cr>", desc = "Toggle global minimap" },
{ "<leader>no", "<cmd>Neominimap on<cr>", desc = "Enable global minimap" },
{ "<leader>nc", "<cmd>Neominimap off<cr>", desc = "Disable global minimap" },
{ "<leader>nr", "<cmd>Neominimap refresh<cr>", desc = "Refresh global minimap" },

-- Window-Specific Minimap Controls
{ "<leader>nwt", "<cmd>Neominimap winToggle<cr>", desc = "Toggle minimap for current window" },
{ "<leader>nwr", "<cmd>Neominimap winRefresh<cr>", desc = "Refresh minimap for current window" },
{ "<leader>nwo", "<cmd>Neominimap winOn<cr>", desc = "Enable minimap for current window" },
{ "<leader>nwc", "<cmd>Neominimap winOff<cr>", desc = "Disable minimap for current window" },

-- Tab-Specific Minimap Controls
{ "<leader>ntt", "<cmd>Neominimap tabToggle<cr>", desc = "Toggle minimap for current tab" },
{ "<leader>ntr", "<cmd>Neominimap tabRefresh<cr>", desc = "Refresh minimap for current tab" },
{ "<leader>nto", "<cmd>Neominimap tabOn<cr>", desc = "Enable minimap for current tab" },
{ "<leader>ntc", "<cmd>Neominimap tabOff<cr>", desc = "Disable minimap for current tab" },

-- Buffer-Specific Minimap Controls
{ "<leader>nbt", "<cmd>Neominimap bufToggle<cr>", desc = "Toggle minimap for current buffer" },
{ "<leader>nbr", "<cmd>Neominimap bufRefresh<cr>", desc = "Refresh minimap for current buffer" },
{ "<leader>nbo", "<cmd>Neominimap bufOn<cr>", desc = "Enable minimap for current buffer" },
{ "<leader>nbc", "<cmd>Neominimap bufOff<cr>", desc = "Disable minimap for current buffer" },

---Focus Controls
{ "<leader>nf", "<cmd>Neominimap focus<cr>", desc = "Focus on minimap" },
{ "<leader>nu", "<cmd>Neominimap unfocus<cr>", desc = "Unfocus minimap" },
{ "<leader>ns", "<cmd>Neominimap toggleFocus<cr>", desc = "Switch focus on minimap" },
},
init = function()
-- The following options are recommended when layout == "float"
Expand All @@ -161,8 +153,6 @@ With Lazy:
}
```

</details>

## Configuration

The following is the default configuration.
Expand All @@ -176,10 +166,10 @@ The following is the default configuration.
auto_enable = true, ---@type boolean

-- Log level
log_level = vim.log.levels.OFF, ---@type integer
log_level = vim.log.levels.OFF, ---@type Neominimap.Log.Levels

-- Notification level
notification_level = vim.log.levels.INFO, ---@type integer
notification_level = vim.log.levels.INFO, ---@type Neominimap.Log.Levels

-- Path to the log file
log_path = vim.fn.stdpath("data") .. "/neominimap.log", ---@type string
Expand Down Expand Up @@ -231,6 +221,9 @@ The following is the default configuration.
split = {
minimap_width = 20, ---@type integer

-- Always fix the width of the split window
fix_width = false, ---@type boolean

---@alias Neominimap.Config.SplitDirection "left" | "right"
direction = "right", ---@type Neominimap.Config.SplitDirection

Expand Down Expand Up @@ -461,9 +454,6 @@ These are the corresponding commands in the Lua API.

## How it works

<details>
<summary>Click to expand</summary>

### Caching Minimap Buffers

For every file opened, the plugin generates a corresponding minimap buffer.
Expand Down Expand Up @@ -495,8 +485,6 @@ As a result, unshown highlights may be displayed in the minimap,
leading to potential inconsistencies
between the highlights in the minimap and those in the buffer.

</details>

## Tips

Checkout the wiki page for more details. [wiki](https://github.com/Isrothy/neominimap.nvim/wiki/Tips)
Expand Down Expand Up @@ -544,9 +532,6 @@ Checkout the wiki page for more details. [wiki](https://github.com/Isrothy/neomi

## TODO

<details>
<summary>Click to expand</summary>

- [x] LSP integration
- [x] TreeSitter integration
- [x] Git integration
Expand All @@ -557,13 +542,8 @@ Checkout the wiki page for more details. [wiki](https://github.com/Isrothy/neomi
- [ ] Performance improvements
- [ ] More test cases

</details>

## Non-Goals

<details>
<summary>Click to expand</summary>

- Scrollbar.
Use [satellite.nvim](https://github.com/lewis6991/satellite.nvim),
[nvim-scrollview](https://github.com/dstein64/nvim-scrollview)
Expand All @@ -574,24 +554,14 @@ Checkout the wiki page for more details. [wiki](https://github.com/Isrothy/neomi
Since a screen bound is a windowwise thing,
it's not impossible to display them by highlights.

</details>

## Limitations

<details>
<summary>Click to expand</summary>

- Updating Folds Immediately.
Neovim does not provide a fold event. Therefore, this plugin cannot update
immediately whenever fold changes in a buffer.

</details>

## Similar projects

<details>
<summary>Click to expand</summary>

- [codewindow.nvim](https://github.com/gorbit99/codewindow.nvim)
- Codewindow.nvim renders the minimap whenever focus is switched to a
different window or the buffer is switched. In contrast, this plugin caches
Expand Down Expand Up @@ -623,8 +593,6 @@ Checkout the wiki page for more details. [wiki](https://github.com/Isrothy/neomi
- Minimap.vim shows the minimap in a split window but does not support a
floating window. This plugin supports both.

</details>

## Acknowledgements

Thanks to [gorbit99](https://github.com/gorbit99) for
Expand Down
7 changes: 5 additions & 2 deletions lua/neominimap/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local M = {
auto_enable = true, ---@type boolean

-- Log level
log_level = vim.log.levels.OFF, ---@type integer
log_level = vim.log.levels.OFF, ---@type Neominimap.Log.Levels

-- Notification level
notification_level = vim.log.levels.INFO, ---@type integer
notification_level = vim.log.levels.INFO, ---@type Neominimap.Log.Levels

-- Path to the log file
log_path = vim.fn.stdpath("data") .. "/neominimap.log", ---@type string
Expand Down Expand Up @@ -59,6 +59,9 @@ local M = {
split = {
minimap_width = 20, ---@type integer

-- Always fix the width of the split window
fix_width = false, ---@type boolean

---@alias Neominimap.Config.SplitDirection "left" | "right"
direction = "right", ---@type Neominimap.Config.SplitDirection

Expand Down
5 changes: 3 additions & 2 deletions lua/neominimap/config/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ local M = {}
---@class (exact) Neominimap.UserConfig
---@field auto_enable? boolean
---@field log_path? string
---@field log_level? integer
---@field notification_level? integer
---@field log_level? Neominimap.Log.Levels
---@field notification_level? Neominimap.Log.Levels
---@field exclude_filetypes? string[]
---@field exclude_buftypes? string[]
---@field buf_filter? fun(bufnr: integer): boolean
Expand All @@ -27,6 +27,7 @@ local M = {}

---@class (exact) Neominimap.SplitConfig
---@field minimap_width? integer
---@field fix_width? boolean
---@field direction? Neominimap.Config.SplitDirection
---@field close_if_last_window? boolean

Expand Down
1 change: 1 addition & 0 deletions lua/neominimap/config/validator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ M.validate_config = function(cfg)
split = { cfg.split, "table" },
["split.direction"] = { cfg.split.direction, "string" },
["split.minimap_width"] = { cfg.split.minimap_width, "number" },
["split.fix_width"] = { cfg.split.fix_width, "boolean" },
["split.close_if_last_window"] = { cfg.split.close_if_last_window, "boolean" },

float = { cfg.float, "table" },
Expand Down
13 changes: 9 additions & 4 deletions lua/neominimap/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ local M = {}
local config = require("neominimap.config")
local levels = vim.log.levels

---@type table<integer, string>
---@enum level
vim.log.levels = vim.log.levels

---@alias Neominimap.Log.Levels 0|1|2|3|4|5

---@type table<Neominimap.Log.Levels, string>
local level_names = {
[levels.TRACE] = "TRACE",
[levels.DEBUG] = "DEBUG",
Expand All @@ -13,7 +18,7 @@ local level_names = {
}

---@param msg string
---@param level integer?
---@param level Neominimap.Log.Levels?
M.log = function(msg, level)
local filepath = config.log_path
level = level or levels.INFO
Expand All @@ -30,7 +35,7 @@ M.log = function(msg, level)
end

---@param msg string
---@param level integer?
---@param level Neominimap.Log.Levels?
M.notify = function(msg, level)
level = level or levels.INFO
if level >= config.notification_level then
Expand All @@ -39,7 +44,7 @@ M.notify = function(msg, level)
end

---@param msg string
---@param level integer?
---@param level Neominimap.Log.Levels?
M.log_and_notify = function(msg, level)
M.log(msg, level)
M.notify(msg, level)
Expand Down
22 changes: 20 additions & 2 deletions lua/neominimap/window/split/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,28 @@ M.create_autocmds = function()
end)
end,
})

if config.split.fix_width then
api.nvim_create_autocmd("WinResized", {
group = "Neominimap",
desc = "Reset minimap width when window is resized",
callback = function()
local logger = require("neominimap.logger")
logger.log("WinResized event triggered.", vim.log.levels.TRACE)
vim.schedule(function()
logger.log("Resetting minimap width.", vim.log.levels.TRACE)
require("neominimap.window.split.internal").reset_minimap_width()
logger.log("Minimap width reset.", vim.log.levels.TRACE)
end)
end,
})
end

api.nvim_create_autocmd("User", {
group = "Neominimap",
pattern = { "MinimapBufferCreated", "MinimapBufferDeleted" },
callback = function(args)
desc = "Refresh source window when buffer is created or deleted",
callback = function()
local logger = require("neominimap.logger")
logger.log(
"User Neominimap event triggered. patter: MinimapBufferCreated or MinimapBufferDeleted",
Expand All @@ -100,7 +118,7 @@ M.create_autocmds = function()
group = "Neominimap",
pattern = "MinimapBufferTextUpdated",
desc = "Reset cursor line when buffer text is updated",
callback = function(args)
callback = function()
local logger = require("neominimap.logger")
logger.log("User Neominimap event triggered. patter: BufferTextUpdated", vim.log.levels.TRACE)
vim.schedule(function()
Expand Down
Loading

0 comments on commit 3030e8d

Please sign in to comment.