Sunday, October 21, 2018

Re: Cursor stays in command line after echo invoked with pumvisible() == 1

On 07/09/2018 20:58, Lifepillar wrote:
> If you run `vim --clean` (I have tried with Vim 8.1.300) and
> source this:
>
> fun! Act()
>   echo "The cursor gets stuck here ->"
>   return ''
> endf
>
> " 1. Trigger keyword completion (<c-x><c-n)
> " 2. Force waiting for the pop-up menu to appear (<c-r>==''<cr>)
> " 3. Invoke Act() with pumvisible() == 1 (<plug>(Act)
> fun! Complete()
>   return "\<c-x>\<c-n>\<c-r>=''\<cr>\<plug>(Act)"
> endf
>
> imap <silent> <expr> <plug>(Act) Act()
> imap <expr> <tab> Complete()
>
> set completeopt=menu
> set noshowmode
>
> then (in the same buffer) type something like `s<tab>`: you should see
> that the pop-up menu appears, but the cursor stays in the command line
> until you press another character.
>
> Is there a way to avoid that, i.e., to have the cursor stays in the
> buffer? Tried redraw after echo, but it does not change anything;
> redraw! leaves the cursor at the bottom-right angle of the menu instead.

Forcing a status line redraw (e.g., let &ro=&ro) fixes the issue (thanks
to Github user @cwfoo). The status line must be visible, though.
The fixed example follows.

Life.

fun! Act()
echo "The cursor won't get stuck here ->"
let &ro=&ro
return ''
endf

fun! Complete()
return "\<c-x>\<c-n>\<c-r>=''\<cr>\<plug>(Act)"
endf

imap <silent> <expr> <plug>(Act) Act()
imap <expr> <tab> Complete()

se cot=menu
set noshowmode
set laststatus=2

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: