cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
1.01k stars 46 forks source link

Newline rules throw "Undefined variable: dummy" in Python + Neovim #97

Closed staticshock closed 4 years ago

staticshock commented 4 years ago

To reproduce, open this python file in Neovim, and try to add a newline inside the [] (yes, it appears like it must be at least this long to reproduce the bug):

def foo():
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass
    pass

def foo():
    foo = []

Here's the error that I'm seeing:

Error detected while processing function lexima#insmode#_map_impl[1]..<SNR>68_map_impl[35]..<SNR>68_input[22]..GetPythonIndent:
line   71:
E121: Undefined variable: dummy

I haven't looked too closely, but this seems related:

https://github.com/neovim/neovim/blob/2b00d1d09c0ff7ee6cc2de7ba70d9e84167540e5/runtime/indent/python.vim#L73-L74

Classic vim uses the same trick, so it's possible that the same behavior can be observed there.

cohama commented 4 years ago

I cannot reproduce. (with Neovim v0.5.0-316 and Vim 8.2.373 with latest (head) lexima.vim) Please report neovim version (nvim --version) and lexima settings.

PanagiotisS commented 4 years ago

I have the same issue.

The python file may be as simple as having at least 49 empty lines and trying to write in the 51st.

def test():

    ()

Error message

When trying to press enter in order to expand (|) to two lines the following error message shows

Error detected while processing function lexima#insmode#_map_impl[1]..<SNR>48_map_impl[35
]..<SNR>48_input[22]..GetPythonIndent:                                                   
line   71:                                                                               
E121: Undefined variable: dummy                                                          

I think the error message is from when calling GetPythonIndent

Provide a minimal .vimrc

" Your minimal init.vim
let &runtimepath .= ',' . expand(stdpath('config') . '/bundle/repos/github.com/Shougo/dein.vim/')
if dein#load_state(expand(stdpath('config') . '/bundle'))
    call dein#begin(expand(stdpath('config') . '/bundle'))

    call dein#add('cohama/lexima.vim')

    call dein#end()
    call dein#save_state()
endif
" Your minimal .vimrc
let &runtimepath .= ',' . expand('~/.vim/bundle/repos/github.com/Shougo/dein.vim/')
if dein#load_state(expand('~/.vim/bundle'))
    call dein#begin(expand('~/.vim/bundle'))

    call dein#add('cohama/lexima.vim')

    call dein#end()
    call dein#save_state()
endif
filetype plugin indent on
syntax enable

System 1

$ lsb_release -d
Description:    Fedora release 31 (Thirty One)
$ uname -r
5.5.11-200.fc31.x86_64
:version                                                                                 
NVIM v0.4.3                                                                              
Build type: RelWithDebInfo                                                               
LuaJIT 2.1.0-beta3                                                                       
Compilation: /usr/bin/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE
=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches 
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-
cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protec
tion -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall 
-Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconvers
ion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-commo
n -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_
HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/builddir/build/BUILD/neovim-0.4.3/build/config -
I/builddir/build/BUILD/neovim-0.4.3/src -I/usr/include -I/usr/include/lua-5.1 -I/builddir
/build/BUILD/neovim-0.4.3/build/src/nvim/auto -I/builddir/build/BUILD/neovim-0.4.3/build/
include                                                                                  
Compiled by mockbuild                                                                    

Features: +acl +iconv +tui                                                               
See ":help feature-compile"                                                              

   system vimrc file: "$VIM/sysinit.vim"                                                 
  fall-back for $VIM: "/usr/share/nvim"                                                  

system 2

$ lsb_release -d                               
Description:    CentOS Linux release 7.7.1908 (Core) 
$ uname -r            
3.10.0-1062.12.1.el7.x86_64 
NVIM v0.5.0-dev                                                                                
Build type: RelWithDebInfo                                                                     
LuaJIT 2.0.4                                                                                   
Compilation: /usr/bin/cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protec
tor-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -Wp,-U_FORTIFY_
SOURCE -Wp,-D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wst
rict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-s
trong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_UNIBI_HAS_
VAR_FROM -DMIN_LOG_LEVEL=3 -I/builddir/build/BUILD/neovim-nightly/build/config -I/builddir/buil
d/BUILD/neovim-nightly/src -I/usr/include -I/builddir/build/BUILD/neovim-nightly/build/src/nvim
/auto -I/builddir/build/BUILD/neovim-nightly/build/include                                     
Compiled by mockbuild                                                                          

