cocopon / vaffle.vim

:file_folder: Lightweight, window-based file manager for Vim
MIT License
284 stars 20 forks source link

Vaffle seems delete the previous buffer after/with d85164a commit #31

Closed markwu closed 4 years ago

markwu commented 5 years ago

Before d85164a commit, I can open multiple buffers without any problems. You can see there are 2 buffers after open with Vaffle multiple times. before

Within d85164a commit, Vaffle seems delete/remove/replace previous buffer after open another file. You can see there are only 1 buffer left, and the other is gone. after

nganhkhoa commented 5 years ago

This is confirmed too on Arch Linux. The default behaviour is somehow different, and quite annoying to edit multiple files.

It still works though, the file is change to accept file as an argument, but not directory. Change the command to :Vaffle %:p<CR> will resolve the issue.

The document is changed from Vaffle {dir} to Vaffle {file} too. The command is better then before, it can open and jump to the current file name of the current file.

However, I still think Vaffle {dir} is needed in some case when we want to open another directory outside the current file, or when the buffer is empty.

nganhkhoa commented 5 years ago
function! OpenVaffle() abort
  if bufname('%') == ''
    call vaffle#init()
  else
    call vaffle#init(expand('%:p'))
  endif
endfunction
nnoremap <leader>dd :call OpenVaffle()<CR>  # map to yours

The :Vaffle %:p<CR> will fail on empty buffer, so I have a work arround. You can try this.

markwu commented 5 years ago

Thank you, I really appreciate that. I will try to adapt this script.

markwu commented 5 years ago

I found I have my personal focus feature before d85164a based on search to do the same thing.

function! <SID>OpenVaffleUnderBuffer()
    let name = expand('%:t')
    let file = expand('%:p')
    let folder = expand('%:p:h')
    if !empty(name) && filereadable(file)
        let last_search = @/
        let @/ = '\<'.name.'\>'
        execute ':Vaffle' . folder
        execute 'normal n'
        let @/ = last_search
    else
        execute ':Vaffle' . folder
    endif
endfunction

Now, I just need to change the script to

function! <SID>OpenVaffleUnderBuffer()
    let name = expand('%:t')
    let file = expand('%:p')
    let folder = expand('%:p:h')
    if !empty(name) && filereadable(file)
        execute ':Vaffle' . file
    else
        execute ':Vaffle' . folder
    endif
endfunction

The problem just solved. Thanks for your hint.

nganhkhoa commented 5 years ago

That's neat, glad you solved it.

cocopon commented 4 years ago

Thank you for reporting and investigating the issue. I added a test case for this and fixed the problem in the latest commit 0bc35d2. Please try it!

markwu commented 4 years ago

@cocopon I confirmed it fixed. Thanks!

markwu commented 4 years ago

@cocopon I am sorry, I think there are still bugs after this fix https://github.com/cocopon/vaffle.vim/commit/0bc35d2a67149da74f3d4bdff41afd3ffd7d8ec8 .

The same scenario, you can produce the bug follow the steps:

  1. Assume we have 3 files,~/a/1.txt, ~/a/2.txt/,~/b/3.txt`.
  2. :Vaffle<cr>, and open ~/a/1.txt, use :ls, you will see ~/a/1.txt
  3. :Vaffle<cr>, and open ~/a/2.txt, use :ls, you will see ~/a/1.txt, ~/a/2.txt
  4. :Vaffle ~/b<cr>, and open /b/3.txt, use :ls, you will see ~/a/1.txt, ~/b/3.txt
  5. ~/a/2.txt just disappeared in (removed from) the buffer list.
markwu commented 4 years ago

If I use :edit ~/b to open the folder, vaffle works well. I don't need to change anything.

I also try to change the code like following, seems solve the problem, too.

  if !isdirectory(path)
    " Open new directory buffer and overwrite it
    " (will be initialized by vaffle#event#on_bufenter)
    let dir = fnamemodify(path, ':h')
    execute printf('edit %s', fnameescape(dir))

    call vaffle#buffer#move_cursor_to_path(
          \ fnamemodify(path, ':p'))
    return
  else
    execute printf('edit %s', fnameescape(path))
  endif