cocopon/vaffle.vim

Vaffle seems delete the previous buffer after/with d85164a commit

Closed this issue ยท 9 comments

  • OS: macOS 10.14.6
  • Vim: MacVim v8.1.2102 / Neovim v0.5.0-2e14dffbb

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

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.

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.

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

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.

That's neat, glad you solved it.

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!

@cocopon I confirmed it fixed. Thanks!

@cocopon I am sorry, I think there are still bugs after this fix 0bc35d2 .

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.

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