junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.89k stars 1.9k forks source link

Vim9 .vimrc seems to completely break &cpo in plugin files #1191

Closed LunarWatcher closed 2 years ago

LunarWatcher commented 2 years ago

Obligatory note that I'm not sure who's to blame here. I have minimal understanding of the internals of plugin loading, so I have to start somewhere. If this isn't vim-plug's fault, I'll happily report this in vim/vim instead.

Explain the problem here ...

Given the following relatively minimal vimrc:

vim9script

set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set nocompatible
filetype off

echo 'CPO, vimrc' &cpo

plug#begin('~/.vim9/plugged')
Plug '~/demo/'
plug#end()

and a dummy (in my example, ~/demo/) project with a plugin file MyFile.vim:

echo &cpo
fun s:func()
    echo 'hi'
    let x = {
        \ 'x': 'y' 
    \ }
endfun

fun MyFile#vim8()
    call s:func()

    return 42
endfun

I get some extremely weird output:

❯ vim -u vim9.vimrc +qa                                                                                              
# Editor's note: this is the default value
CPO, vimrc aABceFs                                                                                                   
# Editor's note, I have no idea what this utter garbage is:
aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;

This weird behavior causes syntax errors that I initially believed to be the files parsed as Vim9, but I don't believe that's the case, considering it doesn't respond to function with an error, which it would be in vim9.

This happens somewhere when loading the plugin files themselves, and that's where my knowledge of Vim gets too flaky to tell who's to blame. It's either vim-plug or vim, and like I said, I have to start somewhere.

Also worth noting that Vim9 is the component that somehow breaks everything. This vimrc does not fail:

set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set nocompatible
filetype off

echo 'CPO, vimrc' &cpo

call plug#begin('~/.vim9/plugged')
Plug '~/demo/'
call plug#end()

Yielding:

❯ vim -u vim9.vimrc +qa                                                                                              
CPO, vimrc aABceFs                                                                                                   
aABceFs    

... which is what I expected. Worth noting that, aside converting to legacy vimscript, these two vimrcs are functionally identical on the surface.

When I initially reported this, I also tried this on my own plugin (LunarWatcher/auto-pairs) and another plugin (mhinz/vim-startify). The symptom in the wild is a potential enormous amount of syntax errors, which is why I pushed extra for some basic Vim features in the demo file. The syntax errors are overwhelmingly the consequence of cpo being a complete mess. Worth noting that the syntax errors aren't tripped, because the code is in a set of functions, neither of which are executed. CPO being completely screwed results in line continuations being disabled, which is in line with :h E10.

vim-startify in particular yielded problems in an autoload file; this autoload file is loaded via the plugin file, as a consequence of cpo cascading down into called autoload files.

While I haven't made an example for this, it's trivial to prove it isn't a surface level Vim9 issue; converting MyFile to an autoload file instead of a plugin file, and adding echo MyFile#vim8() prints the right cpoptions, and everything runs as expected. This means it is clearly an issue when the plugin files themselves are loaded; and I don't know whether vim does that itself, or if that's dealt with by vim-plug. Again, if it isn't vim-plug's fault, I'll happily move this over to Vim's repo instead


VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 17 2022 18:41:43)
Included patches: 1-55
Compiled by Olivia
Huge version with GTK2 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_interact
+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: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/arm-linux-gnueabihf/gtk-2.0/include -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lrt -ldl -L/usr/lib/arm-linux-gnueabihf -lluajit-5.1 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf/perl/5.28/CORE -lperl -ldl -lm -lpthread -lcrypt -L/opt/upm-active/lib/python3.10/config-3.10-arm-linux-gnueabihf -lpython3.10 -lcrypt -lpthread -ldl -lutil -lm -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm -L/usr/lib
LunarWatcher commented 2 years ago

According to :h new-plugins, this is Vim's fault. Moving this issue there