Skip to main content
deleted 1 character in body
Source Link
romainl
  • 42.3k
  • 5
  • 87
  • 118

Is something wrong with this approach?

Yes.

When you do gf and Vim doesn't find the target file, it tries to use :help 'includeexpr', if it is set, as a last resort. It is expected to be an expression that transforms the given "path-like" string into an actual usable path.

In this case, it would look something like this:

" in after/ftplugin/yaml.vim
setlocal includeexpr=substitute(v:fname, '^\/', '', '')

which would let you use the native gf and gF and make this problem moot.

FWIWNow, includeexpr is supposed to return a valid path but it doesn't prescribe a way to do so. There are, actually, many situations where a substantial amount of work is required in order to obtain a valid path and that work can all be encapsulated in a function:

" in after/ftplugin/yaml.vim
function HandleAzurePaths(fname)
    " your code here
endfunction
setlocal includeexpr=HandleAzurePaths(v:fname)

If your logic in lines 677-694 works, you should be able to fit it there and make it return x… without having to deal with "real" gf and "fake" gf.

FWIW, I use such a function for JavaScript, where I reimplemented Node's module resolution algorithm in about 100 lines so don't feel constrained, here.

Is something wrong with this approach?

Yes.

When you do gf and Vim doesn't find the target file, it tries to use :help 'includeexpr', if it is set, as a last resort. It is expected to be an expression that transforms the given "path-like" string into an actual usable path.

In this case, it would look something like this:

" in after/ftplugin/yaml.vim
setlocal includeexpr=substitute(v:fname, '^\/', '', '')

which would let you use the native gf and gF and make this problem moot.

FWIW, includeexpr is supposed to return a valid path but it doesn't prescribe a way to do so. There are, actually, many situations where a substantial amount of work is required in order to obtain a valid path and that work can all be encapsulated in a function:

" in after/ftplugin/yaml.vim
function HandleAzurePaths(fname)
    " your code here
endfunction
setlocal includeexpr=HandleAzurePaths(v:fname)

If your logic in lines 677-694 works, you should be able to fit it there and make it return x… without having to deal with "real" gf and "fake" gf.

FWIW, I use such a function for JavaScript, where I reimplemented Node's module resolution algorithm in about 100 lines so don't feel constrained, here.

Is something wrong with this approach?

Yes.

When you do gf and Vim doesn't find the target file, it tries to use :help 'includeexpr', if it is set, as a last resort. It is expected to be an expression that transforms the given "path-like" string into an actual usable path.

In this case, it would look something like this:

" in after/ftplugin/yaml.vim
setlocal includeexpr=substitute(v:fname, '^\/', '', '')

which would let you use the native gf and gF and make this problem moot.

Now, includeexpr is supposed to return a valid path but it doesn't prescribe a way to do so. There are, actually, many situations where a substantial amount of work is required in order to obtain a valid path and that work can all be encapsulated in a function:

" in after/ftplugin/yaml.vim
function HandleAzurePaths(fname)
    " your code here
endfunction
setlocal includeexpr=HandleAzurePaths(v:fname)

If your logic in lines 677-694 works, you should be able to fit it there and make it return x… without having to deal with "real" gf and "fake" gf.

FWIW, I use such a function for JavaScript, where I reimplemented Node's module resolution algorithm in about 100 lines so don't feel constrained, here.

Source Link
romainl
  • 42.3k
  • 5
  • 87
  • 118

Is something wrong with this approach?

Yes.

When you do gf and Vim doesn't find the target file, it tries to use :help 'includeexpr', if it is set, as a last resort. It is expected to be an expression that transforms the given "path-like" string into an actual usable path.

In this case, it would look something like this:

" in after/ftplugin/yaml.vim
setlocal includeexpr=substitute(v:fname, '^\/', '', '')

which would let you use the native gf and gF and make this problem moot.

FWIW, includeexpr is supposed to return a valid path but it doesn't prescribe a way to do so. There are, actually, many situations where a substantial amount of work is required in order to obtain a valid path and that work can all be encapsulated in a function:

" in after/ftplugin/yaml.vim
function HandleAzurePaths(fname)
    " your code here
endfunction
setlocal includeexpr=HandleAzurePaths(v:fname)

If your logic in lines 677-694 works, you should be able to fit it there and make it return x… without having to deal with "real" gf and "fake" gf.

FWIW, I use such a function for JavaScript, where I reimplemented Node's module resolution algorithm in about 100 lines so don't feel constrained, here.