macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.5k stars 681 forks source link

Syntax highlight is lost after sleep #1068

Open masukomi opened 4 years ago

masukomi commented 4 years ago

Describe the bug

I believe this only happens with the currently visible tab, in whatever split has the cursor. If no split then the tab's current buffer.

To Reproduce Put the computer to sleep. Wake the computer. Text is now all white. set filetype=ruby (or whatever) fixes it. Happens almost every time.

I have suspicions that this may be related to macOS moving the windows around as the external monitors are recognized.

Expected behavior Syntax highlighting should never be lost as a result of a sleep/wake cycle or as a result of the OS moving the window.

Environment (please complete the following information):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 17 2020 17:49:10)
macOS version
Included patches: 1-503, 505-680, 682-2292
Compiled by root@apple.com
Normal version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
-arabic            +file_in_path      -mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       -termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
-balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            -gettext           +num64             +textprop
+builtin_terms     -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        -vartabs
+clipboard         -keymap            +printer           +vertsplit
+cmdline_compl     +lambda            -profile           +virtualedit
+cmdline_hist      -langmap           +python/dyn        +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
-conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          -rightleft         +wildignore
+cscope            +localmap          +ruby/dyn          +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      -sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            -mouse_dec         +statusline        -xsmp
-emacs_tags        -mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          -mouse_netterm     +tag_binary
+extra_search      +mouse_sgr         -tag_old_static
   system vimrc file: "$VIM/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: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa
eirnym commented 4 years ago

Thank you for an issue @masukomi

Long while ago I had a problem with requirement to redraw text, but these times long gone as CoreText renderer is quite stable. I even still have following lines from these times:

" autocmd FocusLost * redraw!
" autocmd VimResized * redraw!

Could you please tell which MacVim's defaults do you have by providing an output of defaults read org.vim.MacVim | grep 'MM\|SU'. These settings of MacVim GUI and they're not stay in vimrc file.

Also please try to test by running mvim --clean to make sure none of your plugins interfere with syntax highlighting in some weird way.

masukomi commented 4 years ago

haven't forgotten.... just haven't gotten around to testing yet. will do so.

masukomi commented 4 years ago

I'm happy & sad to report that it's likely one of the plugins. after running mvim --clean with a typical (for me) set of tabs and splits I tried lots of sleeps and unplugging monitors and replugging monitors during sleep, during wake, etc... couldn't make it loose syntax highlight. Sorry i didn't think to try that before it seemed like a thing that "must" be from MacVim itself but... duh, obviously it could be a plugin.

Happy because Yay MacVim doesn't have this bug. Sad because OMG that's going to be a PITA to figure out which one.

I'll update this ticket with the plugin once I figure out which one it was but I'm thinking probably best to close this one now.

Thanks for the help.

Here are the defaults you asked for in case that's still useful.

$ defaults read org.vim.MacVim | grep 'MM\|SU'
    MMAutosaveColumns = 78;
    MMAutosaveRows = 44;
    MMCurrentPreferencePane = Advanced;
    MMTopLeftPoint = "{966, 1057}";
    "NSWindow Frame SUStatusFrame" = "960 928 400 129 0 0 1920 1057 ";
    "NSWindow Frame SUUpdateAlert" = "2570 516 620 392 -1680 30 1680 1050 ";
    SUEnableAutomaticChecks = 1;
    SUHasLaunchedBefore = 1;
    SULastCheckTime = "2020-08-14 13:21:42 +0000";
    SUSendProfileInfo = 0;
    SUUpdateGroupIdentifier = 246492181;
    SUUpdateRelaunchingMarker = 0;
ychin commented 4 years ago

I think this is related to #634. Basically, Vim has an option (:help redrawtime) that puts an upper-cap on how much time syntax files can run before it just stops it and don't display syntax highlighting. This could happen if you have a large file, for example (see that linked issue).

Do you know if this is specific to MacVim or just Vim? For example, if you open the same file in terminal Vim (no GUI) does the problem still exist? It could just be a plugin interacting poorly with your file. If that's the issue, you can probably disable the plugin, set redrawtime to be higher, or get a faster Mac. :)