Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If lazy-loaded pounce does not work for the first time #1

Open
khalidchawtany opened this issue Jan 17, 2022 · 5 comments
Open

If lazy-loaded pounce does not work for the first time #1

khalidchawtany opened this issue Jan 17, 2022 · 5 comments

Comments

@khalidchawtany
Copy link

If lazy-loaded pounce does not work for the first time. However, after the first try everything works as expected.
Here is my config using packer:

vim.cmd [[
	nmap <leader>p <cmd>Pounce<CR>
	vmap <leader>p <cmd>Pounce<CR>
	omap <leader>P <cmd>Pounce<CR>
  ]]

use {
  "rlane/pounce.nvim",
  cmd = {"Pounce"},
  config = function()
    require "pounce".setup {
      accept_keys = "JFKDLSAHGNUVRBYTMICEOXWPQZ",
      debug = false
    }
    vim.cmd [[
	nmap <leader>p <cmd>Pounce<CR>
	vmap <leader>p <cmd>Pounce<CR>
	omap <leader>P <cmd>Pounce<CR>
  ]]
  end
}
@rlane
Copy link
Owner

rlane commented Jan 17, 2022

I haven't used packer before. Here's my init.lua attempting to reproduce this:

return require('packer').startup(function()
  vim.cmd [[
    nmap <leader>p <cmd>Pounce<CR>
    vmap <leader>p <cmd>Pounce<CR>
    omap <leader>P <cmd>Pounce<CR>
  ]]

  use {
    "rlane/pounce.nvim",
    cmd = {"Pounce"},
    opt = true,
    config = function()
      require "pounce".setup {
        accept_keys = "JFKDLSAHGNUVRBYTMICEOXWPQZ",
        debug = false
      }
      vim.cmd [[
        nmap <leader>p <cmd>Pounce<CR>
        vmap <leader>p <cmd>Pounce<CR>
        omap <leader>P <cmd>Pounce<CR>
      ]]
    end
  }
end)

With this config, hitting \p starts Pounce normally for me. Could you try to reproduce the issue with a minimal config?

It seems like the config can also be shortened:

return require('packer').startup(function()
  vim.cmd [[
    nmap <leader>p <cmd>Pounce<CR>
    vmap <leader>p <cmd>Pounce<CR>
    omap <leader>P <cmd>Pounce<CR>
  ]]

  use { "rlane/pounce.nvim", cmd = {"Pounce"}, opt = true }
end)

@JellyApple102
Copy link

I know this issue is over a year old but I'll put this here to avoid opening redundant issues.

When lazy loading with lazy.nvim, highlight groups are not set at all. Because of #37 highlights are only defined on the ColorScheme autocommand, which is called before pounce is even loaded. If the user never switches color schemes, it won't be called again. Currently I am solving this by manually defining the highlights in the config function of lazy.

require('lazy').setup({
    -- other plugins...
    {
        'rlane/pounce.nvim',
        keys = {
            { 's', '<cmd>Pounce<CR>' }
        },
        config = function()
            local str_color = vim.api.nvim_get_hl(0, { name = 'String' }).fg
            local num_color = vim.api.nvim_get_hl(0, { name = 'Number' }).fg
            local const_color = vim.api.nvim_get_hl(0, { name = 'Constant' }).fg
            local spec_color = vim.api.nvim_get_hl(0, { name = 'Special' }).fg
            vim.api.nvim_set_hl(0, 'PounceMatch', { bold = true, fg = 'bg', bg = str_color })
            vim.api.nvim_set_hl(0, 'PounceUnmatched', { link = 'None' })
            vim.api.nvim_set_hl(0, 'PounceGap', { bold = true, fg = 'bg', bg = num_color })
            vim.api.nvim_set_hl(0, 'PounceAccept', { bold = true, fg = 'black', bg = const_color })
            vim.api.nvim_set_hl(0, 'PounceAcceptBest', { bold = true, fg = 'black', bg = spec_color })

            -- not required
            -- require('pounce').setup{}
        end
    },
    -- other plugins
})

I am also using this opportunity to get the colors to match my color scheme by pulling from the already defined highlights.

This gives me several ideas about user configurable highlights or dynamically changing highlights to fit the color scheme in use (or even moving to 100% lua - everything exists in the lua api for that now). I could totally start working on a PR if any of that is of interest, though I would wait for #36 to get merged first.

@rlane
Copy link
Owner

rlane commented Apr 9, 2023

Could you check if #36 fixed this? It's now setting up the highlights both in the ColorScheme autocommand and when the plugin loads.

@JellyApple102
Copy link

Could you check if #36 fixed this? It's now setting up the highlights both in the ColorScheme autocommand and when the plugin loads.

Must have missed that when I looked over it last. I will test when I have the chance soon.

@JellyApple102
Copy link

Can confirm lazy loading works as expected now, awesome job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants