[vim/vim] `popup` in `completeopt` leaves behind a scratch buffer that can't be killed (#7443)

22 views
Skip to first unread message

Boris Staletic

unread,
Dec 8, 2020, 7:43:52 PM12/8/20
to vim/vim, Subscribed

Instructions: Replace the template text and remove irrelevant text (including this line)

Describe the bug

With set completeopt+=preview, a scratch buffer is used that can be "killed" with a :pclose.

If a user is using set completeopt+=popup, a scratch buffer is used, but without an associated preview window. This renders :pclose useless, but :bwipeout! is also ineffective. This mean that :bnext and :bprevious will take the user to the "hidden" scratch buffer. The same scratch buffer is present in the output of :ls.

To Reproduce
Use the following vimrc:

function! Omni(findstart, base)
        if a:findstart
                return 0
        endif
        return [ {'word':'foo', 'info': 'bar'} ]
endfunction
set omnifunc=Omni
set completeopt=popup,menuone
  1. Save the above file as bug_vimrc.vim
  2. Start vim with vim -Nu bug_vimrc.vim --noplugins
  3. i<C-x><C-o> - go to insert mode and trigger omnicompletion.
  4. <Esc>:ls<CR> - exit insert mode and check the buffer list. Note that The second listed buffer is the [Scratch] buffer.
  5. :pclose<CR> - attempt to close the preview. Note that the scratch buffer doesn't have an associated preview window.
  6. :ls<CR> - check the buffer list again. Note that the scratch buffer is still there.

Expected behavior

Users and/or plugin maintainers should have a way to get rid of the scratch buffer. I'd even argue that the scratch buffer should be thrown away when the completion popup gets closed.

Screenshots

I'm not sure which screenshot would be helpful, if any. I'll gladly provide any requested.

Environment (please complete the following information):

  • Vim version:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Nov 15 2020 19:21:07)
Included patches: 1-1989
Compiled by Arch Linux
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +cmdline_info      -farsi             +langmap           +mouse_sgr         +profile           +tag_binary        +virtualedit
+arabic            +comments          +file_in_path      +libcall           -mouse_sysmouse    +python/dyn        -tag_old_static    +visual
+autocmd           +conceal           +find_in_path      +linebreak         +mouse_urxvt       +python3/dyn       -tag_any_white     +visualextra
+autochdir         +cryptv            +float             +lispindent        +mouse_xterm       +quickfix          +tcl/dyn           +viminfo
-autoservername    +cscope            +folding           +listcmds          +multi_byte        +reltime           +termguicolors     +vreplace
+balloon_eval      +cursorbind        -footer            +localmap          +multi_lang        +rightleft         +terminal          +wildignore
+balloon_eval_term +cursorshape       +fork()            +lua/dyn           -mzscheme          +ruby/dyn          +terminfo          +wildmenu
+browse            +dialog_con_gui    +gettext           +menu              +netbeans_intg     +scrollbind        +termresponse      +windows
++builtin_terms    +diff              -hangul_input      +mksession         +num64             +signs             +textobjects       +writebackup
+byte_offset       +digraphs          +iconv             +modify_fname      +packages          +smartindent       +textprop          +X11
+channel           +dnd               +insert_expand     +mouse             +path_extra        +sound             +timers            -xfontset
+cindent           -ebcdic            +ipv6              +mouseshape        +perl/dyn          +spell             +title             +xim
+clientserver      +emacs_tags        +job               +mouse_dec         +persistent_undo   +startuptime       +toolbar           -xpm
+clipboard         +eval              +jumplist          +mouse_gpm         +popupwin          +statusline        +user_commands     +xsmp_interact
+cmdline_compl     +ex_extra          +keymap            -mouse_jsbterm     +postscript        -sun_workshop      +vartabs           +xterm_clipboard
+cmdline_hist      +extra_search      +lambda            +mouse_netterm     +printer           +syntax            +vertsplit         -xterm_save
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/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/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/at-spi-2.0 -pthread    -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -D_REENTRANT  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.32/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0  -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf   -lcanberra  -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.32/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.32/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm
  • OS:Arch Linux x64
  • Terminal: st

