nvim-focus/focus.nvim

vim.g.enabled_focus_resizing no longer works

Closed this issue ยท 20 comments

Is there a new way to get the state of whether reszing is enabled or not? I have a status line plugin that relies on it but it looks like it has been removed! Cheers!

I am having all sorts of problems with figuring out how to use this plugin and I think this auto resizing issue may be part of it.
@piersolenski Have you figured out a way around it? This plugin is almost unusable with things like this not working (or maybe i just don't understand how to properly configure / use the plugin).

Sadly not ๐Ÿ˜ข

See the README how to disable the plugin.

https://github.com/nvim-focus/focus.nvim#disabling-focus

It seems the problem with that is it's not set when the plugin is initiated, only after you have disabled / reenabled it?

It is set when you disable the focus functionality. It doesn't make sense if you only evaluate on startup. You might disable it for certain buffers or not. Also there are several variable. For window, buffer and globally. Write a function which evaluates them all.

If this is just about if you have enabled it in the config or not, evaluate the config. I think you should be able to access _G.Focus.config. You should be more clear what you actually want ... my crystal ball is damaged.

If you go back to my original issue, I have a status line plugin that shows whether various plugins are currently enabled or not. This used to use the vim.g.enabled_focus_resizing, but at some point this was deprecated. I'm basically looking for the updated way to bring back this behaviour. Using vim.g.Focus.config doesn't seem to work for me.

CleanShot 2024-01-09 at 09 10 48@2x
:lua vim.print(_G.Focus.config)

If you want if it is enable for the current window you have to check vim.g.focus_disable, vim.b.focus_disable and vim.w.focus_disable (g = global, b = buffer, w = window).

That's great, thanks for clearing everything up!

Hmm whilst this works on start, after running :FocusToggle to turn it off, _G.Focus.config.enable still returns true - is that the correct?

Yes, that's correct. That's what the user configured.

See my commant above how to evaluate if it is enabled or disable for the current window:

#144 (comment)

All of those always returns as nil for me?

:lua require('focus').focus_toggle_buffer()
:lua vim.print(vim.b.focus_disable)
true

Works as expected.

I don't want to use it with the buffer, I want to use it globally. On the first run:

:lua vim.print(vim.g.focus_disable)
nil

The code in Lualine is as follows:

local function highlightStatus(enabled)
  return enabled and "#9ccfd8" or "#6e6a86"
end

{
  -- Window resizing
  function()
    return "๏ƒ› "
  end,
  color = function()
    return { fg = highlightStatus(vim.g.focus_disable == false) }
  end,
}

That means that at launch the code returns nil, and that the icon that indicates Focus is enabled is not highlighted.

After using :FocusToggle to disable it, then reenable it, it will start working.

I don't want to use it with the buffer, I want to use it globally.

Focus can be disabled globally (for all buffers and windows currently open), for a buffer or just a window.

Again, it is describe here: https://github.com/nvim-focus/focus.nvim#disabling-focus

We go around in a circles ...

Answer to the initial question:

focus.nvim has been rewritten. vim.g.enabled_focus_resizing is not used anymore, you can disable focus more fine grained in the meantime, see https://github.com/nvim-focus/focus.nvim#disabling-focus for all the different options.

@GitMurf let me know if you have a similar use case to me, and if any of the above helped you - still unclear to me from the instructions above ๐Ÿ™

Maybe start with reading :help windows and then move to

  • :help global-varibale
  • :help buffer-variable
  • :help window-variable
  • :help variable-scope

If focus is enabled or disabled for a windows can depend on the windows filetype and/or buffer type.

We have an internal function to check if a window has focus disabled:

:lua vim.print(require('focus.modules.utils').is_disabled())

You need to evaluate on a window basis if focus is enabled or not. Read :help autocmd to find out how to keep it updated. You probably want an autocmd for :help WinEnter. Then check if if focus is enabled and update your statusline.

I really just wanted to simply recreate the old behaviour of vim.g.enabled_focus_resizing which was simple and worked fine. Thanks though.