timers not working for MacVim run in GUI mode
I reported Shougo/neocomplete.vim#563, in which @Shougo tracked the issue down to the timers feature not working in MacVim as a GUI application. The odd thing is that timers works fine when running MacVim within my terminal (iTerm2) via mvim -v. This issue also relates to maralla/completor.vim#35.
In Shougo/neocomplete.vim#560, @Shougo mentions he is not able to reproduce this issue in GVim, so this is specific to MacVim.
Environment
OS X 10.11 El Capitan
$ brew info macvim
macvim: stable 8.0-114 (bottled), HEAD
GUI for vim, made for macOS
https://github.com/macvim-dev/macvim
/usr/local/Cellar/macvim/8.0-113 (2,102 files, 33.5M)
Built from source on 2016-10-27 at 12:33:22 with: --with-python3 --without-python --with-lua --with-luajit
/usr/local/Cellar/macvim/8.0-114 (2,107 files, 33.6M) *
Built from source on 2016-11-07 at 09:20:23 with: --with-python3 --without-python --with-lua --with-luajit
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/macvim.rb
==> Dependencies
Recommended: cscope
Optional: lua, luajit
==> Requirements
Build: xcode
Recommended: python
Optional: python3
==> Options
--with-custom-python
Build with a custom Python 2 instead of the Homebrew version.
--with-lua
Build with lua support
--with-luajit
Build with luajit support
--with-override-system-vim
Override system vim
--with-python3
Build with python3 support
--without-cscope
Build without cscope support
--without-python
Build without python support
--HEAD
Install HEAD version
==> Caveats
.app bundles were installed.
Run `brew linkapps macvim` to symlink these to /Applications.
$ mvim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 7 2016 09:20:12)
MacOS X (unix) version
Included patches: 1-52
Compiled by Homebrew
Huge version with MacVim GUI. Features included (+) or not (-):
+acl +find_in_path -mouse_sysmouse -tag_any_white
+arabic +float +mouse_urxvt +tcl
+autocmd +folding +mouse_xterm +termguicolors
+balloon_eval -footer +multi_byte +terminfo
+browse +fork() +multi_lang +termresponse
++builtin_terms +fullscreen -mzscheme +textobjects
+byte_offset -gettext +netbeans_intg +timers
+channel -hangul_input +num64 +title
+cindent +iconv +odbeditor +toolbar
+clientserver +insert_expand +packages +transparency
+clipboard +job +path_extra +user_commands
+cmdline_compl +jumplist +perl +vertsplit
+cmdline_hist +keymap +persistent_undo +virtualedit
+cmdline_info +lambda +postscript +visual
+comments +langmap +printer +visualextra
+conceal +libcall +profile +viminfo
+cryptv +linebreak -python +vreplace
+cscope +lispindent +python3 +wildignore
+cursorbind +listcmds +quickfix +wildmenu
+cursorshape +localmap +reltime +windows
+dialog_con_gui +lua +rightleft +writebackup
+diff +menu +ruby -X11
+digraphs +mksession +scrollbind -xfontset
+dnd +modify_fname +signs +xim
-ebcdic +mouse +smartindent -xpm
+emacs_tags +mouseshape +startuptime -xsmp
+eval +mouse_dec +statusline -xterm_clipboard
+ex_extra -mouse_gpm -sun_workshop -xterm_save
+extra_search -mouse_jsbterm +syntax
+farsi +mouse_netterm +tag_binary
+file_in_path +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"
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: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -L/usr/local/lib -L. -L/usr/local/lib -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon -lm -lncurses -liconv -framework Cocoa -pagezero_size 10000 -image_base 100000000 -L/usr/local/opt/luajit/lib -lluajit-5.1 -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -L/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/config-3.5m -lpython3.5m -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -framework Ruby
can you write a short Vim script to repro the issue?
At least, timer unittests including testdir/test_timers.vim works with GUI. GUI_FLAG=-fg make test.
@splhack I'm sorry. Unfortunately, I'm only a high-level user of Vim, and not knowledgable enough to create a small test. I only know the effects of this on neocomplete.
Maybe @Shougo or @maralla would have an idea on how to demonstrate this issue in a small script.
It seems the timer_stop function blocked by something, becauee when you move the mouse cursor or type any candidate characters, than the popup menu just showed like I demo in those screencasts.
@markwu is there any chance to check and modify test_timers.vim to repro the issue? timer_stop seems ok for me, at least in the test.
I really hope I can help. But, I am not familiar with timer and completion in vimscript, I just know how to reproduce problem with these plugins.
I think test_timers.vim does not test timer feature in insertmode.
It seems timers work well as excepted, but there is something when input >. Maybe related highlighting bracket in Insert mode.
I try to disable matchit.vim at start by add this line to my vimrc
let loaded_matchparen = 1
Nothing changed.
This problem is due to feedkeys() in timer callback.
nnoremap <F5> :<C-U>call TimerStart()<CR>
fu! TimerStart()
call timer_start(50, 'Feedkeys')
endfu
fu! Feedkeys(...)
call feedkeys('iabc')
endfu
Keying <F5>, on TUI shows "abc" promptly, but on GUI MacVim doesn't show it until other any input (keyboard or mouse cursor moved) given.
The reason is, GUI has not check input buffer typebuf after timer callback.
https://github.com/vim/vim/blob/ca8b8d6/src/gui.c#L2869
when invoked timer callback in check_due_timer(), due_time is set to -1.
https://github.com/vim/vim/blob/ca8b8d6/src/gui.c#L2877
so gui_mch_wait_for_chars() waits for input forever.
Thus, when feedkeys() is called in callback, the input of feedkeys() must be handled in gui_mch_wait_for_chars() but MacVim does not so and simply waits for input.
Other GUI Vim, gui_win32;
https://github.com/vim/vim/blob/ca8b8d6/src/gui_w32.c#L2100
gui_gtk_x11;
https://github.com/vim/vim/blob/ca8b8d6/src/gui_gtk_x11.c#L6648
both of these have checked input_available(), which returns TRUE if feedkeys() gave input, in gui_mch_wait_for_chars ().
@ichizok Thanks for chasing that down!
@splhack Can we please re-open this issue, since the initial fix was reverted?
I just wondering why revert the fix? Anything wrong?
via Newton Mail [https://cloudmagic.com/k/d/mailapp?ct=pi&cv=9.2.5&pv=10.1.1&source=email_footer_2] loooop