sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.74k stars 105 forks source link

integration question: static way to determine if a view is open (and which view is open)? #329

Closed mrjones2014 closed 1 year ago

mrjones2014 commented 1 year ago

Hi, amazing plugin. I'd love to be able to make a legendary.nvim extension for it (basically a way for legendary.nvim to automatically load keymaps from diffview.nvim).

Since the keymaps are only active when in a diffview.nvim-managed view, I would need a way to detect if the current buffer is a diffview.nvim view (and which one), so that the legendary.nvim UI can filter out the keymaps. Are there perhaps some global variables like vim.g.diffview_view_diff3 etc.?

I'd be happy to make a PR but I'm not sure what the "right way" to do it would be.

sindrets commented 1 year ago

Thank for taking an interest in the project!

We don't currently offer a stable public API, as nobody has requested it yet (although I'm not opposed to implement such an interface). However, the following function for getting the currently open view has been available - I believe - since the plugin's release:

local view = require("diffview.lib").get_current_view()

Are there perhaps some global variables like vim.g.diffview_view_diff3 etc.?

A way to find out what layout is currently in use? If so:

print(view.cur_layout.name)
mrjones2014 commented 1 year ago

Awesome, this is perfect! Exactly what I was looking for. Thanks!