Dec
2
1 day ago
started
started time in 15 hours ago
Dec
1
2 days ago
started
started time in 2 days ago
Nov
30
3 days ago
started
started time in 2 days ago
started
started time in 3 days ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Callback for ftplugin style setup when opening diffview.nvim

I want to add some <buffer> keymaps that are only active in the diffview. I know that we can bind any maps in setup.key_bindings, but I also want to add which-key.nvim entries for description. I think a more flexible method is to be able to register a callback that is run when opening a new diffview buffer (like ftplugin)

sindrets
sindrets

This should be resolved now as I've implemented both autocommands as well as a lua API for hooking into events emitted from Diffview. But just let me know if there are any problems.

Activity icon
delete

sindrets in sindrets/diffview.nvim delete branch feat/hooks

deleted time in 3 days ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

feat: Hooks (#99)

  • feat: Implemented hooks.

Hooks let you define event callbacks that will be called when the related events are emitted from Diffview. These are the currently implemented hooks:

  • 'diff_buff_read'
  • 'view_opened'
  • 'view_closed'

See ':h diffview-config-hooks'

  • doc: Update README.

  • feat: Implement all hooks as autocmds as well.

commit sha: 2c0f5af509a9e0f42430c0b561ab7e49aec84f72

push time in 3 days ago
pull request

sindrets pull request sindrets/diffview.nvim

sindrets
sindrets

feat: Hooks

Resolves #75.

The hooks table in the config allows you to define callbacks for various events emitted from Diffview. The available hooks are documented in detail in :h diffview-config-hooks.

The hook events are also available as User autocommands. See :h diffview-user-autocmds for more details.

hooks                                                  *diffview-config-hooks*
        Type: `table<string, function>`, Default: `{}`

        This is a table of event names mapped to callback functions. The
        callbacks are called when the related events are emitted from
        Diffview.

        Available Events:~
                {view_opened} (`fun(view: View)`)
                        Emitted after a new view has been opened. It's called
                        after initializing the layout in the new tabpage (all
                        windows are ready).

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was opened.

                {view_closed} (`fun(view: View)`)
                        Emitted after closing a view.

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was closed.

                {diff_buf_read} (`fun(bufnr: integer)`)
                        Emitted after a new diff buffer is ready (the first
                        time it's created and loaded into a window). Diff
                        buffers are all buffers with |diff-mode| enabled. That
                        includes buffers of local files (not created from
                        git).

                        This is always called with the new buffer as the
                        current buffer and the correct diff window as the
                        current window such that |:setlocal| will apply
                        settings to the relevant buffer / window.

                        Callback Parameters:~
                                {bufnr} (`integer`)
                                        The buffer number of the new buffer.

        Examples: >
                hooks = {
                  diff_buf_read = function(bufnr)
                    -- Change local options in diff buffers
                    vim.opt_local.wrap = false
                    vim.opt_local.list = false
                    vim.opt_local.colorcolumn = { 80 }
                  end,
                  view_opened = function(view)
                    print(
                      ("A new %s was opened on tab page %d!")
                      :format(view:class():name(), view.tabpage)
                    )
                  end,
                }

User Autocommands

  • DiffviewViewOpened
  • DiffviewViewClosed
  • DiffviewViewDiffBufRead
Activity icon
issue

sindrets issue sindrets/diffview.nvim

sindrets
sindrets

Callback for ftplugin style setup when opening diffview.nvim

I want to add some <buffer> keymaps that are only active in the diffview. I know that we can bind any maps in setup.key_bindings, but I also want to add which-key.nvim entries for description. I think a more flexible method is to be able to register a callback that is run when opening a new diffview buffer (like ftplugin)

Previous