nvimdev / spaceline.vim

vim statusline like spacemacs
MIT License
281 stars 23 forks source link

E254: Cannot allocate color #50

Closed edaplayer closed 4 years ago

edaplayer commented 4 years ago

I had the problem after install,i use vim 8.2.1076 not neovim.

Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[6]..66_ActiveStatusLine[1]..
spaceline#syntax#icon_syntax:
line 7:
E254: Cannot allocate color #
E254: Cannot allocate color #
Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[7]..spaceline#colorscheme_init[3]
..spaceline#colorscheme#space#space[90]..spaceline#colors#spaceline_hl:
line 28:
E254: Cannot allocate color #234
E254: Cannot allocate color #234
E254: Cannot allocate color #234
E254: Cannot allocate color #234
Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[6]..66_ActiveStatusLine[1]..
spaceline#syntax#icon_syntax:
line 7:
E254: Cannot allocate color #261
E254: Cannot allocate color #261
Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[7]..spaceline#colorscheme_init[3]
..spaceline#colorscheme#space#space[90]..spaceline#colors#spaceline_hl:
line 28:
E254: Cannot allocate color #234
E254: Cannot allocate color #234
E254: Cannot allocate color #234
E254: Cannot allocate color #234
Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[6]..66_ActiveStatusLine[1]..
spaceline#syntax#icon_syntax:
line 7:
E254: Cannot allocate color #261
E254: Cannot allocate color #261
Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[7]..spaceline#colorscheme_init[3]
..spaceline#colorscheme#space#space[90]..spaceline#colors#spaceline_hl:
line 28:
glepnir commented 4 years ago

Did you set the termguicolors?

edaplayer commented 4 years ago

Did you set the termguicolors? 我是在securecrt上远程ssh使用vim的,是虚拟终端。 设置termguicolors之后变成黑白色了,也会报错: Error detected while processing function spaceline#spacelinetoggle[2]..66_SetStatusline[6]..66_ActiveStatusLine[1].. spaceline#syntax#icon_syntax: line 7: E254: Cannot allocate color # E254: Cannot allocate color #

glepnir commented 4 years ago

没法重现。最小配置.vim 8.1

set runtimepath+=~/workstation/vim/spaceline.vim
set runtimepath+=~/.cache/vim/dein/repos/github.com/ryanoasis/vim-devicons

set laststatus=2
set termguicolors
syntax on

image

edaplayer commented 4 years ago

看信息似乎是这个函数第7行出了问题,你的vim-devicons是最新版本的吗?

59 function! spaceline#syntax#icon_syntax()
 60     let icon = substitute(WebDevIconsGetFileTypeSymbol(), "\u00A0", '', '') 
 61     let bg_color = substitute(synIDattr(hlID("FileName"), "bg"),'#','','') 
 62  
 63     for color in keys(g:coldevicons_iconmap) 
 64         let index = index(g:coldevicons_iconmap[color], icon) 
 65         if index != -1 
 66           execute 'highlight! FileIcon'.color.' guifg=#'.g:coldevicons_colormap[color].' ctermfg='.s:rgb(g:coldevicons_colormap[color]) . ' guibg=#' . bg_color 
glepnir commented 4 years ago

那只是图标。提示不能解析颜色索引。我这边试了最小配置是没问题的。 不清楚你的环境了。

edaplayer commented 4 years ago

我屏蔽 execute 这行就不会报错了

glepnir commented 4 years ago

肯定啊 都不执行高亮文件图标颜色了哪里还有错误。问题不是出在代码上。

edaplayer commented 4 years ago

不管是不是代码问题,问题总要解决啊,我把颜色打印出来,bg_color是空值, 那么let bg_color = substitute(synIDattr(hlID("FileName"), "bg"),'#','','') 返回空值,这里为什么拿不到FileName语法颜色才是问题点

glepnir commented 4 years ago

Filename 是旁边文件名称的背景颜色。如果是space主题 拿到是紫色purple 加载了主题就肯定能拿到颜色值https://github.com/hardcoreplayers/spaceline.vim/blob/71d6dbacb9c011b74f3e1043bebee6edbbdd80c1/autoload/spaceline/colorscheme/space.vim#L87

edaplayer commented 4 years ago
"autoload/spaceline/syntax.vim" 273L, 7180B
bg_color=
Error detected while processing BufRead Autocommands for "*.vim"..FileType Autocommands for "*"..function spaceline#spacelinetoggle
[2]..<SNR>73_SetStatusline[6]..<SNR>73_ActiveStatusLine[1]..spaceline#syntax#icon_syntax:
line   11:
E254: Cannot allocate color #
bg_color=
E254: Cannot allocate color #
bg_color=50FA7B
bg_color=50FA7B
bg_color=50FA7B
bg_color=50FA7B

