kassio / neoterm

Wrapper of some vim/neovim's :terminal functions.
Other
1.31k stars 117 forks source link

Topen resets unset env variable #227

Closed petobens closed 5 years ago

petobens commented 5 years ago

Consider the following minimal vimrc:

set nocompatible

let $DOTVIM = expand('$HOME/.config/nvim')

set runtimepath+=$DOTVIM/bundle/repos/github.com/kassio/neoterm
filetype plugin indent on

au WinEnter,BufWinEnter *.py let $FOO = 'foo'

Now do the following: i) Open nvim on any empty python file bar.py and run :echo $FOO. This returns foo ii) Run :unlet $FOO and run :echo $FOO. Now this returns and empty string (i.e the variable is unset) iii) Run botright Topen and run :echo $FOO. Now this return foo.

In the last step I expect :echo $FOO to return an empty string and not to repopulate the environment variable. I guess that somewhere in neoterm#open() you are returning to the python file which therefore triggers the autocommand that reset the env variable.

Thanks in advance for looking into this. Let me know if you can reproduce it.

kassio commented 5 years ago

Topen creates a new buffer in a new window, since you have the autocmd on this event, your global variable will be re-created.

You could use :noautocmd Topen to open the new neoterm without re-creating your global variable.

:h BufWinEnter for reference:

After a buffer is displayed in a window. This can be when the buffer is loaded (after processing the modelines) or when a hidden buffer is displayed in a window (and is no longer hidden). Does not happen for |:split| without arguments, since you keep editing the same buffer, or ":split" with a file that's already open in a window, because it re-uses an existing buffer. But it does happen for a ":split" with the name of the current buffer, since it reloads that buffer.

petobens commented 5 years ago

Makes sense. Thanks for the explanation.