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

How to call user defined hydra #3

Closed
JoseConseco opened this issue Jun 21, 2022 · 6 comments
Closed

How to call user defined hydra #3

JoseConseco opened this issue Jun 21, 2022 · 6 comments

Comments

@JoseConseco
Copy link

Awesome plugin (I was waiting for this for long time - it is the only thing that I wish nvim had from emcas)
What I proper way to call my custom hydra?
In my case I defined it under:
<leader>dh
But calling :normal <leader>dh wont work.
Maybe we could get additional option for Hydra({ reference = xyz })
if we call - require'hydra'.xyz() from cmd or lua this would open user defined hydra?
or something similar way to call user defined hydras would be cool.

@anuvyklack
Copy link
Owner

To call hydra you need to press body + head keys. In your case, as I get, you bind body to <leader>dh, so you need to type <leader>dh + <head> key.

@JoseConseco
Copy link
Author

JoseConseco commented Jun 21, 2022

I wanted to just open the my custom Hydra popup - it is defined with - invoke_on_body = True option - thus there is no need for head key, right?
I any case using which key I found out that executing hydra body keys calls:
<Plug>(Layer1_enter)
And using this correctly opened my Hydra UI popup. So I only wish we could define layer1_enter (not sure where it comes from) - it would allow me to call my Hydra without guessing its comand name.

For reference here is command I try to do - add breakpoint at cursor, run dap connect, and open dap Hydra popup using which-key plugin - all mapped to single mapping:

['<leader>da']  = {
":lua require'dap'.set_breakpoint() require'dap'.run({type='python', request='attach', host='127.0.0.1', port=5678})<CR><Plug>(Layer1_enter)",
'Attach'
}



@anuvyklack
Copy link
Owner

Why can't you place this code in hydras config.on_enter function?

@anuvyklack
Copy link
Owner

Never mind. I can create <hydra_obj>:enter() method. I will do it tomorrow.

@anuvyklack
Copy link
Owner

Done in a82bc53.

You can use it next way

local sample = Hydra({...})

sample:activate() -- activate hydra

@JoseConseco
Copy link
Author

Thanks. This fixed the issue. I will post for reference for other people how to integrate this with which-key plug:
In your hydra-config:

local Hydra = require('hydra')
local dap = require'dap'

local hint = [[
 _n_: step over   _s_: Continue/Start   _b_: Breakpoint     _K_: Eval
 _i_: step into   _x_: Quit             ^ ^                 ^ ^
 _o_: step out    _X_: Stop             ^ ^
 _c_: to cursor   _C_: Close UI
 ^
 ^ ^              _q_: exit
]]    

local dap_hydra = Hydra({
   hint = hint,
   config = {
      color = 'pink',
      invoke_on_body = true,
      hint = {
         position = 'bottom',
         border = 'rounded'
      },
   },
	 name = 'dap',
   mode = {'n','x'},
   body = '<leader>dh',
   heads = {
      { 'n', dap.step_over, { silent = true } },
      { 'i', dap.step_into, { silent = true } },
      { 'o', dap.step_out, { silent = true } },
      { 'c', dap.run_to_cursor, { silent = true } },
      { 's', dap.continue, { silent = true } },
      { 'x', ":lua require'dap'.disconnect({ terminateDebuggee = false })<CR>", {exit=true, silent = true } },
      { 'X', dap.close, { silent = true } },
      { 'C', ":lua require('dapui').close()<cr>:DapVirtualTextForceRefresh<CR>", { silent = true } },
      { 'b', dap.toggle_breakpoint, { silent = true } },
      { 'K', ":lua require('dap.ui.widgets').hover()<CR>", { silent = true } },
      { 'q', nil, { exit = true, nowait = true } },
   }
})

Then we can create spawn method for hydra - which will take head as an argument:

Hydra.spawn = function(head)
	if head == 'dap-hydra' then
		dap_hydra:activate()
	end
end

Finally in your which key config file u can spawn dap hydra like so (auto add breakpoint at cursor, run dap attach, ans finally spawn dap-hydra:

	['<leader>da']  = {
		function()
			require'dap'.set_breakpoint()
			require'dap'.run({type='python', request='attach', host='127.0.0.1', port=5678})
			require'hydra'.spawn('dap-hydra')
		end,    'Attach (localhost, 5678)'} ,

Frederick888 pushed a commit to Frederick888/hydra.nvim that referenced this issue Dec 31, 2023
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

2 participants