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

Opening DiffViewFileHistory without Folds #132

Closed
harrisoncramer opened this issue May 2, 2022 · 6 comments
Closed

Opening DiffViewFileHistory without Folds #132

harrisoncramer opened this issue May 2, 2022 · 6 comments
Labels
question Further information is requested stale The issue or PR has grown stale due to inactivity

Comments

@harrisoncramer
Copy link
Contributor

First off, thank you for the awesome plugin, I use it regularly.

Is it possible to configure the :DiffviewFileHistory command to open the diffs without folds? There's a similar discussion about Vim's built-in diff functionality here which is the same functionality that I'm hoping to accomplish.

Hopping into each buffer and running zR to expand them every time I switch a entry in the history isn't really a practical way of accomplishing this. Thanks again!

@sindrets
Copy link
Owner

sindrets commented May 9, 2022

First off, thank you for the awesome plugin, I use it regularly.

I'm glad to hear it!

Is it possible to configure the :DiffviewFileHistory command to open the diffs without folds?

There was a problem with the order in which hooks were called before, but after the latest commit you should be able to do something like:

require("diffview").setup({
  hooks = {
    diff_buf_read = function(bufnr)
      vim.cmd("norm! gg]ckzt") -- Set cursor on the first hunk
    end,
    diff_buf_win_enter = function(bufnr)
      vim.opt_local.foldlevel = 99
    end,
  },
})

If you only want it to apply to file history views, you could do:

diff_buf_win_enter = function(bufnr)
  local FileHistoryView = require("diffview.views.file_history.file_history_view").FileHistoryView
  local view = require("diffview.lib").get_current_view()
  if view and view:instanceof(FileHistoryView) then
    vim.opt_local.foldlevel = 99
  end
end

You could obviously also do vim.opt_local.foldenable = false if you want to disable folds entirely in those windows.

Although, I have to ask: what is the point of this? In large files this will show a lot of irrelevant information, no?

@sindrets sindrets added the question Further information is requested label May 9, 2022
@sindrets
Copy link
Owner

Closing due to inactivity from OP.

@sindrets sindrets closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2022
@sindrets sindrets added the stale The issue or PR has grown stale due to inactivity label May 23, 2022
@harrisoncramer
Copy link
Contributor Author

First off, thank you for the awesome plugin, I use it regularly.

I'm glad to hear it!

Is it possible to configure the :DiffviewFileHistory command to open the diffs without folds?

There was a problem with the order in which hooks were called before, but after the latest commit you should be able to do something like:

require("diffview").setup({
  hooks = {
    diff_buf_read = function(bufnr)
      vim.cmd("norm! gg]ckzt") -- Set cursor on the first hunk
    end,
    diff_buf_win_enter = function(bufnr)
      vim.opt_local.foldlevel = 99
    end,
  },
})

If you only want it to apply to file history views, you could do:

diff_buf_win_enter = function(bufnr)
  local FileHistoryView = require("diffview.views.file_history.file_history_view").FileHistoryView
  local view = require("diffview.lib").get_current_view()
  if view and view:instanceof(FileHistoryView) then
    vim.opt_local.foldlevel = 99
  end
end

You could obviously also do vim.opt_local.foldenable = false if you want to disable folds entirely in those windows.

Although, I have to ask: what is the point of this? In large files this will show a lot of irrelevant information, no?

This works great, apologies I didn't see this notification. Thank you!

@norbertkeri
Copy link

I can't seem to get this to work, is it possible that I have some local plugin that might be overriding the hooks? I'm trying the following:

require("diffview").setup({
    enhanced_diff_hl = true,
    hooks = {
        diff_buf_read = function(bufnr) 
            vim.opt_local.foldlevel = 99
            vim.opt_local.foldenable = false
        end,
        diff_buf_win_enter = function(bufnr) 
            vim.opt_local.foldlevel = 99
            vim.opt_local.foldenable = false
        end
    }
})

And I'm still seeing folds when using :DiffviewFileHistory.

@sindrets
Copy link
Owner

@norbertkeri Sorry, there was a regression related to the order of execution for hooks after a recent refactor. I just fixed this in the latest commit. Setting local options from these hooks should work as expected now.

@norbertkeri
Copy link

No worries, works perfect now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale The issue or PR has grown stale due to inactivity
Projects
None yet
Development

No branches or pull requests

3 participants