lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

Avoid "E499: Empty file name for '%' or '#'" when Fern . -reveal=% has called just after Vim started #95

Closed jesseleite closed 4 years ago

jesseleite commented 4 years ago

Would you consider adding a reveal command something like this? I've been using the below script for a bit and love it. I'm sure my vimscript could be cleaned up, but the idea is this...

Thoughts?

function! FernReveal(location)
  let current_file = match(@%, '/') == 0 ? @% : getcwd() . '/' . @%
  if empty(@%)
    exec 'Fern ' . a:location
  elseif filereadable(current_file)
    exec 'Fern ' . a:location . ' -reveal=%'
  else
    exec 'Fern ' . substitute(@%, '/'. expand('%:t'), '', '') . ' -reveal=%'
  endif
endfunction

command! -nargs=* FernReveal call FernReveal(<f-args>)
lambdalisue commented 4 years ago

If no buffers are open, instead of showing an error it falls back to :Fern .

I'm not sure why you need to fallback to :Fern . when no buffers are opened. Fern does not claim when a path specified to -reveal exists so you can simply use :Fern . -reveal=% in both case.

If the open buffer is not within the current working directory, reveal the file within it's parent folder instead.

I feel it's quite personal behavior. I think it's better to write a tips on Wiki rather than providing the functionality.

jesseleite commented 4 years ago

I'm not sure why you need to fallback to :Fern . when no buffers are opened. Fern does not claim when a path specified to -reveal exists so you can simply use :Fern . -reveal=% in both case.

Well the idea is that I don't want to have to setup two mappings for :Fern . and :Fern . -reveal=%. If I use :Fern . -reveal=% in both cases, I see an error when no buffers are open. Say a user opens a fresh instance of Vim and decides to hit their single :Fern . -reveal=% mapping to open their first file, they'll see this error...

image

I'm falling back to :Fern . to avoid showing that error. Or would you consider that error a bug?

If the open buffer is not within the current working directory, reveal the file within it's parent folder instead. [...] I feel it's quite personal behavior. I think it's better to write a tips on Wiki rather than providing the functionality.

That point is fair; I can see how that's maybe a bit more subjective 🙂

lambdalisue commented 4 years ago

they'll see this error...

Thanks. I've forgotten that error. Now what you said makes sense.

Or would you consider that error a bug?

It's.... not a bug but I agree that it's much easier if the error is not raised. I'll try to make Fern . -reveal=% avoids E499 automatically.

lambdalisue commented 4 years ago

I'm sorry but I could not reproduce E499 somehow in Vim 8.2.654

asciicast

with the following vimrc

set runtimepath+=~/.ghq/github.com/lambdalisue/fern.vim

filetype plugin indent on

Could you make a minimal vimrc to reproduce E499

jesseleite commented 4 years ago

@lambdalisue interesting, I don't get the error with that minimal vimrc either. I'll see if I can find the conflicting config and will get back to you. Thanks!