在初始化阶段没有拿到颜色值,第三次才拿到

glepnir commented 4 years ago

你用最新的测吧我两天前更了一下。

edaplayer commented 4 years ago

已经最新的了,今天刚下的,vim也是最新的

edaplayer commented 4 years ago

有可能c库版本太老,我这是ubuntu12.04,下次我试试换ubuntu看看

glepnir commented 4 years ago

你是怎么加载的?我试了最小配置怎么都没法重现。

glepnir commented 4 years ago

很多人用spaceline的都没出问题这块。所以很奇怪。和依赖没关系你vim能正常运行。

edaplayer commented 4 years ago

最小配置我试了,一样的现象

bg_color=
Error detected while processing BufRead Autocommands for "*vimrc*"..function <SNR>5_StarSetf[2]..FileType Autocommands for "*"..fun
ction spaceline#spacelinetoggle[2]..<SNR>26_SetStatusline[6]..<SNR>26_ActiveStatusLine[1]..spaceline#syntax#icon_syntax:
line   11:
E254: Cannot allocate color #
bg_color=
E254: Cannot allocate color #
Error detected while processing BufRead Autocommands for "*vimrc*"..function <SNR>5_StarSetf[2]..FileType Autocommands for "*"..fun
ction spaceline#spacelinetoggle[2]..<SNR>26_SetStatusline[7]..spaceline#colorscheme_init[3]..spaceline#colorscheme#space#space[29].
.spaceline#colors#spaceline_hl:
line   28:
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
bg_color=5d4d7a
bg_color=5d4d7a
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
E254: Cannot allocate color #NONE
edaplayer commented 4 years ago

我的vim编译配置是:

./configure --with-features=huge \
        --enable-multibyte \
        --enable-rubyinterp=yes \
        --enable-python3interp=yes \
        --with-python3-command=python3.8 \
        --with-python-config-dir=$HOME/.local/lib/python3.8/config-3.8-x86_64-linux-gnu \
        --enable-perlinterp=yes \
        --enable-cscope \
        --enable-luainterp \
        --with-lua-prefix=$HOME/.local \
        --prefix=$HOME/.local

没缺什么吧?

glepnir commented 4 years ago

能用dockerfile重现吗?你是自己build的吗。有些库需要挂vpn才能down把?

edaplayer commented 4 years ago

dockerfile没用过,我自己编译的vim,不需要vpn

edaplayer commented 4 years ago

换了14.04,一样的现象 ubuntu版本: ubuntu 12.04(64bit), 14.04,64bit vim版本: vim8.2.1551 vim-devicons版本 commit 308526367703698554d19f15f692ee3c45a598cb Merge: 712d1ab 8bc6634 Author: IK 36619465+kazukazuinaina@users.noreply.github.com Date: Sat Aug 15 01:01:18 2020 +0900

Merge pull request #353 from kazukazuinaina/update_gha

[update] github-actions
glepnir commented 4 years ago

我在centos试了下没有重现。我装个ubuntu试试。

edaplayer commented 4 years ago

加载顺序有问题,icon_syntax调用得太早了 我加了两行log

diff --git a/autoload/spaceline/colorscheme/space.vim b/autoload/spaceline/colorscheme/space.vim
index 0e93878..2425f9c 100644
--- a/autoload/spaceline/colorscheme/space.vim
+++ b/autoload/spaceline/colorscheme/space.vim
@@ -84,6 +84,7 @@ function! spaceline#colorscheme#space#space()
   endif

   call spaceline#colors#spaceline_hl('InActiveFilename', s:slc, 'lightgray', 'navy')
+  echom 'call spaceline_hl'
   call spaceline#colors#spaceline_hl('FileName', s:slc, 'aqua', 'purple','bold')
   call spaceline#colors#spaceline_hl('Filesize', s:slc, 'green', 'navy')
   call spaceline#colors#spaceline_hl('HeartSymbol', s:slc, 'orange',  'navy')
diff --git a/autoload/spaceline/syntax.vim b/autoload/spaceline/syntax.vim
index 2c8f413..580da2e 100644
--- a/autoload/spaceline/syntax.vim
+++ b/autoload/spaceline/syntax.vim
@@ -59,6 +59,7 @@ endif
 function! spaceline#syntax#icon_syntax()
     let l:icon = substitute(WebDevIconsGetFileTypeSymbol(), "\u00A0", '', '')
     let l:bg_color = substitute(synIDattr(hlID("FileName"), "bg"),'#','','')
