Skip to content

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

Description

@perelo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions