lambdalisue / vim-fern-mapping-project-top

MIT License
7 stars 1 forks source link

[Feature Request] Provide option to always open directory of nearest .git folder #2

Closed IgorGee closed 4 years ago

IgorGee commented 4 years ago

I see there is a section in the wiki about this, but I was unable to get it to work.

Wiki

Not sure if it's outdated, because I don't see any references to fern-my-enter-project-root.

Here is what I have:

function! s:map_enter_project_root(helper) abort
  " NOTE: require 'file' scheme
  let root = a:helper.get_root_node()
  let path = root._path
  let path = finddir('.git/..', path . ';')
  execute printf('Fern %s', fnameescape(path))
endfunction

function! FernInit() abort
  " Find and enter project root
  nnoremap <buffer><silent>
        \ <Plug>(fern-my-enter-project-root)
        \ :<C-u>call fern#helper#call(funcref('<SID>map_enter_project_root'))<CR>
  nmap <buffer><expr><silent>
        \ ^
        \ fern#smart#scheme(
        \   "^",
        \   {
        \     'file': "\<Plug>(fern-my-enter-project-root)",
        \   }
        \ )
  ...
endfunction

augroup FernGroup
  autocmd!
  autocmd FileType fern call FernInit()
augroup END
lambdalisue commented 4 years ago

I don't get the question or request. It seems what you explained is what exactly this plugin (fern-mapping-project-top.vim) does.

IgorGee commented 4 years ago

This plugin is providing the action to take to me to the project top. But I'd like this to happen automatically when I open fern.

I tried implementing that functionality according to the wiki, but it wasn't working.

lambdalisue commented 4 years ago

But I'd like this to happen automatically when I open fern.

I'm not sure if I got your question correctly but it sounds like you'd like to open fern on the project root of the current working directory right?

Then

  1. Find a project root from cwd
  2. Use that path to open fern

e.g.

function! s:my_fern() abort
  let path = getcwd()
  let found = find('.git/..', path . ';')
  let path = empty(found) ? path : found
  let path = fnamemodify(path, ':p')
  execute printf('Fern %s', fnameescape(path))
endfunction

nnoremap <silent> <Leader>f :<C-u>call <SID>my_fern()<CR>
IgorGee commented 4 years ago

Almost.

Say I have the following directory:

dotfiles/x/.c/n/m/zsh

And the following file:

dotfiles/x/.c/n/m/zsh/abc.sh

If I'm editing abc.sh while my pwd is dotfiles/x/.c/n/m/zsh and I open fern, I want fern to show me everything underneath dotfiles, and the cursor on abc.sh.

This is my desired end-result when opening fern while editing post-compinit.zsh: image

If fern-action-project-top is triggered from here:

image

This is my end result:

image

lambdalisue commented 4 years ago

Then use -reveal=% like

function! s:my_fern() abort
  let path = getcwd()
  let found = find('.git/..', path . ';')
  let path = empty(found) ? path : found
  let path = fnamemodify(path, ':p')
  execute printf('Fern %s -reveal=%%', fnameescape(path))
endfunction

nnoremap <silent> <Leader>f :<C-u>call <SID>my_fern()<CR>
lambdalisue commented 4 years ago

Ah, I think I got it. Yes, the project-top action does NOT reveal. I'll add extra mappings for that.

lambdalisue commented 4 years ago

Please update the plugin and try project-top:reveal action. @IgorGee

IgorGee commented 4 years ago

Perfect.

I appreciate the quick responses and turnaround!