+       echom 'bg_color=' . l:bg_color

     for color in keys(g:coldevicons_iconmap)
         let l:icon_index = index(g:coldevicons_iconmap[color], l:icon)

结果先调用icon_syntax,才调用Filename颜色初始化函数 spaceline#colors#spaceline_hl('FileName', s:slc, 'aqua', 'purple','bold')

"colorscheme/space.vim" 115L, 7044B
bg_color=
Error detected while processing BufRead Autocommands for "*.vim"..FileType Autocommands for "*"..function spaceline#spacelinetoggle
[2]..<SNR>73_SetStatusline[6]..<SNR>73_ActiveStatusLine[1]..spaceline#syntax#icon_syntax:
line    8:
E254: Cannot allocate color #
bg_color=
E254: Cannot allocate color #
call spaceline_hl
bg_color=5d4d7a
bg_color=5d4d7a
call spaceline_hl
edaplayer commented 4 years ago

看调用顺序:

 1: ~/.vimrc
  2: ~/.local/share/vim/vim82/syntax/syntax.vim
  3: ~/.local/share/vim/vim82/syntax/synload.vim
  4: ~/.local/share/vim/vim82/syntax/syncolor.vim
  5: ~/.local/share/vim/vim82/filetype.vim
  6: ~/.local/share/vim/vim82/plugin/getscriptPlugin.vim
  7: ~/.local/share/vim/vim82/plugin/gzip.vim
  8: ~/.local/share/vim/vim82/plugin/logiPat.vim
  9: ~/.local/share/vim/vim82/plugin/manpager.vim
 10: ~/.local/share/vim/vim82/plugin/matchparen.vim
 11: ~/.local/share/vim/vim82/plugin/netrwPlugin.vim
 12: ~/.local/share/vim/vim82/plugin/rrhelper.vim
 13: ~/.local/share/vim/vim82/plugin/spellfile.vim
 14: ~/.local/share/vim/vim82/plugin/tarPlugin.vim
 15: ~/.local/share/vim/vim82/plugin/tohtml.vim
 16: ~/.local/share/vim/vim82/plugin/vimballPlugin.vim
 17: ~/.local/share/vim/vim82/plugin/zipPlugin.vim
 18: ~/.vim/plugged/spaceline.vim/plugin/statusline.vim
 19: ~/.vim/plugged/spaceline.vim/autoload/spaceline/seperator.vim
 20: ~/.vim/plugged/vim-devicons/plugin/webdevicons.vim
 21: ~/.local/share/vim/vim82/scripts.vim
 22: ~/.local/share/vim/vim82/syntax/vim.vim
 23: ~/.local/share/vim/vim82/syntax/lua.vim
 24: ~/.local/share/vim/vim82/syntax/ruby.vim
 25: ~/.local/share/vim/vim82/syntax/python.vim
 26: ~/.vim/plugged/spaceline.vim/autoload/spaceline.vim
 27: ~/.vim/plugged/spaceline.vim/autoload/spaceline/syntax.vim
 28: ~/.vim/plugged/spaceline.vim/autoload/spaceline/diagnostic.vim
 29: ~/.vim/plugged/spaceline.vim/autoload/spaceline/file.vim
 30: ~/.vim/plugged/spaceline.vim/autoload/spaceline/vcs.vim
 31: ~/.vim/plugged/spaceline.vim/autoload/spaceline/colorscheme/space.vim
 32: ~/.vim/plugged/spaceline.vim/autoload/spaceline/colors.vim
 33: ~/.vim/plugged/spaceline.vim/autoload/spaceline/vimode.vim
 34: ~/.vim/plugged/spaceline.vim/autoload/spaceline/utils.vim
 35: ~/.vim/plugged/spaceline.vim/autoload/spaceline/status.vim
 36: ~/.vim/plugged/spaceline.vim/autoload/spaceline/vista.vim
 37: ~/.vim/plugged/spaceline.vim/autoload/spaceline/scrollbar.vim
edaplayer commented 4 years ago

问题在于如何让space.vim早于syntax.vim运行?

glepnir commented 4 years ago

你这个顺序每次都是固定的?

glepnir commented 4 years ago

这里是加载,你把顺序换一下试试吧 https://github.com/hardcoreplayers/spaceline.vim/blob/71d6dbacb9c011b74f3e1043bebee6edbbdd80c1/autoload/spaceline.vim#L136-L137

glepnir commented 4 years ago

解决了应该在vim 8.2复现了。试了下没问题。

jacobkim9881 commented 3 years ago

set termguicolors

@glepnir This worked for me, thanks!