Note that another user reproduced this bug on a completely different machine.

Additional context


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

Anton Romanov

unread,
Dec 8, 2020, 7:44:47 PM12/8/20
to vim/vim, Subscribed

Can confirm on 8.2.2041

Bram Moolenaar

unread,
Dec 9, 2020, 11:53:42 AM12/9/20
to vim/vim, Subscribed


Boris Staletic wrote:

> **Describe the bug**
>
> With `set completeopt+=preview`, a scratch buffer is used that can be "killed" with a `:pclose`.
>
> If a user is using `set completeopt+=popup`, a scratch buffer is used, but without an associated preview window. This renders `:pclose` useless, but `:bwipeout!` is also ineffective. This mean that `:bnext` and `:bprevious` will take the user to the "hidden" scratch buffer. The same scratch buffer is present in the output of `:ls`.
>
> **To Reproduce**
> Use the following vimrc:
>
> ```viml

> function! Omni(findstart, base)
> if a:findstart
> return 0
> endif
> return [ {'word':'foo', 'info': 'bar'} ]
> endfunction
> set omnifunc=Omni
> set completeopt=popup,menuone
> ```
> 1. Save the above file as `bug_vimrc.vim`
> 2. Start vim with `vim -Nu bug_vimrc.vim --noplugins`
> 3. `i<C-x><C-o>` - go to insert mode and trigger omnicompletion.
> 4. `<Esc>:ls<CR>` - exit insert mode and check the buffer list. Note that The second listed buffer is the `[Scratch]` buffer.
> 5. `:pclose<CR>` - attempt to close the preview. Note that the scratch buffer doesn't have an associated preview window.
> 6. `:ls<CR>` - check the buffer list again. Note that the scratch buffer is still there.
>
> **Expected behavior**

>
> Users and/or plugin maintainers should have a way to get rid of the scratch buffer. I'd even argue that the scratch buffer should be thrown away when the completion popup gets closed.
>
> **Screenshots**

>
> I'm not sure which screenshot would be helpful, if any. I'll gladly provide any requested.

The first problem is that this scratch buffer is list. It should have
'buflisted' set to false.

The buffer is kept around because the popup is kept around. This allows
for reusing a few things while completion is going through different
alternatives. We can most likely delete the popup when leaving Insert
mode.

As a workaround: setting 'completeopt' deletes the popup and the buffer.

--
No man may purchase alcohol without written consent from his wife.
[real standing law in Pennsylvania, United States of America]

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Dec 9, 2020, 12:06:06 PM12/9/20
to vim...@googlegroups.com, Bram Moolenaar

I wrote:

> The first problem is that this scratch buffer is list. It should have
> 'buflisted' set to false.
>
> The buffer is kept around because the popup is kept around. This allows
> for reusing a few things while completion is going through different
> alternatives. We can most likely delete the popup when leaving Insert
> mode.

That actually goes against what is documented: use popup_findinfo() to
change its properties. It also mentions using popup_close() to get rid
of it, thus I don't think we should make a change here.


--
It is illegal to take more than three sips of beer at a time while standing.
[real standing law in Texas, United States of America]

Gabriel Dupras

unread,
Dec 14, 2020, 12:14:13 PM12/14/20
to vim/vim, Subscribed

I can reproduce the bug in 8.2.2041 but not in 8.2.2143. With the latter, there is no scratch buffer when doing :ls but it does appear as unlisted when doing :ls!.

bfrg

unread,
Dec 14, 2020, 12:16:33 PM12/14/20
to vim/vim, Subscribed

I think this was fixed in d356fc6.

Boris Staletic

unread,
Dec 14, 2020, 12:37:32 PM12/14/20
to vim/vim, Subscribed

With the latter, there is no scratch buffer when doing :ls but it does appear as unlisted when doing :ls!.

That's good enough for me. As far as I'm concerned, this issue can be closed.

Bram Moolenaar

unread,
Dec 14, 2020, 1:49:27 PM12/14/20
to vim/vim, Subscribed

Closed #7443.

Reply all
Reply to author
Forward
0 new messages