Code Monkey home page Code Monkey logo

neozoom.lua's Introduction

NeoZoom.lua

NeoZoom.lua helps you focus... and maybe protect your left-rotated neck.

DEMO

show-off.mov

How it works

The idea is simple: toggle your current window into a floating one, so you can:

  1. Focus on one of your windows without mess-up any of your tabpages(=window layouts).
  2. Pre-define a window layout for each list of filetypes. Now you can use the same keymap to have a customized window layout depending on the filetype of the current buffer.

(The original idea of this project can be found at branch neo-zoom-original)

Features

  • Only one function neo_zoom().
    • setup.winopts will be picked up if no match against setup.presets[i].filetypes.
    • setup.presets[n] will be picked up, otherwise.
    • setup.callbacks are always called, regardless of setup.presets[i].filetypes.
  • Some APIs to help you do customization:
    • M.did_zoom(tabpage=0) by passing a number tabpage, you can check for whether there is zoom-in window on the given tabpage.

Setup

Click to expand

NOTE: remove use if you're using lazy.nvim.

use {
  'nyngwang/NeoZoom.lua',
  config = function ()
    require('neo-zoom').setup {
      popup = { enabled = true }, -- this is the default.
      -- NOTE: Add popup-effect (replace the window on-zoom with a `[No Name]`).
      -- EXPLAIN: This improves the performance, and you won't see two
      --          identical buffers got updated at the same time.
      -- popup = {
      --   enabled = true,
      --   exclude_filetypes = {},
      --   exclude_buftypes = {},
      -- },
      exclude_buftypes = { 'terminal' },
      -- exclude_filetypes = { 'lspinfo', 'mason', 'lazy', 'fzf', 'qf' },
      winopts = {
        offset = {
          -- NOTE: omit `top`/`left` to center the floating window vertically/horizontally.
          -- top = 0,
          -- left = 0.17,
          width = 150,
          height = 0.85,
        },
        -- NOTE: check :help nvim_open_win() for possible border values.
        border = 'thicc', -- this is a preset, try it :)
      },
      presets = {
        {
          -- NOTE: regex pattern can be used here!
          filetypes = { 'dapui_.*', 'dap-repl' },
          winopts = {
            offset = { top = 0.02, left = 0.26, width = 0.74, height = 0.25 },
          },
        },
        {
          filetypes = { 'markdown' },
          callbacks = {
            function () vim.wo.wrap = true end,
          },
        },
      },
    }
    vim.keymap.set('n', '<CR>', function () vim.cmd('NeoZoomToggle') end, { silent = true, nowait = true })
  end
}

Bonus: transparent bg when unfocus

Thanks for the support from the upstream, i.e. neovim/neovim#23542 :)

NeoZoom-bonus.mov
Click to expand
vim.api.nvim_create_autocmd({ 'WinEnter' }, {
  callback = function ()
    local zoom_book = require('neo-zoom').zoom_book

    if require('neo-zoom').is_neo_zoom_float()
    then for z, _ in pairs(zoom_book) do vim.wo[z].winbl = 0 end
    else for z, _ in pairs(zoom_book) do vim.wo[z].winbl = 20 end
    end
  end
})

neozoom.lua's People

Contributors

eduardoarandah avatar henry-hsieh avatar irubataru avatar jmcclell avatar kevinhughes27 avatar mivort avatar nyngwang avatar trivoz avatar zwodahs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neozoom.lua's Issues

[Bug report] Doesn't work on nvim-spectre

Hello @nyngwang . Hope you're doing well. Thank you for creating such a handy and awesome plugin.

This plugin works perfectly on normal buffers. However, I'm trying to zoom in on the pane created by nvim-pack/nvim-spectre and it doesn't work:

screenshot-2022-06-17-15-55-19

The left side is created by the cmd :Spectre.

To reproduce:

  1. open a normal file buffer
  2. :Spectre to start find and replace by Spectre
  3. On the Spectre pane, trigger zoom-in (<C-w>m)
  4. Nothing

Does it mean that NeoZoom only works on "normal file buffers"? I'm not asking to have NeoZoom support specfically for Spectre; just trying to understand if it's a bug or a limitation of NeoZoom. dhruvasagar/vim-zoom works on Spectre pane but it creates extra buffers when closing.

Config:

NeoZoom.lua:

neo_zoom.setup({
  left_ratio = 0.0,
  top_ratio = 0.0,
  width_ratio = 1.0,
  height_ratio = 1.0,
  border = "double",
})

local noref_noerr_trunc = { noremap = true, silent = true, nowait = true }
vim.keymap.set("n", "<C-w>m", function()
  vim.cmd("NeoZoomToggle")
end, noref_noerr_trunc)

OS: Linux
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3

Any input is much appreciated. Thank you:)

UX bug1, on zoom-out, not too serious

How to reproduce:

