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

fugitive compatibility for viewing commits in PlugDiff #1278

Open
6 of 11 tasks
cpmsmith opened this issue Apr 10, 2024 · 2 comments
Open
6 of 11 tasks

fugitive compatibility for viewing commits in PlugDiff #1278

cpmsmith opened this issue Apr 10, 2024 · 2 comments

Comments

@cpmsmith
Copy link

cpmsmith commented Apr 10, 2024

In :PlugDiff, it's possible to hit enter on a given commit to view its content:

image

fugitive.vim has a very similar feature for viewing commits, but with extra features like being able to browse to other commits and files, and with rhubarb.vim and others, to open the equivalent forge URL e.g. on GitHub.

It'd be cool if vim-plug used fugitive to view commits when it's available.

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"
  • Type:
    • Bug
    • Enhancement
    • Feature Request
    • Question
  • OS:
    • All/Other
    • Linux
    • macOS
    • Windows
  • Vim:
    • Terminal Vim
    • GVim
    • Neovim
@junegunn
Copy link
Owner

junegunn commented Apr 17, 2024

Need some more testing, but this should do the trick.

diff --git a/plug.vim b/plug.vim
index 940811a..4c3a081 100644
--- a/plug.vim
+++ b/plug.vim
@@ -2683,6 +2683,11 @@ function! s:preview_commit()
     return
   endif
 
+  let use_fugitive = exists('*FugitiveFind') && len(sha)
+  if use_fugitive
+    let title = FugitiveFind(sha, g:plugs[name].dir . '/.git')
+  endif
+
   if !s:is_preview_window_open()
     execute get(g:, 'plug_pwindow', 'vertical rightbelow new')
     execute 'e' title
@@ -2691,6 +2696,12 @@ function! s:preview_commit()
     wincmd P
   endif
   setlocal previewwindow filetype=git buftype=nofile bufhidden=wipe nobuflisted modifiable
+  nnoremap <silent> <buffer> q :q<cr>
+  if use_fugitive
+    wincmd p
+    return
+  endif
+
   let batchfile = ''
   try
     let [sh, shellcmdflag, shrd] = s:chsh(1)
@@ -2706,7 +2717,6 @@ function! s:preview_commit()
     endif
   endtry
   setlocal nomodifiable
-  nnoremap <silent> <buffer> q :q<cr>
   wincmd p
 endfunction
 

@junegunn
Copy link
Owner

The patch works. But it's considerably slower to open a commit, so users who don't need additional features of Fugitive may not like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants