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

feat: paste window open hook #197

Closed
ofseed opened this issue Feb 18, 2024 · 6 comments · Fixed by #198
Closed

feat: paste window open hook #197

ofseed opened this issue Feb 18, 2024 · 6 comments · Fixed by #198
Labels
enhancement New feature or request released

Comments

@ofseed
Copy link
Contributor

ofseed commented Feb 18, 2024

Because the paste window needs a common filetype like bash to get the correct syntax highlighting and completion, It's hard to do something like setting keymaps or adjusting window options. I suggest exposing a hook function that receives winid or bufnr as arguments for doing these things.

@mikesmithgh
Copy link
Owner

Hey @ofseed thanks for reporting.

Regarding adjusting window options, there are overrides exposed via:

Options Type Description
paste_window.winopts_overrides fun(paste_winopts: KsbWinOpts): table<string,any>? Paste float window overrides, see nvim_open_win() for configuration
paste_window.footer_winopts_overrides fun(footer_winopts: KsbWinOpts, paste_winopts: KsbWinOpts): table<string,any>? Paste footer window overrides, see nvim_open_win() for configuration

There is an example of this in Advanced Configuration Examples named ksb_example_paste_win_winopts.

But, I agree, there is no general hook if you want to do something based on the bufnr or winid. What are you trying to trigger when the paste window opens?

@mikesmithgh mikesmithgh added the enhancement New feature or request label Feb 18, 2024
@mikesmithgh mikesmithgh changed the title [Feature Request]: paste window open hook feat: paste window open hook Feb 18, 2024
@ofseed
Copy link
Contributor Author

ofseed commented Feb 18, 2024

I know this option, and I fixed a bug about this : ), see: #182

There's a more complicated situation in my use case. I'm using 'statuscolumn' to arrange my sign columns, there's no way to disable 'statuscolumn' except a hook to do this.

@mikesmithgh
Copy link
Owner

I know this option, and I fixed a bug about this : ), see: #182

😅 oops, didn't realize.

There's a more complicated situation in my use case. I'm using 'statuscolumn' to arrange my sign columns, there's no way to disable 'statuscolumn' except a hook to do this.

Ah, I see yeah you are right.

mikesmithgh added a commit that referenced this issue Feb 20, 2024
@mikesmithgh mikesmithgh linked a pull request Feb 20, 2024 that will close this issue
mikesmithgh added a commit that referenced this issue Feb 20, 2024
mikesmithgh pushed a commit that referenced this issue Feb 20, 2024
# [4.2.0](v4.1.0...v4.2.0) (2024-02-20)

### Bug Fixes

* add buffer name suffix .ksb_footerbuf to footer ([4f234de](4f234de))
* create separate set_local_defaults function ([2c6812a](2c6812a))
* include buffer local mappings when resolving footer keymaps ([af2aa25](af2aa25))

### Features

* add after_paste_window_ready callback ([646a41e](646a41e)), closes [#197](#197)
@mikesmithgh
Copy link
Owner

🎉 This issue has been resolved in version 4.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@mikesmithgh
Copy link
Owner

Hey @ofseed I added the callback after_paste_window_ready that has a first parameter containing the window and buffer ids of the scrollback buffer, paste window, and paste window footer. The paste window data will be in form similar to:

local paste_window_data = {
  scrollback_buffer = { bufid = p.bufid, winid = p.winid },
  paste_window = { bufid = p.paste_bufid, winid = p.paste_winid },
  paste_window_footer = { bufid = p.footer_bufid, winid = p.footer_winid },
}

I played around a bit and created this example:

require('kitty-scrollback').setup({
  {
    callbacks = {
      after_paste_window_ready = function(pastewin_data, kitty_data, opts)
        local stc = '%#ErrorMsg#%{(v:lnum%2)?" ".v:lnum:""}' .. '%#WarningMsg#%{!(v:lnum%2)?" ".v:lnum:""} '
        vim.api.nvim_set_option_value('statuscolumn', stc, {
          win = pastewin_data.paste_window.winid,
        })

        vim.keymap.set({ '' }, '<Tab>', '<Plug>(KsbToggleFooter)', {
          buffer = pastewin_data.paste_window.bufid,
        })

        if pastewin_data.paste_window_footer.winid then
          vim.api.nvim_set_option_value('statuscolumn', 'help:', {
            win = pastewin_data.paste_window_footer.winid,
          })
        end
      end,
    },
  },
})

callback-example

Please let me know if you run into any issues

@ofseed
Copy link
Contributor Author

ofseed commented Feb 20, 2024

It runs without problems, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants