HampusHauffman / block.nvim

209 stars 2 forks source link

With lazy.nvim, I have to `require('block').setup()` again to ensure that all commands `:Block{On,Off}` will have effect. #7

Open nyngwang opened 1 year ago

nyngwang commented 1 year ago

Problem

As title. This is my config:

use {
  'HampusHauffman/block.nvim',
  config = function ()
    require('block').setup {
      percent = 1.15, -- e.g. 0.8 would change each box to be 20% darker than the last and 1.2 would be 20% brighter.
      depth = 4, -- after this the colors reset.
      automatic = false,
    }
  end
}

Demo

https://github.com/HampusHauffman/block.nvim/assets/24765272/c03842f2-6c2f-45ff-8828-d9aa086a5e12

Additional Context

I thought this might have something to do with lua_ls (the LSP server of Lua I'm using) but it turned out I was wrong.

@HampusHauffman

nyngwang commented 1 year ago

The current workaround is to create an autocmd on BufEnter for it. It's BufEnter instead of LspAttach to prevent those extmarks from disappearing when switching between sessions:

vim.api.nvim_create_autocmd({ 'BufEnter' }, {
  callback = function ()
    require('block').setup {
      -- ...
    }
  end
})

I also tried adding a new file at the root plugin/block.lua(provided below) but it doesn't work. (This is a convention adopted by probably every Neovim plugin):

plugin/block.lua ```lua if vim.fn.has("nvim-0.9") == 0 then return end if vim.g.loaded_block_nvim ~= nil then return end require('neo-zoom') vim.g.loaded_block_nvim = 1 ```
HampusHauffman commented 1 year ago

plugin/block.lua

if vim.fn.has("nvim-0.9") == 0 then
  return
end

if vim.g.loaded_block_nvim ~= nil then
  return
end

require('neo-zoom')

vim.g.loaded_block_nvim = 1

Good stuff. thank you! I'll look more at this tomorrow :)