mrjones2014 / smart-splits.nvim

🧠 Smart, seamless, directional navigation and resizing of Neovim + terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. Think about splits in terms of "up/down/left/right".
MIT License
977 stars 43 forks source link

Resize commands are triggering BufEnter event #28

Closed alanoliveira closed 2 years ago

alanoliveira commented 2 years ago

Issue

I notice if we have some buffer with a BufEnter autocommand, like

au BufEnter term://* startinsert

When we use any resize command the BufEnter is triggered.

As far as I could investigate it seems to be caused by wincmd h|j|k|l| on lua/smart-splits/api.lua.
I tried to solve it preppending a noautocmd on the beginning of wincmd, but for somereason it not works on this line lua/smart-splits/api.lua#L53 (a neovim bug maybe).

To reproduce

" mini.init.vim
noautocmd e aaa
noautocmd vs bbb

call plug#begin()
  Plug 'mrjones2014/smart-splits.nvim'
call plug#end()

map <space> :lua require('smart-splits').resize_left()<CR>

lua << EOF
require('smart-splits').setup({})
EOF
$ nvim -u mini.init.vim

When space is pressed in normal mode a message with aaa and bbb is displayed.

Additional info

" PlugSnapshot
silent! let g:plugs['smart-splits.nvim'].commit = 'c8d80d90f3c783ac0ea21f256c74d541a7b66a72'

" nvim --version
NVIM v0.8.0-1210-gd367ed9b2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/cmake.config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az457-787
alanoliveira commented 2 years ago

About the neovim I found out how to reproduce, so I created an issue on neovim repo https://github.com/neovim/neovim/issues/20450 .

Once it is fixed, do you think add a noautocmd on all vim.cmd calls could cause some undesired side effect?

mrjones2014 commented 2 years ago

Instead, I think a better approach is to just set eventignore before starting any smart-splits stuff, then reset it on complete. I can make the ignored events list customizable.

mrjones2014 commented 2 years ago

@alanoliveira does a246c4f7b386c435a286b18bcdd0fd4dfb929ab5 fix it for you?

alanoliveira commented 2 years ago

Thank you very much, that was fast!

Could you make it run only for resize events?
Its because when I move to a terminal buffer I want it to run a startinsert, but when I'm just resizing I don't want it.

mrjones2014 commented 2 years ago

Yup, that makes sense, my mistake. Done.

alanoliveira commented 2 years ago

Like a charm! thank you! :bow: