itchyny / lightline.vim

A light and configurable statusline/tabline plugin for Vim
MIT License
6.74k stars 313 forks source link

[plugin integration] lightline it's calling with default values when changing the color scheme #497

Closed ivanruvalcaba closed 4 years ago

ivanruvalcaba commented 4 years ago

Nice day!

I'm currently trying to get the night-day plugin working, a plugin whose function is to change the editor's color scheme at a certain time, for its integration with lightline without much success. Although this plugin works properly when changing the color scheme of Vim and lightline at the right time, it seems that when doing so lightline is executed with the default values.

For example, my current configuration of lightline is as follows:

let g:lightline = {
    \ 'colorscheme': 'monokai_pro',
    \ 'active': {
        \ 'left': [
            \ [ 'mode', 'paste' ],
            \ [ 'readonly', 'filename', 'spell', 'modified' ]
        \ ],
        \ 'right': [
            \ [ 'lessmess', 'lineinfo' ],
            \ [ 'percent' ],
            \ [ 'fugitive', 'gitgutter', 'fileformat', 'fileencoding', 'filetype' ]
        \ ]
    \ },
    \ 'component': {
        \ 'filename': '%f%<',
        \ 'lineinfo': ' %3l:%-2v'
    \ },
    \ 'component_function': {
        \ 'filename': 'LightlineFilename',
        \ 'readonly': 'LightlineReadonly',
        \ 'fugitive': 'LightlineFugitive',
        \ 'gitgutter': 'LightLineGitGutter',
        \ 'lessmess': 'Lessmess'
    \ }
\ }

function! LightlineFilename()
    let fname = expand('%:t')
    return fname ==# 'ControlP' && has_key(g:lightline, 'ctrlp_item') ? g:lightline.ctrlp_item :
        \ fname =~# '^__Tagbar__\|__Gundo\|NERD_tree' ? '' :
        \ &ft ==# 'vimfiler' ? vimfiler#get_status_string() :
        \ &ft ==# 'unite' ? unite#get_status_string() :
        \ &ft ==# 'vimshell' ? vimshell#get_status_string() :
        \ (fname !=# '' ? fname : '[No Name]')
endfunction

function! LightlineReadonly()
    return &readonly ? '' : ''
endfunction

function! LightlineFugitive()
    if exists('*FugitiveHead')
        let branch = FugitiveHead()
        return branch !=# '' ? ' '.branch : ''
    endif
    return ''
endfunction

function! LightLineGitGutter()
    if exists('*GitGutterGetHunkSummary')
        let [ added, modified, removed ] = GitGutterGetHunkSummary()
        return printf('+%d ~%d -%d', added, modified, removed)
    endif

    return ''
endfunction

function! Lessmess()
    if exists('*lessmess#statusline')
        return lessmess#statusline()
    endif

    return ''
endfunction

And once the color scheme is changed through night-day, the lightline configuration becomes the following visually:

let g:lightline.active = {
    \ 'left': [ [ 'mode', 'paste' ],
    \           [ 'readonly', 'filename', 'modified' ] ],
    \ 'right': [ [ 'lineinfo' ],
    \            [ 'percent' ],
    \            [ 'fileformat', 'fileencoding', 'filetype' ] ] }
let g:lightline.inactive = {
    \ 'left': [ [ 'filename' ] ],
    \ 'right': [ [ 'lineinfo' ],
    \            [ 'percent' ] ] }
let g:lightline.tabline = {
    \ 'left': [ [ 'tabs' ] ],
    \ 'right': [ [ 'close' ] ] }

In the process, all custom settings made to lightline are lost visually.

I've superficially checked the plugin code to try to find some inconsistencies that could affect the correct functioning of lightline but I didn't find anything significant. night-day executes the following function, which appears in the lightline documentation:

""" DEFINE SWITCH FUNCTIONS (for switching theme/background if necessary)

" lightline theme switching
function! NdSetLightlineColorscheme(name)
    let g:lightline = { 'colorscheme': a:name }
    call lightline#init()
    call lightline#colorscheme()
    call lightline#update()
endfunction

My setup for the night-day plugin is:

let g:nd_themes = [
    \ ['7:00', 'nord', 'dark', 'nord'],
    \ ['20:00', 'dracula', 'dark', 'darcula'],
\ ]

let g:nd_lightline = 1

Any kind of help is welcome!

Regards.

itchyny commented 4 years ago

let g:lightline = { 'colorscheme': a:name } clears all the configuration except for the colorscheme, so lightline#init initilizes the configuration with its defaults. Please fix this to let g:lightline.colorscheme = a:name.

ivanruvalcaba commented 4 years ago

Wow! It's works! Thanks a lot!