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

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

Open
thanhnguyen2187 opened this issue May 8, 2024 · 6 comments

Comments

@thanhnguyen2187
Copy link

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
Copy link
Owner

jpalardy commented May 9, 2024

hi @thanhnguyen2187

can you confirm your setup?

  • OS?
  • target?
  • neovim? (rather than vim)

and anything else that you customized?

@thanhnguyen2187
Copy link
Author

thanhnguyen2187 commented May 9, 2024

Sorry I missed that. Here is my setup:

  • NixOS and Home Manager, both at 23.11
  • Neovim's version is 0.9.4

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`
" 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 <Tab> in the file counts for
set softtabstop=4 " sts ; number of spaces a <Tab> 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 <c-c><c-s> <Plug>SlimeSendCell

" Easy Align
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(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
Copy link
Owner

jpalardy commented May 9, 2024

@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
Copy link
Contributor

jam1015 commented May 10, 2024

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
Copy link
Author

thanhnguyen2187 commented May 11, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants