EdenEast / nightfox.nvim

🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
MIT License
3.1k stars 143 forks source link

W18: Invalid character in group name (vim) #218

Closed jgb closed 1 year ago

jgb commented 1 year ago

Description

When starting vim/gvim with nightfox theme enabled, since yesterday I get this error repeated a few dozen times:

Error detected while processing nightfox.vim line 9:

W18: Invalid character in group name

I'm on vim 9.0.0626-1 on debian.

betolink commented 1 year ago

I just ran into this after reinstalling my plugins with neovim

EdenEast commented 1 year ago

This is due to commit 6585499. This change uses the current highlight groups for treesitter. Can you execute NightfoxCompile and see if that solves your issue.

betolink commented 1 year ago

I can confirm that NightfoxCompile fixed this on my end. Thanks @EdenEast!

jgb commented 1 year ago

@EdenEast the issue remains in vim/gvim (even if I do the NightfoxCompile in neovim first)

EdenEast commented 1 year ago

For vim could you try:

require("nightfox").setup({
  options = {
    modules = {
      native_lsp = {
        enable = false,
      },
      treesitter = false,
    },
  },
})

This would disable neovim specific modules.

oxalica commented 1 year ago

Could we disable incompatible modules by default?

EdenEast commented 1 year ago

If this did solve the issue I would set these modules to be enabled only if neovim. Still unsure about the precompiled files. These are only used if there is now setup function called and the user has not compiled themselves.

jgb commented 1 year ago

I don't know what the best solution is, but in the current state nightfox unfortuntely isn't really compatible with vanilla vim any longer.

name-andy46 commented 1 year ago

On win 11, upgrading Neovim from 0.7.2 to 0.8.0 fixed the issue. Used the command: winget upgrade Neovim

Eliot00 commented 1 year ago

NightfoxCompile throw an error: nightfox/lua/nightfox/lib/color.lua:105: attempt to index a nil value (upvalue 'bitopt')

Vim 9.0.800

zb140 commented 1 year ago

NightfoxCompile also fails for me with the same error message (Vim 9.0.844). I was going to try disabling the neovim modules as suggested in https://github.com/EdenEast/nightfox.nvim/issues/218#issuecomment-1285666881, but I just can't figure out where to put the config snippet. I'm sure I'm overlooking something obvious, but nothing I've tried has worked. The closest I got was putting it in a

lua << END
...
END

block but that throws an error that "module nightfox not found". I'd really appreciate any pointers anyone can give.

xuoe commented 1 year ago

