rstacruz / vim-closer

Closes brackets
MIT License
343 stars 34 forks source link

Hangs with mapping inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' #37

Closed astier closed 2 years ago

astier commented 3 years ago

System

Reproducible with all the following vim-version:

Problem

vim-closer hangs when trying to close a bracket if an insert-mapping exists which executes <expr> dependent on pumvisible().

VIMRC

call plug#begin()
    Plug 'rstacruz/vim-closer'
call plug#end()
filetype plugin on
inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' 

Reproduce

  1. Create a new file with a filetype which is supported bug vim-closer: vim bug.sh
  2. Enter insert-mode, type { and press <cr>: i{<cr>
  3. Vim should hang now. Abort operation by pressing <c-c>

It should be visible that vim-closer created a long line which looks like this:

{pumvisible() ? '' : 'pumvisible() ? '' : 'pumvisible() ? '' :

It essentially pastes {pumvisible() ? '' : over and over.

Related

22

25

w1zd commented 3 years ago

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

pastes {pumvisible() ? '' : over and over again.

vim-hyperstyle has the same issue.

gegnew commented 3 years ago

same issue, temporarily switching to coc-pairs, although I'd love to have closer work

IllustratedMan-code commented 2 years ago

Can confirm that I also have this issue, using COQ.nvim

geofffranks commented 2 years ago

+1 here

rstacruz commented 2 years ago

Thanks for the replies everyone. I have no idea how to fix this and could use some help.

On Wed, 12 Jan 2022, 4:28 am Geoff Franks, @.***> wrote:

+1 here

— Reply to this email directly, view it on GitHub https://github.com/rstacruz/vim-closer/issues/37#issuecomment-1010193983, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASFEME64ADJUC5S7NT2K3UVRSCVANCNFSM454PJMVA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

laomaiweng commented 2 years ago

I'm not sure that's best fixed on your end rather than on the completers' (non-expr mapping) or Neovim's end (ability to "chain" mappings?), but perhaps at least put a warning in the README? This bug affects multiple auto-completers, isn't trivial to isolate, and is quite disruptive (complete neovim hang), so I figure people would be glad to know before getting bitten.

It took me days to find out this was the root cause for my hangs, I'd sure have appreciated a heads up. 😅

rstacruz commented 2 years ago

I added a note to the README now. Thanks all, would appreciate some ideas on how to fix this.

Someone has posted a workaround in #22.

tpope commented 2 years ago

I recently solved this for Endwise and Eunuch. My recommended approach would be to give closer#close() an optional ... argument and add something like this to the top: https://github.com/tpope/vim-eunuch/blob/74e0e1662cc9ed3d58ba3e3de20eb30ac4039956/plugin/eunuch.vim#L438-L440

Then when defining the <CR> map, you can chain to an existing <expr> map by passing the original definition as an argument: https://github.com/tpope/vim-eunuch/blob/74e0e1662cc9ed3d58ba3e3de20eb30ac4039956/plugin/eunuch.vim#L468-L485

P.S. Endwise and Eunuch now default to this approach, which means vim-closer now suffers from this issue if either is installed.

rstacruz commented 2 years ago

A fix was just merged, give it a go!

mjs commented 2 years ago

Seems to work. Thanks for fixing!