Skip to content

Commit

Permalink
Merge pull request #45 from LintaoAmons/config-bookmark-format
Browse files Browse the repository at this point in the history
config bookmark render format
  • Loading branch information
LintaoAmons authored Dec 26, 2024
2 parents bc19fd6 + f59ed12 commit dcdab8a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lua/bookmarks/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ local default_config = {

---@type { keymap: { [string]: string|string[] } }
treeview = {
---@type fun(node: Bookmarks.Node): string | nil
render_bookmark = nil,
-- stylua: ignore start
keymap = {
quit = { "q", "<ESC>" }, -- Close the tree view window and return to previous window
Expand Down
7 changes: 7 additions & 0 deletions lua/bookmarks/domain/location.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ M.same_line = function(a, b)
return a.line == b.line and a.path == b.path
end

---Get just the file name from a location
---@param location Bookmarks.Location
---@return string # the file name without path
function M.get_file_name(location)
return vim.fn.fnamemodify(location.path, ":t")
end

return M
6 changes: 0 additions & 6 deletions lua/bookmarks/tree/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ local function register_local_shortcuts(buf)
end
end

local function clean_tree_cache(buf)
vim.b[buf]._bm_context = nil
vim.b[buf]._bm_tree_cut = nil
end

---Toggle the tree view
---Toggle the tree view
function M.toggle()
local cur_window = vim.api.nvim_get_current_win()
Expand Down
7 changes: 6 additions & 1 deletion lua/bookmarks/tree/render/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local Context = require("bookmarks.tree.ctx")
local Repo = require("bookmarks.domain.repo")
local Highlight = require("bookmarks.tree.render.highlight")
local Location = require("bookmarks.domain.location")
local INTENT = " "
local M = {}

Expand Down Expand Up @@ -37,7 +38,8 @@ end
local function render_bookmark(node)
local book_icon = ""

local name = node.name
local filename = Location.get_file_name(node.location)
local name = filename .. ": " .. node.name
if node.name == "" then
name = "[Untitled]"
end
Expand Down Expand Up @@ -71,6 +73,9 @@ end
---@return string
local function render_context(node, deep, active_list_id)
if node.type == "bookmark" then
if vim.g.bookmarks_config.treeview.render_bookmark then
return string.rep(INTENT, deep) .. vim.g.bookmarks_config.treeview.render_bookmark(node)
end
return string.rep(INTENT, deep) .. render_bookmark(node)
else
return string.rep(INTENT, deep) .. render_list(node, active_list_id)
Expand Down

0 comments on commit dcdab8a

Please sign in to comment.