@zb140, the updated version sets those values to whatever boolean util.is_nvim holds (I'd assume false if using vim), so you could modify the file (lua/nightfox/config.lua) directly and set it to false. Having done that myself, it makes no difference, NightfoxCompile still failing with:

lua/nightfox/lib/color.lua:206: bad argument #1 to 'lshift' (number has no integer representation)

Which is this line:

local bitopt = util.is_nvim and bit or bit32 or bit

Depending on whether I set this to bit or bit32, I either get the same error as above or the one mentioned by this comment.

I thought it had something to do with there being no Lua bitop library installed on my system (AFAIU, if you have vim compiled against LuaJIT, bitop should be included by default/bitops are builtin), but installing bitop didn't fix it either, and that may be because bitop is not compatible with Lua 5.3, which my binary happens to be compiled against.

Not sure what the solution is.

zb140 commented 1 year ago

Thanks @xuoe! That's actually given me enough to work with that I've actually got it working. There seems to be a couple of issues at play here:

  1. In order to be able to do bitwise math, some versions of Lua need bitop, some versions need bit32, and some versions (notably 5.3+) support bitwise operators natively.
  2. Color:to_hex() tries to perform bitwise math numbers that are not necessarily integers. Specifically, the individual color components are floats, and to_hex() just multiplies them by 0xff and passes them straight to lshift

I worked around these issues by replacing line 26 in color.lua with this code:

local function get_bitopt(op)
    return function(a,b)
        a = util.round(a)
        b = util.round(b)
        return op(a,b)
    end
end

local native_bitopt = {
    lshift = get_bitopt(function(a,b) return a << b end),
    rshift = get_bitopt(function(a,b) return a >> b end),
    band   = get_bitopt(function(a,b) return a & b end),
    bor    = get_bitopt(function(a,b) return a | b end),
}

local bitopt = util.is_nvim and bit or bit32 or bit or native_bitopt

Now :NightfoxCompile works fine, and I can use the color schemes without issue in Vim 9 😄

xuoe commented 1 year ago

Great work, @zb140! That solved it for me as well (I just replaced native_bitopt with bitopt in-place and ran :NightfoxCompile). Hadn't known Lua 5.3 had native support for bitwise operations.

EdenEast commented 1 year ago

Thanks to everyone for looking into this. I am thinking of using the solution @zb140 commented as a fallback if it cant find the neovim luajit is not found. That should handle different lua versions for the color lib.

EdenEast commented 1 year ago

I tried to have this working but you cant have 5.2 and 5.3 in the same file. There is no way to guard the >>.

zb140 commented 1 year ago

Depending on your appetite for dirty hacks, you might be able to get away with something like this:

local function get_bitopt(op)
    return function(a,b)
        a = util.round(a)
        b = util.round(b)
        return load("return " .. op)()(a,b)
    end
end

local native_bitopt = {
    lshift = get_bitopt("function(a,b) return a << b end"),
    rshift = get_bitopt("function(a,b) return a >> b end"),
    band   = get_bitopt("function(a,b) return a & b end"),
    bor    = get_bitopt("function(a,b) return a | b end"),
}

But everything I know about Lua I learned in the last 12 hours, so there may be good reasons to avoid it, even over and above the standard "eval is evil" arguments...

xuoe commented 1 year ago

@EdenEast, what about exporting bitop from two different files, one for Lua 5.3 (which exports @zb140's native bitop wrappers) and one for earlier versions (which exports either bit or bit32, as before), and then requireing one or the other in color.lua based on the value of _VERSION?

EDIT: or something like this:

local version = tonumber(string.sub(_VERSION, 5, 7)) -- LuaJIT-compatible
local bitop = version >= 5.3 and require("bitop_native") or (util.is_nvim and bit or bit32 or bit)
EdenEast commented 1 year ago

For others that were having issues with the compile file in vim could I get some help testing this pr #241 which makes the compiler automatic. This change should support vim better and be overall much faster.

I tested it with my nix-shell version of vim but testing on more setups would help.

Tested on ```console vim --version VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jan 01 1980 00:00:00) Included patches: 1-609 Compiled by nixbld Huge version with GTK3 GUI. Features included (+) or not (-): +acl +file_in_path +mouse_urxvt -tag_any_white +arabic +find_in_path +mouse_xterm -tcl +autocmd +float +multi_byte +termguicolors +autochdir +folding +multi_lang +terminal -autoservername -footer -mzscheme +terminfo +balloon_eval +fork() +netbeans_intg +termresponse +balloon_eval_term +gettext +num64 +textobjects +browse -hangul_input +packages +textprop ++builtin_terms +iconv +path_extra +timers +byte_offset +insert_expand -perl +title +channel +ipv6 +persistent_undo +toolbar +cindent +job +popupwin +user_commands +clientserver +jumplist +postscript +vartabs +clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +vim9script +cmdline_hist +langmap -python +viminfo +cmdline_info +libcall +python3 +virtualedit +comments +linebreak +quickfix +visual +conceal +lispindent +reltime +visualextra +cryptv +listcmds +rightleft +vreplace +cscope +localmap +ruby +wildignore +cursorbind +lua +scrollbind +wildmenu +cursorshape +menu +signs +windows +dialog_con_gui +mksession +smartindent +writebackup +diff +modify_fname -sodium +X11 +digraphs +mouse -sound -xfontset +dnd +mouseshape +spell +xim -ebcdic +mouse_dec +startuptime +xpm +emacs_tags -mouse_gpm +statusline -xsmp +eval -mouse_jsbterm -sun_workshop +xterm_clipboard +ex_extra +mouse_netterm +syntax -xterm_save +extra_search +mouse_sgr +tag_binary -farsi -mouse_sysmouse -tag_old_static system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" defaults file: "$VIMRUNTIME/defaults.vim" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: " /nix/store/rll1dln5lml9bayj6b0kkk50cbg7sklg-vim_configurable-9.0.0609/share/vim " Compilation: see nix-store --read-log /nix/store/rll1dln5lml9bayj6b0kkk50cbg7sklg-vim_configurable-9.0.0609 Linking: see nix-store --read-log /nix/store/rll1dln5lml9bayj6b0kkk50cbg7sklg-vim_configurable-9.0.0609 lua -v LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/ ```
tani commented 1 year ago

I have tested on feat/auto-compile branch. However, I still have the same issue.

[error][nightfox]: Unable to find lua library `bit` or `bit32`. Please make sure lua vesion is 5.1 or 5.2
/Users/xxxx/yyyy/vim/vimrc の処理中にエラーが検出されました:
行  179:
...m/pack/jetpack/opt/nightfox.nvim/lua/nightfox/config.lua:107: attempt to call a nil value (field 'hash')
:version

:version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 15 2022 18:56:17)
macOS 版 - x86_64
適用済パッチ: 1-472
Compiled by Homebrew
Huge 版 with MacVim GUI.  機能の一覧 有効(+)/無効(-)
+acl               +cmdline_hist      +ex_extra          +job               +mouseshape        +packages          +signs             +terminfo          +visualextra
+arabic            +cmdline_info      +extra_search      +jumplist          +mouse_dec         +path_extra        +smartindent       +termresponse      +vreplace
+autocmd           +comments          -farsi             +keymap            -mouse_gpm         +perl              -sodium            +textobjects       +wildignore
+autochdir         +conceal           +file_in_path      +lambda            -mouse_jsbterm     +persistent_undo   -sound             +textprop          +wildmenu
-autoservername    +cryptv            +find_in_path      +langmap           +mouse_netterm     +popupwin          +spell             +timers            +windows
+balloon_eval      +cscope            +float             +libcall           +mouse_sgr         +postscript        +startuptime       +title             +writebackup
+balloon_eval_term +cursorbind        +folding           +linebreak         -mouse_sysmouse    +printer           +statusline        +toolbar           -X11
+browse            +cursorshape       -footer            +lispindent        +mouse_urxvt       +profile           -sun_workshop      +transparency      -xfontset
++builtin_terms    +dialog_con_gui    +fork()            +listcmds          +mouse_xterm       -python            +syntax            +user_commands     +xim
+byte_offset       +diff              +fullscreen        +localmap          +multi_byte        +python3           +tag_binary        +vartabs           -xpm
+channel           +digraphs          +gettext           +lua               +multi_lang        +quickfix          -tag_old_static    +vertsplit         -xsmp
+cindent           +dnd               -hangul_input      +menu              -mzscheme          +reltime           -tag_any_white     +vim9script        -xterm_clipboard
+clientserver      -ebcdic            +iconv             +mksession         +netbeans_intg     +rightleft         +tcl               +viminfo           -xterm_save
+clipboard         +emacs_tags        +insert_expand     +modify_fname      +num64             +ruby              +termguicolors     +virtualedit
+cmdline_compl     +eval              +ipv6              +mouse             +odbeditor         +scrollbind        +terminal          +visual
      システム vimrc: "$VIM/vimrc"
      ユーザー vimrc: "$HOME/.vimrc"
   第2ユーザー vimrc: "~/.vim/vimrc"
       ユーザー exrc: "$HOME/.exrc"
     システム gvimrc: "$VIM/gvimrc"
     ユーザー gvimrc: "$HOME/.gvimrc"
  第2ユーザー gvimrc: "~/.vim/gvimrc"
  デフォルトファイル: "$VIMRUNTIME/defaults.vim"
    システムメニュー: "$VIMRUNTIME/menu.vim"
       省略時の $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
コンパイル: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -arch x86_64 -D_REENTRANT -U_FORTIFY_SOURCE
 -D_FORTIFY_SOURCE=1
リンク: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-str
ong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -arch x86_64 -L/usr/local/lib -o Vim -lm -lncurses -liconv /usr/
local/lib/libintl.a -framework AppKit -L/usr/local/opt/lua/lib -llua5.4 -L/System/Library/Perl/5.30/darwin-thread-multi-2level/CORE -lperl -L/usr/local/opt/python@3.10/Framework
s/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin -lpython3.10 -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -
lruby.3.1 -L/usr/local/Cellar/ruby/3.1.2_1/lib 
EdenEast commented 1 year ago

Thanks for checking it out. I have added a native bit file for 5.3 like the suggestion from @xuoe. Let me know it this solves your issue.

tani commented 1 year ago

Thank you for updating. I guess that you forgot to add bxor in native_bitops.lua

EdenEast commented 1 year ago

Resolved with #241