chentoast / marks.nvim

A better user experience for viewing and interacting with Vim marks.
MIT License
848 stars 43 forks source link

Toggle signs + clearing virtual text #26

Closed lcrockett closed 2 years ago

lcrockett commented 2 years ago

I'm trying to hide the bookmark signs + virtual text upon a BufLeave,FocusLost and showing them again upon a BufEnter,FocusGained as I do with other plugins like vim-gitgutter and Neovim's LSP decorations. This prevents unnecessary clutter on windows with many simultaneous splits opened.

I'm using the snippet below to toggle signs and remove the virtual text on a per-buffer basis.

Upon BufLeave,FocusLost:

local namespace_id_bookmarks_one = vim.api.nvim_create_namespace('Bookmarks1')
vim.api.nvim_buf_clear_namespace(0, namespace_id_bookmarks_one, 0, -1)

vim.cmd('MarksToggleSigns')

Upon BufEnter,FocusGained:

vim.cmd('MarksToggleSigns')

I'm running into a few items however with bookmarks set via (lua require('marks').set_bookmark1()):

  1. The commmand MarksToggleSigns doesn't seem to do anything as the bookmark signs stay put
  2. Using vim.api.nvim_buf_clear_namespace, leaving the buffer and then returning to it, the following persistent error message pops up: (Error executing vim.schedule lua callback: ...site/pack/packer/start/marks.nvim/lua/marks/bookmark.lua:233: attempt to perform arithmetic on local 'line' (a nil value)% )
  3. Set bookmarks don't seem to survive Neovim restarts (not sure if bookmarks are supposed to survive Neovim sessions, would be a fantastic-to-have feature however)

Would it additionally be possible to have additional commands MarksSignsBufferDisable + MarksSignsBufferEnable to allow for more control on when to show signs on a per-buffer basis ? This is similar to vim-gitgutter and would allow for non-interactive control of signs display as opposed to the MarksToggleSigns command which is very useful interactively.

Currently used configuration:

require('marks').setup {
  default_mappings = false,
  force_write_shada = true,
  refresh_interval = 250,
  sign_priority = {
    bookmark = 4,
    builtin = 4,
    lower = 4,
    upper = 4
  },
  bookmark_1 = {
    sign = '⚑',
    virt_text = '    ⚑ Bookmarks'
  }
}

Cheers

chentoast commented 2 years ago

The commmand MarksToggleSigns doesn't seem to do anything as the bookmark signs stay put

I have a WIP PR that will fix this, and allow toggling signs on a per buffer basis.

Using vim.api.nvim_buf_clear_namespace, leaving the buffer and then returning to it, the following persistent error message pops up: (Error executing vim.schedule lua callback: ...site/pack/packer/start/marks.nvim/lua/marks/bookmark.lua:233: attempt to perform arithmetic on local 'line' (a nil value)% )

This seems like a bad idea. The extmark namespaces used by the plugin are an implementation detail and shouldn't be modified by users. In this case, you have deleted all of the extmarks placed by the plugin without it knowing; when it then checks to see the positions of these extmarks, it runs into an error since they are no longer there.

Set bookmarks don't seem to survive Neovim restarts (not sure if bookmarks are supposed to survive Neovim sessions, would be a fantastic-to-have feature however)

This is on the todo list, but no timeline.

lcrockett commented 2 years ago

That's great, looking forward to trying out the PR or merge for both the per-buffer toggling of signs and being able to restore bookmarks in between sessions.

Regarding clearing the extmark namespace; i'd reckon that the upcoming per-buffer basis toggling will make the need for this redundant so i'll just wait for that to come out to continue testing.

Cheers !