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

Provide API to just resolve specs #13

Open
blueyed opened this issue Sep 16, 2016 · 3 comments
Open

Provide API to just resolve specs #13

blueyed opened this issue Sep 16, 2016 · 3 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 16, 2016

I've thought to use this plugin to get the filename under the cursor in a quickfix list, and then :edit it after wincmd w.

From a quick glance fetch#cfile does this, but the command to be executed is hard-coded to gf/gF already.

It would be great to have an interface where the filename that would be understood by vim-fetch would be returned: empty would mean that vim-fetch (and gf/gF) cannot handle it.
For my use case using the current cursor position is good, but I could also imagine passing in a string (and maybe the position in that string).

Another approach would be for the function to return the spec itself: the filename and the jump action (and a way to call / execute those).

@kopischke kopischke self-assigned this Sep 16, 2016
@kopischke
Copy link
Collaborator

kopischke commented Sep 16, 2016

That is a) definitely possible and b) a major refactoring of the codebase. Before undertaking it, I would like to understand your exact use case. Is it just a matter of using fetch to parse a spec’ed <cfile> back into a usable file name? Or is there something else I am missing from your description?

@blueyed
Copy link
Contributor Author

blueyed commented Sep 16, 2016

What I want is to basically use the improved gF from a quickfix window, and control where it gets opened - e.g. in the previous window (after wincmd p), or a new tab.
For the most control I would like to get the matching spec (trying all, or by providing a list) and then a method to do what vim-fetch does itself given this spec to open the file.

My hack for this is the following in ~/.vim/after/ftplugin/qf.vim:

function! s:open_in_prev_win()
  " does not contain line number
  let cfile = expand('<cfile>')
  let f = findfile(cfile)
  if !len(f)
    echom "Could not find file at cursor (".cfile.")"
    return
  endif

  " Delegate to vim-fetch.  Could need better API
  " (https://github.com/kopischke/vim-fetch/issues/13).
  let f = expand('<cWORD>')
  wincmd w
  silent exe 'e' f
endfunction

nmap <buffer> o :call <SID>open_in_prev_win()<cr>

@kopischke kopischke added this to the Future plans milestone Mar 4, 2018
@kopischke kopischke removed their assignment May 5, 2018
@wsdjeg
Copy link
Owner

wsdjeg commented Dec 25, 2018

yeah, a nice feature request. Maybe be this plugin could provide a function and accept a dict argv:

{
     'filename' : needed,
     'line' :  default 1,
     'col' : default 1,
     'win' : default 0, current Windows,
     'tab' : default 0, current tab
}

with this function, user can create there own mappings.

for example,

nnoremap gf :call fetch#open(
     \ 'filename' : filename,
     \ 'line' : line,
     \ 'col' : col,
     \ 'win' : 'w',
     \ }

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

3 participants