Open two splits (to enable zoom-in), zoom-in, open a buffer that's not already present, this is the only split (so zoom-out enable), zoom-out, error message shown.

Solution:

Should be easy to resolve: cycle through all windows again before restoring the cursor pos. that causes the bug.

Issue with 2 tabs without splits

If you have 2 tabs and activate NeoZoom in the 1st tab without any splits, then the 1st tab just closes and switches to the second tab.

The expected behavior would be to do nothing.

Calling :q inside a zoom window gives invalid window id

As the title says, :q gives an error when called in a zoom

Error detected while processing WinEnter Autocommands for "*":
Error executing lua callback: ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:92: Invalid window id: 1003
stack traceback:
        [C]: in function 'nvim_win_get_buf'
        ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:92: in function <...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:87>

This might make sense, but the muscle memory of calling :q to close something is quite hard to get rid off.

Bug Report: Zoom-out from the right

Problem

When creating a new split the original one will be located on the right. The current behaviour is that NeoZoom will zoom-out on this split.

Expected

NeoZoom should zoom-out on the right split instead.

Bug report: zoom-out disaster

In #8 I create a map that uses window handles as its keys. This is not good: users may consider two windows with the same buffer (apparently) to be the same.

exclude_filetypes setup option doesn't work

Adding filetypes to be excluded during setup doesn't work because

  M.exclude_filetypes = opt.exclude_filetypes ~= nil and
    _add_table(opt.exclude_filetypes, { 'fzf', 'qf', 'dashboard' }) or { 'fzf', 'qf', 'dashboard' }

_add_table has no return value meaning the left side of the OR always fails.

The checking for option `popup` is bullshit

 ๏™™  Error  13:57:48 msg_show.lua_error E5108: Error executing lua: /Users/ningwang/.config/nvim/lua/plugins/UX.lua:286: nvim_exec(): Vim(lua):E5108: Error executing lua ...local/share/nvim/lazy/NeoZoom.lua/lua/neo-zoom/utils.lua:5: bad argument #1 to 'pairs' (table expected, got nil)

Zooming the current buffer closes the file in the buffer it was zoomed from.

The video on the github page shows the capability of zooming the current buffer from a pane, and when the zoomed window is closed, you go back to the current buffer in the same pane.

I can't figure out how to set this up. I just use the defaults, and when I zoom a buffer, the buffer is closed in the pane I zoomed from. So, I zoom, do some editing, then close the zoom (:q) and now the pane I came from is empty.

How do I fix this?

Feat.-quest 4: orphan tab adoption

Idea

Sometimes we might just want to use the plain-old :tabnew. But then it will not be traced by NeoZoom. So here is an idea: also detect these orphans when running : NeoZoomToggle on any window of that tab, and use the previous tab as its parent.

Some issues here

  • How to define the previous tab?
  • What if this orphan tab might have many windows already?

Error: neo-zoom.lua:29: attempt to index local 'opt' (a nil value)

I have this error with de0e27a3e619ed3f79232ba8daf0ae1a8e92bfea changeset on Neovim version 0.7.2:

packer.nvim: Error running config for NeoZoom.lua: ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:29: attempt to index local 'opt' (a nil value)

I wounder if this is an error of my part or a ZeoZoom.lua bug ๐Ÿค”

Issues when working with bufferline instead of tabline

Based on the README and some quick testing. This plugin seems to be based around working with the tabline. But I found a niche problem if a user such as my self does not use the :tab feature but instead relies on some bufferline plugin.

If for some reason the bufferline is not loaded at startup but is instead lazy loaded on some module call or editor event. Then if one where to create splits with the NeoSplit or NeoVsplit commands. Then upon invoking NeoZoomToggle the bufferline breaks as the tabline appears. Not until the bufferline plugin gets loaded do things come back to normal

This does not happens if splits are created normally, and only use NeoZoomToggle or if the bufferline plugins is loaded before any call to NeoSplit or NeoVsplit

I know is a very edge case issue, but I thought it would be good to report it

scrolloff error

When zooming in or out of any buffer I get the following error. After zooming back out once I only get the error when zooming in. Looks like getting the scrolloff isn't working right:

https://github.com/nyngwang/NeoZoom.lua/blob/main/lua/neo-zoom.lua#L9

E5108: Error executing lua vim/_meta.lua:170: Value for option 'scrolloff' is out of range
stack traceback:
        [C]: in function 'nvim_set_option'
        vim/_meta.lua:170: in function 'set_scoped_option'
        vim/_meta.lua:682: in function '_set'
        vim/_meta.lua:724: in function '__newindex'
        ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:12: in function 'pin_to_80_percent_height'
        ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:45: in function 'maximize_current_split'
        [string ":lua"]:1: in main chunk

My config:

vim.opt.scrolloff = 5

did_zoom not working on popup

Hi!
I have the following mapping to close floating windows with q but to toggle neozoom if the floating window is zoomed:

