Skip to content

Conversation

@lambdalisue
Copy link
Owner

@lambdalisue lambdalisue commented Aug 11, 2020

Add FernReveal buffer local command

Fix #114

Users can reveal a path on the current fern viewer with FernReveal {reveal} [-wait] command.
Use FernDo command to execute FernReveal from different buffer.

Kapture 2020-08-12 at 2 44 13

-reveal option of Fern command always reveal the node

Fix #146

Kapture 2020-08-12 at 2 46 42

@nickjj
Copy link

nickjj commented Aug 11, 2020

If I have 2 files in a directory and open them in splits.

If I keep toggling noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR><C-w>= it doesn't select the file I was previously at. It will alternate between revealing / highlighting the file and the root node every time I toggle.

@lambdalisue
Copy link
Owner Author

@nickjj Thanks. I've fixed the behavior so please try latest again 👍

@nickjj
Copy link

nickjj commented Aug 11, 2020

Confirmed fixed. Also vs master (not fixed), the 2nd split file never gets selected while toggle revealing, so whatever you did seems to be for the better.

Unrelated but relevant issue: If you vim . and have fern set to open automatically on directories, toggling fern open with the same bind mentioned before will open a 2nd instance of fern. Is there a way to detect if fern is already open and modify the state of it instead of open a 2nd one? The only way to get around this is to manually close the fern buffer that was opened during vim ..

@lambdalisue
Copy link
Owner Author

Unrelated but relevant issue: If you vim . and have fern set to open automatically on directories, toggling fern open with the same bind mentioned before will open a 2nd instance of fern. Is there a way to detect if fern is already open and modify the state of it instead of open a 2nd one? The only way to get around this is to manually close the fern buffer that was opened during vim ..

I don't get your situation. Are you using "hijack netrw" so that vim . opens a fern buffer? In that case, the buffer opened by vim . is split windows style rather than project drawer style. That's why executing :Fern . -drawer -toggle open a project drawer styled fern while no project drawer styled fern exists in the current tab.

If you desire, you can write some Vim script to check if you are on split windows style but I think you don't need it while the usage of split windows style is completely different from project drawer style and -toggle like feature is useless in most case.

" The script below may not work in the future while it relys on non documented behavior
function! s:smart_fern() abort
  let bufname = bufname('%')
  if bufname =~# '^fern://` && bufname !~# '^fern://drawer'
    " On split windows style
    execute "normal! \<C-^>"
  else
    " Others
    Fern . -drawer -reveal=% -toggle -width=35 -wait
    execute "normal! \<C-w>="
  endif
endfunction
nnoremap <silent> <Leader>f :<C-u>call <SID>smart_fern()<CR>

P.S.

You should use -wait if you want to execute some command after while :Fern works asynchronously and <C-w>= may be executed during fern startup

nnoremap <silent> <Leader>f :<C-u>Fern . -drawer -reveal=% -toggle -width=35 -wait<CR><C-w>=

@lambdalisue lambdalisue merged commit e8f6327 into master Aug 12, 2020
@lambdalisue lambdalisue deleted the fix-reveal branch August 12, 2020 00:42
@nickjj
Copy link

nickjj commented Aug 12, 2020

If you desire, you can write some Vim script to check if you are on split windows style but I think you don't need it.

Is there some combo of flags I can use to avoid writing using the custom Vim script that may not work in the future?

One that says "open fern in project drawer if there's no fern, but if fern is open already in split mode, close that one first".

And yes, I am using the hjack code from the wiki.

@lambdalisue
Copy link
Owner Author

Unfortunately no while

One that says "open fern in project drawer if there's no fern, but if fern is open already in split mode, close that one first".

Is not clear enough. There are too many situations to care. For example, what you expect for "closing" when there are two windows and one is the fern. Close the window itself or replace it to a new buffer or replace it with a previous buffer or? What do you expect if there are two tab pages and only one window in the current tab page? Like this. So the usage of a split window is completely different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants