bookmarks.nvim icon indicating copy to clipboard operation
bookmarks.nvim copied to clipboard

Add scoped bookmarks

Open ten3roberts opened this issue 1 year ago • 11 comments

Fixes: #7

ten3roberts avatar Nov 08 '23 12:11 ten3roberts

Something to consider is if we should make scoped the default, or keep the current global behavior.

What do you think @tomasky?

From what I've seen most other plugins do per-cwd state, such as harpoon, neogit, and likely a few others

ten3roberts avatar Nov 08 '23 13:11 ten3roberts

I tried this feature branch, and if scoped is set to false, an error will occur

image

xlboy avatar Jan 07 '24 13:01 xlboy

Thank you :heart:

I will have a look at it

ten3roberts avatar Jan 07 '24 14:01 ten3roberts

Alright, I should have fixed your issue now

ten3roberts avatar Jan 09 '24 08:01 ten3roberts

So good! This is working for me. It breaks the telescope extension though.

Setting scope to false doesn't return an error, however when returning the bookmarks in the quick fix window, I still only see the scoped bookmarks, and not all (ie globally)

require('bookmarks').setup {
  -- sign_priority = 8,  --set bookmark sign priority to cover other sign
  scoped = false,
  save_file = vim.fn.expand "$HOME/.config/nvim/bookmarks", -- bookmarks save file path
  keywords =  {
    ["@t"] = "☑️ ", -- mark annotation startswith @t ,signs this icon as `Todo`
    ["@w"] = "⚠️ ", -- mark annotation startswith @w ,signs this icon as `Warn`
    ["@f"] = "⛏ ", -- mark annotation startswith @f ,signs this icon as `Fix`
    ["@n"] = " ", -- mark annotation startswith @n ,signs this icon as `Note`
  },
  on_attach = function(bufnr)
    local bm = require "bookmarks"
    local map = vim.keymap.set
    map("n","mm",bm.bookmark_toggle) -- add or remove bookmark at current line
    map("n","mi",bm.bookmark_ann) -- add or edit mark annotation at current line
    map("n","mc",bm.bookmark_clean) -- clean all marks in local buffer
    map("n","mn",bm.bookmark_next) -- jump to next mark in local buffer
    map("n","mp",bm.bookmark_prev) -- jump to previous mark in local buffer
    map("n","ml",bm.bookmark_list) -- show marked file list in quickfix window
  end
}

There is a global bookmark file too

bookmarks
├── %%global%%
├── %Users%tjex%.config%nvim
└── %Users%tjex%.local%src%zk-org%zk.git%main

tjex avatar Jan 31 '24 16:01 tjex

I see, would you want the global and scope bookmarks to coexist and be loaded at the same time?

For now, it is just one or the other as a means for the user to make one decision of their preference initially.

Would you like them to coexist? if so, how would creating a bookmark behave and when or how would you want it to decide for where to store it?

ten3roberts avatar Jan 31 '24 16:01 ten3roberts

I think it can be useful to have the option to switch between global and scoped mode, even by means of switching scoped = <bool> and restarting neovim or sourcing the config file.

I see it as a similar UX to browser bookmarks, where you can store a bookmark in a folder, which keeps it available through the context of that folder name, but we can also search globally for it directly in the address bar.

I think there may be more value in appending all bookmarks added to the global file, even when in scoped mode. That way, we can start in global mode and be able to jump around everywhere, or start in scoped mode and navigate to each root directory to then work.

Although, I do see the issue with that, in that the global bookmark file will become bloated.

Perhaps there could be a keybind that specifically adds a bookmark to the global file, even when in scoped mode?

That way, even in scoped mode, we can make an executive decision that we would like to be able to access this document from anywhere. This would keep the global bookmark file clean, while also maintaining some value / possibility to switch back to a global mode in the future if we want to.

If it had to be one or the other though, I would agree that scoped bookmarks are more valuable.

tjex avatar Jan 31 '24 17:01 tjex

Personally, I think I prefer the clean separation between scoped and global bookmarks. With a ton of scoped bookmarks, I would rather not have them pollute the global ones.

That being said, I think this PR providing scoped bookmarks is a huge improvement over the default workflow. I would rather see this being merged sooner rather than later, and further improvements can be made with subsequent PRs, if needed.

Hoping @tomasky can give it a quick look for review.

jemag avatar Feb 04 '24 18:02 jemag

Alright, I should have fixed your issue now

May I ask why change session does not isolate bookmarks from different CWDs? It only works when starting nvim from different directories, but my cwd also changed with the session change. But harpoon works fine, I tryed vim-bookmark and still the same.

xzbdmw avatar Feb 20 '24 06:02 xzbdmw

tested, using your branch, thanks a lot @tomasky merge please

jacobrreed avatar Apr 01 '24 18:04 jacobrreed

Thanks for providing this "scoped bookmarks" feature.

It also requires a change to the config (example):

        save_file = vim.fn.expand("$HOME/.bookmarks"), -- this causes an error (see below)

        save_file = ".bookmarks", -- bookmarks save file path

Error message:

Error executing luv callback:
...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:240: bookmarks.save_file must be a directory
stack traceback:
	[C]: in function 'assert'
	...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:240: in function <...share/nvim/lazy/bookmarks.nvim/lua/bookmarks/actions.lua:227>

I also prefer scoped = true, as a default, as jumping to global uppercase marks or bookmarks can cause "swap file already exist" warnings if the target file is already open in another vim instance.

yungthai avatar Apr 13 '24 06:04 yungthai