iron.nvim icon indicating copy to clipboard operation
iron.nvim copied to clipboard

basic question: how would you use the lua functions to toggle a floating window

Open alok opened this issue 4 years ago • 3 comments

for my repls, I want them to be created in floating windows (with some level of winblend most likely), and for a mapping to toggle showing them or not. does iron allow for this?

alok avatar Apr 06 '21 03:04 alok

There's a namespace in iron for handling visibility, it's iron.visibility and it already allows for toggling buffers, but I didn't update it to handle floating ones.

visibility.toggle = function(bufid, showfn)
  local window, was_hidden = hidden(bufid, showfn)
  if not was_hidden then
    vim.api.nvim_command(window .. "wincmd c")
  else
    vim.api.nvim_command(window .. "wincmd p")
  end
end

A quick way to test this would be to come up with a function yourself and replace iron's behavior by setting it to iron.behavior.visibility:

function MyOwnVisibilityToggler(bufid, showfn)
...
end

require("iron").behavior.visibility = MyOwnVisibilityToggler

showfn is a 0 argument function that most of the time is a closure of iron.ll.new_repl_window with the correct arguments, which, in turn, calls iron.config.repl_open_cmd if it's a function, with buffer and ft as arguments, so the final solution would be:

function MyOwnVisibilityToggler(bufid, showfn)
...
end

function MyOwnWindowOpener(buffer_number, ft)
...
end

local iron = require("iron")


iron.behavior.visibility = MyOwnVisibilityToggler
iron.config.repl_open_cmd = MyOwnWindowOpener

I know this is still very complex and I want to simplify this. #174 would lay the foundation to simplify a lot of those.

Sorry for the mess and for the not-so-simple answer for a simple question 😅

hkupty avatar Apr 12 '21 22:04 hkupty

hey! is there any update on this?

jaschenb avatar Sep 12 '22 17:09 jaschenb

I have merged some code that allows for easier and better control over the window management. I don't think we're quite there yet with regards to the intent of this issue, but I'd say we're closer. I'll try to focus on iron in the next couple of days to trim off some of the standing issues and I'll be able to focus a bit more on this.

hkupty avatar Sep 12 '22 20:09 hkupty