[vim/vim] cannot open popup terminal before VimEnter (#7742)

83 views
Skip to first unread message

lacygoill

unread,
Jan 25, 2021, 2:24:12 AM1/25/21
to vim/vim, Subscribed

Describe the bug

We cannot open a popup terminal until after VimEnter has been fired.

To Reproduce

Run this shell command:

vim -Nu NORC -c 'call term_start(&shell, #{hidden: 1})->popup_create({})'

E994 is raised:

E994: Not allowed in a popup window

Expected behavior

No error is raised.

Environment

  • Vim version: 8.2 Included patches: 1-2406
  • OS: Ubuntu 16.04.7 LTS
  • Terminal: xterm(363)

Additional context

The issue comes from these lines in the netrw plugin:

https://github.com/vim/vim/blob/c05fe07529f10fc32a2086cb44a708520c8d14ce/runtime/plugin/netrwPlugin.vim#L156-L157

:windo and :wincmd try to temporarily change the currently focused window, which is disallowed while a popup terminal is active.

In practice, it causes this kind of issues: junegunn/fzf.vim#1231.


This patch should fix the issue:

diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim
index 217a7795c..6083af0ce 100644
--- a/runtime/plugin/netrwPlugin.vim
+++ b/runtime/plugin/netrwPlugin.vim
@@ -151,10 +151,8 @@ endfun
 "             has already been called.
 fun! s:VimEnter(dirname)
 "  call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">")
-  let curwin       = winnr()
   let s:vimentered = 1
-  windo call s:LocalBrowse(expand("%:p"))
-  exe curwin."wincmd w"
+  call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')})
 "  call Dret("s:VimEnter")
 endfun
 

It uses win_execute() which has fewer side-effects.

cc @cecamp


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
Jan 25, 2021, 2:33:16 AM1/25/21
to vim/vim, Subscribed

We cannot open a popup terminal until after VimEnter has been fired.

Actually, we can, but it still raises E994.

Max Schillinger

unread,
Apr 22, 2021, 5:59:09 PM4/22/21
to vim/vim, Subscribed

Can anybody validate @lacygoill's patch?

Michael Orr

unread,
Apr 29, 2021, 8:51:18 AM4/29/21
to vim/vim, Subscribed

I was able to apply the patch from @lacygoill and it does indeed resolve the "cannot open a popup prior to VimEnter" issue.

With the patch, I am able to run:
vim -c "Ag foo" directly which results in a popup window opening correctly as expected, whereas without the patch this will throw an exception:

Error detected while processing VimEnter Autocommands for "*"..function <SNR>50_VimEnter:
line    4:
E994: Not allowed in a popup window
Press ENTER or type command to continue

and I have to resort to hacks like:
vim -c "autocmd VimEnter * call timer_start(0, {->execute('Ag foo')})" to get it to work.

Max Schillinger

unread,
May 1, 2021, 7:30:37 AM5/1/21
to vim/vim, Subscribed

@michaelorr : Thanks for testing!

Meanwhile I have built vim from source with this patch applied and I can confirm that it works as expected (tested with vim -c "RgRaw netrw").

@lacygoill : Would you mind creating a pull request with your patch?

K.Takata

unread,
May 1, 2021, 7:43:51 AM5/1/21
to vim/vim, Subscribed

I assigned to @cecamp.

lacygoill

unread,
Aug 30, 2021, 1:12:09 PM8/30/21
to vim/vim, Subscribed

Fixed in the last update of the runtime files: 89a9c15


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications on the go with GitHub Mobile for iOS or Android.

lacygoill

unread,
Aug 30, 2021, 1:12:14 PM8/30/21
to vim/vim, Subscribed

Closed #7742.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Reply all
Reply to author
Forward
0 new messages