# HG changeset patch # User Bram Moolenaar # Date 1617449415 -7200 # Node ID f8619a303e9dd058c46d2e7ac83d68eb36b56f1c # Parent 7b87429e4b2a7e87e875b9b046ac697f9a362edf patch 8.2.2695: cursor position reset with nested autocommands Commit: https://github.com/vim/vim/commit/1e6bbfb5607c82d872070219c26e2aae20db68ed Author: Bram Moolenaar Date: Sat Apr 3 13:19:26 2021 +0200 patch 8.2.2695: cursor position reset with nested autocommands Problem: Cursor position reset with nested autocommands. Solution: Only check and reset line numbers for not nested autocommands. (closes #5820) diff --git a/src/autocmd.c b/src/autocmd.c --- a/src/autocmd.c +++ b/src/autocmd.c @@ -2116,14 +2116,16 @@ apply_autocmds_group( ap->last = FALSE; ap->last = TRUE; - // make sure cursor and topline are valid - check_lnums(TRUE); + if (nesting == 1) + // make sure cursor and topline are valid + check_lnums(TRUE); do_cmdline(NULL, getnextac, (void *)&patcmd, DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); - // restore cursor and topline, unless they were changed - reset_lnums(); + if (nesting == 1) + // restore cursor and topline, unless they were changed + reset_lnums(); #ifdef FEAT_EVAL if (eap != NULL) diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -2002,5 +2002,32 @@ func Test_terminal_all_ansi_colors() call delete('Xcolorscript') endfunc +function On_BufFilePost() + doautocmd User UserEvent +endfunction + +func Test_terminal_nested_autocmd() + new + call setline(1, range(500)) + $ + let lastline = line('.') + + augroup TermTest + autocmd BufFilePost * call On_BufFilePost() + autocmd User UserEvent silent + augroup END + + let cmd = Get_cat_123_cmd() + let buf = term_start(cmd, #{term_finish: 'close', hidden: 1}) + call assert_equal(lastline, line('.')) + + call TermWait(buf) + exe buf . 'bwipe' + call delete('Xtext') + augroup TermTest + au! + augroup END +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2695, +/**/ 2694, /**/ 2693,