zefei / vim-wintabs

Modern buffer manager for Vim
MIT License
325 stars 25 forks source link

Add option to customise tabline #4

Closed joelmo closed 9 years ago

zefei commented 9 years ago

Thank you @joelmo for the request. However, I cannot merge your PR because of one reasons: wintabs tries very hard to keep long lines correctly truncated and positioned, customization is only possible if the user uses fixed-length custom strings and knows the exact extra length (will need an extra option for the length). My previous plugin buftabs allows that but that makes it very hard to use, for now I don't want to repeat this in wintabs.

joelmo commented 9 years ago

Has this to do with session options or why is this needed? I would really want to add the value returned from getcwd(), but I could truncate it with fnamemodify.

zefei commented 9 years ago

To keep the tabs string correctly truncated, wintabs must know exactly how many characters it will occupy, and that is the window width currently. If it instead relies on vim's native truncation, the current buffer and the highlight of it might be truncated out or incorrectly, so it must use its own truncation method. If you customize it, you have to subtract the extra number of chars you put in, but usually that is dynamic and can't be known in advance. You can check out my buftabs repo to see how that is done, it's not really hard for the plugin writer (only about 10 extra lines), but very confusing for users.

I initially wanted getcwd there too, but eventually I gave up and moved getcwd to statusline. Though more awkward than using tabline, the following code is what I use for my statusline (it chooses between git path and cwd to display, you can ignore the git part):

autocmd BufWinEnter,WinEnter,VimEnter * let w:getcwd = getcwd()
let &statusline = " %{StatuslineTag()} "
let &statusline .= "your other stuff"
function! StatuslineTag()
    if exists('b:git_dir')
        let dir = fnamemodify(b:git_dir[:-6], ':t')
        return dir." \ue0a0 ".fugitive#head(7)
    else
        return fnamemodify(getwinvar(0, 'getcwd', getcwd()), ':t')
    endif
endfunction
joelmo commented 9 years ago

Thanks I didn't think about the truncation, I will just use your satusline instead :sun_with_face: