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

on_enter stopped working properly #51

Open
hrqmonteiro opened this issue Oct 1, 2024 · 4 comments
Open

on_enter stopped working properly #51

hrqmonteiro opened this issue Oct 1, 2024 · 4 comments

Comments

@hrqmonteiro
Copy link

This is a minimal.lua i created:

-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

local function jfunc()
  if vim.wo.diff then
    return "]c"
  else
  end
  local function _3_()
    return gitsigns.next_hunk()
  end
  vim.schedule(_3_)
  return "<Ignore>"
end

-- Setup lazy.nvim
require("lazy").setup({
  spec = {
	  {
		  "lewis6991/gitsigns.nvim",
		  config = function()
			  require("gitsigns").setup()
		  end
	  },
	  {
		  "nvimtools/hydra.nvim",
		  config = function()
			  local Hydra = require("hydra")
			  local gitsigns = require("gitsigns")

			  Hydra({
				  name = "+git",
				  body = "<leader>gh",
				  config = {
					  buffer = vim.bufnr,
					  color = "red",
					  invoke_on_body = true,
					  -- on_enter = function()
					  --  print("a")
					  -- end
				  },
				  heads = {
					{"J", jfunc, {desc = "next hunk", expr = true}}
				  }
			  })
		  end
	  }
  },
  -- Configure any other settings here. See the documentation for more details.
  -- colorscheme that will be used when installing plugins.
  install = { colorscheme = { "habamax" } },
  -- automatically check for plugin updates
  checker = { enabled = true },
})

And it works properly:

image

But when trying to pass a function on on_enter (uncommenting that section), it returns this error as soon as i open nvim:

image

I can't use on_enter or on_exit

@benlubas
Copy link
Collaborator

benlubas commented Oct 1, 2024

what neovim version?

@hrqmonteiro
Copy link
Author

what neovim version?

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

@aszakaly-vcc
Copy link

Upgrading to v0.10.2 worked for me.

@ColinKennedy
Copy link

Same error for me. I'm on

NVIM v0.11.0-dev-1157+g434d5936b6
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260
Run ":verbose version" for more info

And it errors on startup with the Git example on the Wiki

Failed to run `config` for hydra.nvim

vim/shared.lua:0: s: expected string, got number

# stacktrace:
  - vim/shared.lua:0 _in_ **validate**
  - vim/shared.lua:0 _in_ **startswith**
  - vim/_init_packages.lua:0 _in_ **__index**
  - vim/shared.lua:0 _in_ **islist**
  - vim/shared.lua:0 _in_ ****
  - vim/shared.lua:0 _in_ **tbl_deep_extend**
  - /hydra.nvim/lua/hydra/layer/init.lua:116 _in_ **initialize**
  - /hydra.nvim/lua/hydra/lib/class.lua:14 _in_ **Layer**
  - /hydra.nvim/lua/hydra/init.lua:440 _in_ **_setup_pink_hydra**
  - /hydra.nvim/lua/hydra/init.lua:282 _in_ **initialize**
  - /hydra.nvim/lua/hydra/lib/class.lua:14 _in_ **Hydra**
  - lua/my_custom/plugins/hydra/configuration.lua:536
  - lua/my_custom/plugins/manifest/workflow.lua:362 _in_ **config**
  - init.lua:293
local Hydra = require("hydra")
local gitsigns = require('gitsigns')

local hint = [[
 _J_: next hunk   _s_: stage hunk        _d_: show deleted   _b_: blame line
 _K_: prev hunk   _u_: undo last stage   _p_: preview hunk   _B_: blame show full
 ^ ^              _S_: stage buffer      ^ ^                 _/_: show base file
 ^
 ^ ^              _<Enter>_: Neogit              _q_: exit
]]



Hydra({
   name = 'Git',
   hint = hint,
   config = {
      buffer = bufnr,
      color = 'pink',
      invoke_on_body = true,
      hint = {
         border = 'rounded'
      },
      on_enter = function()
         vim.cmd 'mkview'
         vim.cmd 'silent! %foldopen!'
         vim.bo.modifiable = false
         gitsigns.toggle_signs(true)
         gitsigns.toggle_linehl(true)
      end,
      on_exit = function()
         local cursor_pos = vim.api.nvim_win_get_cursor(0)
         vim.cmd 'loadview'
         vim.api.nvim_win_set_cursor(0, cursor_pos)
         vim.cmd 'normal zv'
         gitsigns.toggle_signs(false)
         gitsigns.toggle_linehl(false)
         gitsigns.toggle_deleted(false)
      end,
   },
   mode = {'n','x'},
   body = '<leader>g',
   heads = {
      { 'J',
         function()
            if vim.wo.diff then return ']c' end
            vim.schedule(function() gitsigns.next_hunk() end)
            return '<Ignore>'
         end,
         { expr = true, desc = 'next hunk' } },
      { 'K',
         function()
            if vim.wo.diff then return '[c' end
            vim.schedule(function() gitsigns.prev_hunk() end)
            return '<Ignore>'
         end,
         { expr = true, desc = 'prev hunk' } },
      { 's', ':Gitsigns stage_hunk<CR>', { silent = true, desc = 'stage hunk' } },
      { 'u', gitsigns.undo_stage_hunk, { desc = 'undo last stage' } },
      { 'S', gitsigns.stage_buffer, { desc = 'stage buffer' } },
      { 'p', gitsigns.preview_hunk, { desc = 'preview hunk' } },
      { 'd', gitsigns.toggle_deleted, { nowait = true, desc = 'toggle deleted' } },
      { 'b', gitsigns.blame_line, { desc = 'blame' } },
      { 'B', function() gitsigns.blame_line{ full = true } end, { desc = 'blame show full' } },
      { '/', gitsigns.show, { exit = true, desc = 'show base file' } }, -- show the base of the file
      { '<Enter>', '<Cmd>Neogit<CR>', { exit = true, desc = 'Neogit' } },
      { 'q', nil, { exit = true, nowait = true, desc = 'exit' } },
   }
})

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

4 participants