diff --git a/lua/bookmarks/api.lua b/lua/bookmarks/api.lua index 21e5f27..ebe9e6c 100644 --- a/lua/bookmarks/api.lua +++ b/lua/bookmarks/api.lua @@ -83,7 +83,16 @@ local function goto_bookmark(bookmark, opts) local open_method = opts.open_method or "e" local projects = repo.project.findall() local fullpath = domain.bookmark.fullpath(bookmark, projects) + + local curren_bufnr = vim.api.nvim_get_current_buf() + -- check if the buffer have unsaved changes + if vim.api.nvim_buf_get_option(curren_bufnr, "modified") then + utils.log("Please save the current buffer before goto bookmark", vim.log.levels.WARN) + return + end + vim.api.nvim_exec2(open_method .. " " .. fullpath, {}) + pcall(vim.api.nvim_win_set_cursor, 0, { bookmark.location.line, bookmark.location.col }) vim.cmd("norm! zz") bookmark.visited_at = os.time()