From d6bbd5420bb78e210f928c6be0fc4d95cf46d1d2 Mon Sep 17 00:00:00 2001 From: Kim Gert Nielsen Date: Mon, 26 Feb 2024 12:27:59 +0100 Subject: [PATCH] fix: Added event for better updates - Also added an example for telescope if anyone should need it --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ TODO.md | 2 -- lua/marlin/init.lua | 4 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 355bab3..e843f98 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,52 @@ But they can also be change if you want to write your own sorter. Choice is yours +### But there is no UI + +Correct. I'm not planning on creating a UI but if you really want one you can easily create it. + +Example using telescope + +```lua + vim.keymap.set("n", "fx", function() + local conf = require("telescope.config").values + local action_state = require("telescope.actions.state") + local results = require("marlin").get_indexes() + + local index = 0 + require("telescope.pickers") + .new({}, { + prompt_title = "Marlin", + finder = require("telescope.finders").new_table({ + results = results, + entry_maker = function(entry) + index = index + 1 + return { + value = entry, + ordinal = index ..":" .. entry.filename, + lnum = entry.row, + col = entry.col + 1, + filename = entry.filename, + display = index .. ":" .. entry.filename .. ":" .. entry.row .. ":" .. entry.col, + } + end, + }), + previewer = conf.grep_previewer({}), + sorter = conf.generic_sorter({}), + attach_mappings = function(_, map) + map("i", "d", function(bufnr) + local current_picker = action_state.get_current_picker(bufnr) + current_picker:delete_selection(function(selection) + require("marlin").remove(selection.filename) + end) + end) + return true + end, + }) + :find() + end, { desc = "Telescope marlin" }) +``` + ### Why yet another .. When I first saw harpoon I was immediately hooked but I missed a few key features. diff --git a/TODO.md b/TODO.md index b19e0d3..4640904 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1 @@ # TODO - - - Currently no GUI and there might not be one diff --git a/lua/marlin/init.lua b/lua/marlin/init.lua index 18d4594..a7fb436 100644 --- a/lua/marlin/init.lua +++ b/lua/marlin/init.lua @@ -72,7 +72,7 @@ local default = { local get_cursor = function() local cursor = vim.api.nvim_win_get_cursor(0) - return cursor[1] or 1, cursor[2] or 0 + return cursor[1], cursor[2] end local save = function(m) @@ -327,7 +327,7 @@ marlin.setup = function(opts) end local augroup = vim.api.nvim_create_augroup("marlin", {}) - vim.api.nvim_create_autocmd({ "BufLeave", "VimLeavePre" }, { + vim.api.nvim_create_autocmd({ "CursorMoved", "BufLeave", "VimLeavePre" }, { group = augroup, pattern = "*", callback = function(_)