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

Use [pedit +entry.lnum #entry.bufnr] in qf#preview#PreviewFileUnderCursor() #111

Open
perelo opened this issue Oct 31, 2020 · 2 comments
Open

Comments

@perelo
Copy link

perelo commented Oct 31, 2020

Hi again,

Preview on :helpgrep entries don't work for me. The qf#GetEntryPath(cur_line) doesn't find the help file since only the tail of its name is given.

:pedit allows us to use #{bufnr} to preview an existing buffer. We can get this buffer by querying the entry dictionnary of the current line in cur_list.

--- a/autoload/qf/preview.vim
+++ b/autoload/qf/preview.vim
@@ -24,8 +24,11 @@ function! qf#preview#PreviewFileUnderCursor()
     let cur_list = qf#GetList()
     let cur_line = getline(line('.'))
     let cur_file = fnameescape(qf#GetEntryPath(cur_line))
+    let cur_ntry = get(cur_list, line('.')-1, {})
 
-    if cur_line =~ '|\d\+'
+    if !empty(cur_ntry) && bufexists(cur_ntry.bufnr) && cur_ntry.bufnr
+        execute 'pedit +' . cur_ntry.lnum . ' #' . cur_ntry.bufnr
+    elseif cur_line =~ '|\d\+'
         let cur_pos  = substitute(cur_line, '^\(.\{-}|\)\(\d\+\)\(.*\)', '\2', '')
         execute "pedit +" . cur_pos . " " . cur_file
     else

More generally, is there a reason why almost all queries on the entry list is done by parsing getline(line('.')) ? It seems that the location list of the location list is itself, so we can use the power of getloclist(0) and its {what} argument for the quickfix window mappings, like } and {.

Also, qf#PreviewFileUnderCursor() in autoload/qf.vim and qf#preview#PreviewFileUnderCursor() are duplicates. I guess one is for legacy, but we could simply call one of them from the other.

@romainl
Copy link
Owner

romainl commented Oct 31, 2020

Hi again, could you open a PR?

It seems that the location list of the location list is itself, so we can use the power of getloclist(0) and its {what} argument for the quickfix window mappings, like } and {.

Most of that code predates {what}. In fact vim-qf as a whole is pretty dated, which is a good and a bad thing: it works in older Vims but it is also a bit of a mess that would benefit a lot from newer features. As mentioned in a couple of other discussions, I am considering reviewing the whole thing. The current guards assume 7.3 compatibility but I very much doubt 7.3 or even 7.4 are actually supported so I should probably bump it to 8.0.

@perelo
Copy link
Author

perelo commented Oct 31, 2020

I should probably bump it to 8.0.

I'm glad to hear that 👍

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

No branches or pull requests

2 participants