From a87f73c3b23a09c6566b61db9ef1ca4b3948c359 Mon Sep 17 00:00:00 2001 From: hedy Date: Thu, 2 Nov 2023 17:46:27 +0800 Subject: [PATCH] BREAKING,feat: Customizable guide markers See readme --- README.md | 18 +++++++++++++++--- lua/symbols-outline/config.lua | 10 +++++++++- lua/symbols-outline/parser.lua | 26 ++++++++++++++------------ lua/symbols-outline/ui.lua | 7 ------- lua/symbols-outline/view.lua | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c7388c6..ed0e1b8 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ Features/Changes: - simrat39/symbols-outline.nvim#207 - Feat: when `auto_close=true` only auto close if `goto_location` is used (where -focus changed), and not for `focus_location` (simrat39/symbols-outline.nvim#119) + focus changed), and not for `focus_location` + (simrat39/symbols-outline.nvim#119) - Feat: Cursorline option for the outline window @@ -64,6 +65,9 @@ focus changed), and not for `focus_location` (simrat39/symbols-outline.nvim#119) - Feat: Added function and command to show provider and outline window status, somewhat like `:LspInfo`. +- BREAKING: Marker icons used for guides can now be customized. `show_guides` + deprecated in favor of `guides.enabled`. + Fixes: - Fix symbol preview (simrat39/symbols-outline.nvim#176) @@ -284,8 +288,16 @@ local opts = { -- Whether to highlight the currently hovered symbol (high cpu usage) highlight_hovered_item = true, - -- Whether to show outline guides - show_guides = true, + -- Options for outline guides + guides = { + enabled = true, + markers = { + bottom = '└', + middle = '├', + vertical = '│', + horizontal = '─', + }, + }, -- Automatically open preview of code on hover auto_preview = false, -- Automatically open hover_symbol when opening toggle_preview (see keymaps). diff --git a/lua/symbols-outline/config.lua b/lua/symbols-outline/config.lua index 029b4d9..c24fd85 100644 --- a/lua/symbols-outline/config.lua +++ b/lua/symbols-outline/config.lua @@ -6,7 +6,15 @@ M.defaults = { position = 'right', width = 25, highlight_hovered_item = true, - show_guides = true, + guides = { + enabled = true, + markers = { + bottom = '└', + middle = '├', + vertical = '│', + horizontal = '─', + }, + }, border = 'single', relative_width = true, auto_close = false, diff --git a/lua/symbols-outline/parser.lua b/lua/symbols-outline/parser.lua index 50ad125..339c70d 100644 --- a/lua/symbols-outline/parser.lua +++ b/lua/symbols-outline/parser.lua @@ -113,19 +113,21 @@ function M.get_lines(flattened_outline_items) for index, _ in ipairs(line) do -- all items start with a space (or two) - if config.options.show_guides then - -- makes the guides + if config.options.guides.enabled then + -- makes the guides and add guide markers + local guide_markers = config.options.guides.markers if index == 1 then line[index] = ' ' - -- i f index is last, add a bottom marker if current item is last, + -- if index is last, add a bottom marker if current item is last, -- else add a middle marker elseif index == #line then -- add fold markers - if config.options.fold_markers and folding.is_foldable(node) then + local fold_markers = config.options.fold_markers + if fold_markers and folding.is_foldable(node) then if folding.is_folded(node) then - line[index] = config.options.fold_markers[1] + line[index] = fold_markers[1] else - line[index] = config.options.fold_markers[2] + line[index] = fold_markers[2] end add_guide_hl( @@ -136,16 +138,16 @@ function M.get_lines(flattened_outline_items) -- the root level has no vertical markers elseif depth > 1 then if node.isLast then - line[index] = ui.markers.bottom + line[index] = guide_markers.bottom add_guide_hl( running_length, - running_length + vim.fn.strlen(ui.markers.bottom) - 1 + running_length + vim.fn.strlen(guide_markers.bottom) - 1 ) else - line[index] = ui.markers.middle + line[index] = guide_markers.middle add_guide_hl( running_length, - running_length + vim.fn.strlen(ui.markers.middle) - 1 + running_length + vim.fn.strlen(guide_markers.middle) - 1 ) end end @@ -153,11 +155,11 @@ function M.get_lines(flattened_outline_items) -- vertical marker because there are items under us and we need -- to point to those elseif not node.hierarchy[index] and depth > 1 then - line[index + marker_space] = ui.markers.vertical + line[index + marker_space] = guide_markers.vertical add_guide_hl( running_length - 1 + 2 * marker_space, running_length - + vim.fn.strlen(ui.markers.vertical) + + vim.fn.strlen(guide_markers.vertical) - 1 + 2 * marker_space ) diff --git a/lua/symbols-outline/ui.lua b/lua/symbols-outline/ui.lua index 325f901..e4a93e3 100644 --- a/lua/symbols-outline/ui.lua +++ b/lua/symbols-outline/ui.lua @@ -1,12 +1,5 @@ local M = {} -M.markers = { - bottom = '└', - middle = '├', - vertical = '│', - horizontal = '─', -} - M.hovered_hl_ns = vim.api.nvim_create_namespace 'hovered_item' function M.clear_hover_highlight(bufnr) diff --git a/lua/symbols-outline/view.lua b/lua/symbols-outline/view.lua index b4d1abb..4886440 100644 --- a/lua/symbols-outline/view.lua +++ b/lua/symbols-outline/view.lua @@ -32,7 +32,7 @@ function View:setup_view() vim.api.nvim_win_set_option(self.winnr, 'wrap', config.options.wrap) vim.api.nvim_win_set_option(self.winnr, 'linebreak', true) -- only has effect when wrap=true vim.api.nvim_win_set_option(self.winnr, 'breakindent', true) -- only has effect when wrap=true - -- Would be nice to use ui.markers.vertical as part of showbreak to keep + -- Would be nice to use guides.markers.vertical as part of showbreak to keep -- continuity of the tree UI, but there's currently no way to style the -- color, apart from globally overriding hl-NonText, which will potentially -- mess with other theme/user settings. So just use empty spaces for now.