jpalardy / vim-slime

A vim plugin to give you some slime. (Emacs)
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
MIT License
1.89k stars 227 forks source link

"Undefined variable: g:slime_config_defaults" on opening Python files #432

Open thanhnguyen2187 opened 6 months ago

thanhnguyen2187 commented 6 months ago

Hi!

Thanks for the awesome plugin. I'm having a strange error on opening Python files, however:

Error detected while processing /home/thanh/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/_editor.lua:0: /home/thanh/.config/nvim/init.lua..nvim_exec2() called at /home/thanh/.config/nvim/init.lua:0../nix/store/b2vg1fd0v4f593wzxsi19grjv1bhq
izx-nvim-init-home-manager.vim[24]../nix/store/g8ywwhvf14qywy1zfg1fqyzylw4jj81x-neovim-unwrapped-0.9.4/share/nvim/runtime/syntax/syntax.vim[43]..BufReadPost Autocommands for "*": Vim(append):E
rror executing lua callback: ...x-neovim-unwrapped-0.9.4/share/nvim/runtime/filetype.lua:24: Error executing lua: ...x-neovim-unwrapped-0.9.4/share/nvim/runtime/filetype.lua:25: /home/thanh/.c
onfig/nvim/init.lua..nvim_exec2() called at /home/thanh/.config/nvim/init.lua:0../nix/store/b2vg1fd0v4f593wzxsi19grjv1bhqizx-nvim-init-home-manager.vim[24]../nix/store/g8ywwhvf14qywy1zfg1fqyzy
lw4jj81x-neovim-unwrapped-0.9.4/share/nvim/runtime/syntax/syntax.vim[43]..BufReadPost Autocommands for "*"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[19]..script /nix/store/k
19zs9pjq31danjixqxzw8bs70zb9p77-vimplugin-vim-slime-2023-11-04/ftplugin/python/slime.vim, line 2: Vim(let):E121: Undefined variable: g:slime_config_defaults
stack traceback:
        [C]: in function 'nvim_cmd'
        ...x-neovim-unwrapped-0.9.4/share/nvim/runtime/filetype.lua:25: in function <...x-neovim-unwrapped-0.9.4/share/nvim/runtime/filetype.lua:24>
...

The important part is:

function <SNR>1_LoadFTPlugin[19]..script /nix/store/k
19zs9pjq31danjixqxzw8bs70zb9p77-vimplugin-vim-slime-2023-11-04/ftplugin/python/slime.vim, line 2: Vim(let):E121: Undefined variable: g:slime_config_defaults

I tried using the latest version of vim-slime as I thought Home Manager/NixOS's version might have a problem but the error stays the same. What do you think?

Thanks!

jpalardy commented 6 months ago

hi @thanhnguyen2187

can you confirm your setup?

and anything else that you customized?

thanhnguyen2187 commented 6 months ago

Sorry I missed that. Here is my setup:

The configuration files for Neovim is generated by Home Manager, but I'm gonna simplify it by providing the relevant generated .vim file:

`init.vim` ```lua " Essential set number " nu ; show line number set relativenumber " rnu ; show relative line number set scrolloff=999 " so ; always put the cursor between screen vertically " set sidescrolloff=999 " siso ; always put the cursor between screen horizontally set textwidth=80 " tw ; set line length to 80 set colorcolumn=80 " cc ; highlight the maximal line length highlight ColorColumn ctermbg=238 " ; set the highlighting color to red set nowrap " ; make sure that text is not line-wrapped " Indentation set autoindent " ai ; copy indent from current line when starting a new line set smartindent " si ; do smart autoindenting when starting a new line set expandtab " et ; convert tab to spaces set tabstop=4 " ts ; number of spaces a in the file counts for set softtabstop=4 " sts ; number of spaces a counts for while performing editing operations set shiftwidth=4 " sw ; number of spaces to use for each step of (auto)indent " Windows set splitbelow " sb set splitright " spr " Syntax Highlighting syntax on filetype plugin on filetype plugin indent on " Other Options set background=dark " ; To fix Vim color within tmux " Clipboard Related function! s:setClipboard() set clipboard=unnamedplus endfunction function! s:unsetClipboard() set clipboard=unnamedplus endfunction command! SetClipboard :call s:setClipboard() command! UnsetClipboard :call s:unsetClipboard() " Neovim Specific set nohlsearch " nohl ; no highlight on searching nnoremap Y yy " Colorscheme Nord let g:nord_disable_background = v:true colorscheme nord " Lualine lua << END require('lualine').setup() END " Vim Slime let g:slime_target = "tmux" let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"} let g:slime_dont_ask_default = 1 autocmd FileType markdown let g:slime_cell_delimiter = "```" autocmd FileType scheme let g:slime_cell_delimiter = ";;;" nmap SlimeSendCell " Easy Align xmap ga (EasyAlign) nmap ga (EasyAlign) luafile /nix/store/190yjyvpdnxc09rfzgk6yv6bbw4238jr-source/configs/nvim/completion.lua luafile /nix/store/190yjyvpdnxc09rfzgk6yv6bbw4238jr-source/configs/nvim/lualine.lua luafile /nix/store/190yjyvpdnxc09rfzgk6yv6bbw4238jr-source/configs/nvim/firenvim.lua ```

Content of completion.lua and lualine.lua and firenvim.lua can be found in my dotfiles repository, but I think they are not relevant.

jpalardy commented 6 months ago

@jam1015 thoughts on this?

I don't know anything about nix, and I don't use neovim myself

I see this is the slime config (for tmux), but I don't know how neovim feels about vimscript config into lua 🤷

jam1015 commented 6 months ago

My lua config for tmux works fine with python. My guess is the issue with Nix because if you don't get everything right in Nix there are problems (aspiring to learn Nix soon). I'm not actually a Vim/Neovim expert so I'd like a more minimal config for testing than is shown above, preferably that automatically installs/configures slime, or with instructions to easily install it just for that config.

thanhnguyen2187 commented 6 months ago

I think I found a plausible explanation, which is Neovim's load order for configuration files generated by NixOS/Home Manager. This is the result of :scriptnames:

...
 22: /nix/store/5cjkv4mr882rwjhcsasjdn8smi9gy413-vimplugin-jpalardy-vim-slime-4a898d57f41bc35e99173c5a0a8720f1796459b5/ftplugin/python/slime.vim
 23: /nix/store/g8ywwhvf14qywy1zfg1fqyzylw4jj81x-neovim-unwrapped-0.9.4/share/nvim/runtime/ftplugin/python.vim
...
 48: /nix/store/5cjkv4mr882rwjhcsasjdn8smi9gy413-vimplugin-jpalardy-vim-slime-4a898d57f41bc35e99173c5a0a8720f1796459b5/autoload/slime/config.vim
...

g:slime_config_defaults was utilized by .../ftplugin/python/slime.vim before it is defined in .../autoload/slime/config.vim, and that caused the issue.

StefanHubner commented 5 months ago

I had the same issue. ftplugin is loaded before init.lua. I would suggest initialising let g:slime_config_defaults = {} in vim-slime/ftplugin/python/slime.vim which fixed it for me.