ZhiyuanLck / smart-pairs

Ultimate smart pairs written in lua!
MIT License
136 stars 2 forks source link

smart-pairs is incompatible with extmarks #20

Open rhcher opened 2 years ago

rhcher commented 2 years ago

Explain the issue

smart-pairs can't work with nvim-snippy plugin, it will break snippy behavior. I'm not sure if this is a bug in the smart-pairs.

Steps to reproduce

  1. run nvim -u vimrc.vim test.c

  2. We can input like this image

  3. Then we press tab key, and the snippt will be expanded. image

  4. Then we press tab key and the cursor jump to next place and then we input ". image

  1. When I use smart-pairs and nvim-snippy together, there are many strange behavior that is not in line with my expectations.

Minimal working example

test.c

#include <stdio.h>
int main(int argc, char *argv[])
{
  for
  return 0;
}

Minimal vimrc file

vimrc.vim

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'dcampos/nvim-snippy'
Plug 'honza/vim-snippets'
Plug 'ZhiyuanLck/smart-pairs'
call plug#end()
PlugInstall | quit

imap <expr> <Tab> snippy#can_expand_or_advance() ? '<Plug>(snippy-expand-or-advance)' : '<Tab>'
imap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
smap <expr> <Tab> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<Tab>'
smap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
xmap <Tab> <Plug>(snippy-cut-text)

lua << EOF
    require('snippy').setup({
        hl_group = 'Search',
    })
    require('pairs'):setup()
EOF

Additonal information

nvim version: NVIM v0.7.0-dev+1125-g726ec7fb1 I can provide any other information if needed

ZhiyuanLck commented 2 years ago

I need some time to locate the problem. But the plugin works well with ultisnip.

ZhiyuanLck commented 2 years ago

I think the possible reason is nvim-snippy use the extmarks feature that relies on the keyboard input to maintain the correct position of the extmarks. However, smart-pairs does not like most paring plugins that feed the pair keys with feedkeys, it directly resets the line with nvim_set_current_line. So it is pitiful that smart-pairs cannot work with nvim-snippy now.

There may be two ways to totally fix it:

  1. Change the input way of the pair, which is not considered for now
  2. Wait for some api such as nvim_buf_get_current_extmarks, so that it is possible to update all extmarks at current position
ZhiyuanLck commented 2 years ago

I need to reproduce the issue to check if it does be caused by the extmarks.

ZhiyuanLck commented 2 years ago

Well, it is sure that nvim_set_current_line will push all extmarks to the next line. So smart-pairs is incompatible with extmarks now.

I will work on it to update the extmarks of the current line later.

ZhiyuanLck commented 2 years ago

@rhcher now it should work in most cases

rhcher commented 2 years ago

Yes, it now works really perfect for me, I will close this. If someone still find there are some problem with extmarks, I can reopen this. This plugin works very silky smooth (thanks to nvim_set_current_line), many thanks for your great work on this plugin!

ZhiyuanLck commented 2 years ago

The only issue is that when you delete an empty line, the marks will still be broken, I'll fix it later.