Features: +acl +iconv +tui                                                                     
See ":help feature-compile"                                                                    

   system vimrc file: "$VIM/sysinit.vim"                                                       
  fall-back for $VIM: "/usr/share/nvim"                                                        

Run :checkhealth for more info                                                                 

and vim version

$ vim --version                                                  
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May 11 2018 15:17:01)     
Included patches: 1-1813                                               
Modified by <bugzilla@redhat.com>                                      
Compiled by <bugzilla@redhat.com>   
Huge version without GUI.  Features included (+) or not (-):                          
+acl               +farsi             +mouse_sgr         -tag_any_white               
+arabic            +file_in_path      -mouse_sysmouse    -tcl                         
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors               
-autoservername    +float             +mouse_xterm       +terminal                    
-balloon_eval      +folding           +multi_byte        +terminfo                    
+balloon_eval_term -footer            +multi_lang        +termresponse                
-browse            +fork()            -mzscheme          +textobjects                 
++builtin_terms    +gettext           +netbeans_intg     +timers                      
+byte_offset       -hangul_input      +num64             +title                       
+channel           +iconv             +packages          -toolbar                     
+cindent           +insert_expand     +path_extra        +user_commands               
-clientserver      +job               +perl/dyn          +vertsplit                   
-clipboard         +jumplist          +persistent_undo   +virtualedit                 
+cmdline_compl     +keymap            +postscript        +visual                      
+cmdline_hist      +lambda            +printer           +visualextra                 
+cmdline_info      +langmap           +profile           +viminfo                     
+comments          +libcall           +python/dyn        +vreplace                    
+conceal           +linebreak         -python3           +wildignore                  
+cryptv            +lispindent        +quickfix          +wildmenu                    
+cscope            +listcmds          +reltime           +windows                     
+cursorbind        +localmap          +rightleft         +writebackup                 
+cursorshape       +lua/dyn           +ruby/dyn          -X11                         
+dialog_con        +menu              +scrollbind        -xfontset                    
+diff              +mksession         +signs             -xim                         
+digraphs          +modify_fname      +smartindent       -xpm                         
-dnd               +mouse             +startuptime       -xsmp                        
-ebcdic            -mouseshape        +statusline        -xterm_clipboard             
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_save                  
+eval              +mouse_gpm         +syntax                                         
+ex_extra          -mouse_jsbterm     +tag_binary                                     
+extra_search      +mouse_netterm     +tag_old_static                                 
   system vimrc file: "/etc/vimrc"                                                    
     user vimrc file: "$HOME/.vimrc"                                                  
 2nd user vimrc file: "~/.vim/vimrc"                                                  
      user exrc file: "$HOME/.exrc"                                                   
       defaults file: "$VIMRUNTIME/defaults.vim"                                      
  fall-back for $VIM: "/etc"                                                          
 f-b for $VIMRUNTIME: "/usr/share/vim/vim80"                                          
Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -fexceptions 
-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic 
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1                     
Linking: gcc -std=gnu99   -L. -Wl,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,
--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -Wl,-z,relro  -L/usr/local/lib -Wl,--as-ne
eded -o vim        -lm -lnsl  -lselinux  -lncurses -lacl -lattr -lgpm -ldl   -Wl,--enable-new-d
tags -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lreso
lv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc                                                                                   
cohama commented 4 years ago

I could reproduce it. Thank you for details. I will try to fix.

cohama commented 4 years ago

This problem is caused by original indent/python.vim. Workaround: Use https://github.com/Vimjas/vim-python-pep8-indent instead.

cohama commented 4 years ago

I have just fixed.