Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use nerdfont.vim plugin to display devicons #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ tabline works and looks like.
| `g:buffet_separator` | `''` | The character to be used for separating items in the tabline |
| `g:buffet_show_index` | `0` | Set to `1`, show index before each buffer name. Index is useful for switching between buffers quickly |
| `g:buffet_max_plug` | `10` | The maximum number of `<Plug>BuffetSwitch` provided. Mapping will be disabled if the option is set to `0` |
| `g:buffet_use_devicons` | `1` | If set to `1` and [`vim-devicons`](https://github.com/ryanoasis/vim-devicons) plugin is installed, show file type icons for each buffer in the tabline. If the `vim-devicons` plugin is not present, the option will automatically default to `0` (*Note: you need to have `vim-devicons` loaded before `vim-buffet` in order to make this work*) |
| `g:buffet_use_devicons` | `1` | If set to `1` and either [`vim-devicons`](https://github.com/ryanoasis/vim-devicons) or [`nerdfont.vim`](https://github.com/lambdalisue/nerdfont.vim) plugin is installed, show file type icons for each buffer in the tabline. If neither plugin is present, the option will automatically default to `0`. |
| `g:buffet_tab_icon` | `'#'` | The character to be used as an icon for the tab items in the tabline |
| `g:buffet_new_buffer_name` | `'*'` | The character to be shown as the name of a new buffer |
| `g:buffet_modified_icon` | `'+'` | The character to be shown by the name of a modified buffer |
Expand Down
26 changes: 23 additions & 3 deletions autoload/buffet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ function! s:Render()
let trunc_len = left_trunc_len + right_trunc_len

let capacity = &columns - tabs_len - trunc_len - 5
let buffer_padding = 1 + (g:buffet_use_devicons ? 1+1 : 0) + 1 + sep_len

let devicon_func = buffet#get_devicon_func()
let use_devicon = !empty(devicon_func)

let buffer_padding = 1 + (use_devicon ? 1+1 : 0) + 1 + sep_len

let elements = s:GetAllElements(capacity, buffer_padding)

Expand All @@ -293,8 +297,8 @@ function! s:Render()
endif

let icon = ""
if g:buffet_use_devicons && s:IsBufferElement(elem)
let icon = " " . WebDevIconsGetFileTypeSymbol(elem.value)
if use_devicon && s:IsBufferElement(elem)
let icon = " " . call(devicon_func, [elem.value])
elseif elem.type == "Tab"
let icon = " " . g:buffet_tab_icon
endif
Expand Down Expand Up @@ -430,3 +434,19 @@ function! buffet#bonly(bang, buffer)
call buffet#bwipe(a:bang, b)
endfor
endfunction

function! buffet#get_devicon_func()
if !exists("g:buffet_devicon_func")
if !get(g:, "buffet_use_devicons", 1)
let devicon_func = ""
elseif exists("*WebDevIconsGetFileTypeSymbol")
let devicon_func = "WebDevIconsGetFileTypeSymbol"
elseif exists("*nerdfont#find")
let devicon_func = "nerdfont#find"
else
let devicon_func = ""
endif
let g:buffet_devicon_func = devicon_func
endif
return g:buffet_devicon_func
endfunction
10 changes: 0 additions & 10 deletions plugin/buffet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ let g:buffet_show_index = get(g:, "buffet_show_index", 0)

let g:buffet_max_plug = get(g:, "buffet_max_plug", 10)

if get(g:, "buffet_use_devicons", 1)
if !exists("*WebDevIconsGetFileTypeSymbol")
let g:buffet_use_devicons = 0
else
let g:buffet_use_devicons = 1
endif
else
let g:buffet_use_devicons = 0
endif

if !exists("g:buffet_modified_icon")
let g:buffet_modified_icon = "+"
endif
Expand Down