u.keymap('n', 'q', function()
    if vim.api.nvim_win_get_config(0).zindex then
        if require('neo-zoom').did_zoom() then
            vim.cmd('NeoZoomToggle')
        else
            vim.cmd('close')
        end
    end
end)

The problem with this is that if I get into a popupmenu (such as gitsigns) then did_zoom believes this a "zoomed" window and "NeoZoomToggle" gets called (instead of the expected close). Can get_zoom be changed so it works correctly for this case?

zoom

Can this plugin do directional splitting?

In normal splits you can do something like:

  • :above vsp: Create a split to the right
  • :below vsp: Create a split to the left
  • :above split: Create a split above
  • :below split: Create a split below

Is this still possible with the NeoSplit and NeoVSplit commands?

Bug Report: Should check tab exist on Zoom-out

How to reproduce:

  1. Zoom-in on any buffer.
  2. Switch back to the parent tab with :tabp.
  3. Close all windows with :q on the parent tab.
  4. Trigger NeoZoom on the child buffer.

Expected

In step 4: should be able to zoom-in on that was-child buffer with NeoZoom.

Feat.-quest 1, sketch: zoom-in with default layouts

Idea

When a user zoom-in, it will be really useful to setup a default layout for him, e.g. two equal-size vertical splits (simple = great).

But more details need to be considered:

  • should i use no name buffer for extra-split(s)?
  • how to choose from default layouts, given that more than 1 is provided?

Why

I just found that have to setup this every time I zoom-in.

Feat.-quest 3: Go to first child when `NeoZoom` on parent

As title. This will enhance UX because it let you close all splits rooted from this parent by simply holding your keycomb. for NeoZoom:

  1. On parent: trigger NeoZoom, then goto the first child in the closest tab.
  2. On the first child: trigger NeoZoom will close this split and go back to the parent. Now go back to 1.

See the pattern? So finally you will close all children.

Error 'width' key must be a positive Integer

E5108: Error executing lua ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:48: 'width' key must be a positive Integer                                                                            
stack traceback:                                                                                                                                                                                             
        [C]: in function 'nvim_open_win'                                                                                                                                                                     
        ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:48: in function 'neo_zoom'                                                                                                               
        [string ":lua"]:1: in main chunk

Documentation includes internal constants

Hello, thank you for this plugin, I love the idea!

I blindly copied the docs configuration, trusting that the upper case variables were just available globals, but it seems that they are, in fact, plugin locals. I'm talking about the mapping options ones, for example NOREF_NOERR_TRUNC

UX bug2, on zoom-out, important

How to reproduce:

Open two splits (to enable zoom-in), zoom-in, open a buffer that's not already present, this is the only split (so zoom-out enable), zoom-out, no error message since #1 , while now the problem is that I still want to restore the cursor pos. of this buffer.

Solution:

Might be not easy to solve:

  • should understand how maps work in Lua
  • store cursor pos. for all buffers
  • recover cursor pos. on zoom-out

Bug in combination with quickfix windows.

I use <cr> to Toogle zoom. If I press enter in quickfix window to go to the corresponding location, I get the following error:

E5108: Error executing lua ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:25: Vim(tabedit):E499: Empty file name for '%' or '#', only works with ":p:h": tabedit %:p                                                                                                             
stack traceback:                                                                                                                                                                                                                                                                              
        [C]: in function 'cmd'                                                                                                                                                                                                                                                                
        ...nvim/site/pack/packer/start/NeoZoom.lua/lua/neo-zoom.lua:25: in function 'maximize_current_split'                                                                                                                                                                                  
        [string ":lua"]:1: in main chunk

Feat.-quest 2, sketch: add a toggle to enable NeoMode

What(TF) is NeoMode, exactly?

Take it easy, let's take a look at the classic scene in Matrix:

When NeoMode is enabled, and the behaviour of NeoZoomToggle will change:

  • Instead of zoom(ing)-in the current buffer, it jumps through all the same buffers across all tabs.
  • This might be very fucking hard but I think it's possible to provide and UI to let a user jump to the exact tab containing this buffer.

Some issues here

  • There might be many same-buffer splits under a tab during the jumping.
  • This will require adding a toggle which creates more burden for a user to memorize how(FUCK) many keybindings to do a simple work.

neo-zoom.lua:38: attempt to perform arithmetic on field 'top_ratio' (a nil value)

The first time running :NeoZoomToggle after installation, I got the following error:

E5108: Error executing lua /home/donie/.vim/plugged/NeoZoom.lua/lua/neo-zoom.lua:38: attempt to perform arithmetic on field 'top_ratio' (a nil value)                                                                                                                                                
stack traceback:
        /home/donie/.vim/plugged/NeoZoom.lua/lua/neo-zoom.lua:38: in function 'neo_zoom'
        [string ":lua"]:1: in main chunk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.