aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-26 11:53:17 +0800
committerGitHub <noreply@github.com>2022-07-26 11:53:17 +0800
commit1a07044c1c828edda3e24828782665947fe68049 (patch)
tree947a6b695743b5979567c870c7a7cd0736542b51
parent147cce29a6b5d475729a4d3d5acf23172ead1f3f (diff)
downloadrneovim-1a07044c1c828edda3e24828782665947fe68049.tar.gz
rneovim-1a07044c1c828edda3e24828782665947fe68049.tar.bz2
rneovim-1a07044c1c828edda3e24828782665947fe68049.zip
revert: "vim-patch:9.0.0061: ml_get error with nested autocommand" (#19509)
This reverts commit 6cee15da7235b6ba9c428ee43346415fe6a64e6c. Port this again when https://github.com/vim/vim/issues/10780 is fixed.
-rw-r--r--src/nvim/autocmd.c6
-rw-r--r--src/nvim/testdir/test_autocmd.vim19
-rw-r--r--src/nvim/window.c32
3 files changed, 10 insertions, 47 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 2b4c9c5b9c..73c2cda92b 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -1837,13 +1837,9 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
}
ap->last = true;
- // Make sure cursor and topline are valid. The first time the current
- // values are saved, restored by reset_lnums(). When nested only the
- // values are corrected when needed.
if (nesting == 1) {
+ // make sure cursor and topline are valid
check_lnums(true);
- } else {
- check_lnums_nested(true);
}
// Execute the autocmd. The `getnextac` callback handles iteration.
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index ed439ff6ec..438851a0ad 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -2170,25 +2170,6 @@ func Test_autocmd_nested()
call assert_fails('au WinNew * nested nested echo bad', 'E983:')
endfunc
-func Test_autocmd_nested_cursor_invalid()
- set laststatus=0
- copen
- cclose
- call setline(1, ['foo', 'bar', 'baz'])
- 3
- augroup nested_inv
- autocmd User foo ++nested copen
- autocmd BufAdd * let &laststatus = 2 - &laststatus
- augroup END
- doautocmd User foo
-
- augroup nested_inv
- au!
- augroup END
- set laststatus&
- bwipe!
-endfunc
-
func Test_autocmd_once()
" Without ++once WinNew triggers twice
let g:did_split = 0
diff --git a/src/nvim/window.c b/src/nvim/window.c
index f00d98ca60..97ca45662e 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -6858,16 +6858,17 @@ bool only_one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
return count <= 1;
}
-/// Implementation of check_lnums() and check_lnums_nested().
-static void check_lnums_both(bool do_curwin, bool nested)
+/// Correct the cursor line number in other windows. Used after changing the
+/// current buffer, and before applying autocommands.
+///
+/// @param do_curwin when true, also check current window.
+void check_lnums(bool do_curwin)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
- if (!nested) {
- // save the original cursor position and topline
- wp->w_save_cursor.w_cursor_save = wp->w_cursor;
- wp->w_save_cursor.w_topline_save = wp->w_topline;
- }
+ // save the original cursor position and topline
+ wp->w_save_cursor.w_cursor_save = wp->w_cursor;
+ wp->w_save_cursor.w_topline_save = wp->w_topline;
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
@@ -6876,28 +6877,13 @@ static void check_lnums_both(bool do_curwin, bool nested)
wp->w_topline = curbuf->b_ml.ml_line_count;
}
- // save the (corrected) cursor position and topline
+ // save the corrected cursor position and topline
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
wp->w_save_cursor.w_topline_corr = wp->w_topline;
}
}
}
-/// Correct the cursor line number in other windows. Used after changing the
-/// current buffer, and before applying autocommands.
-///
-/// @param do_curwin when true, also check current window.
-void check_lnums(bool do_curwin)
-{
- check_lnums_both(do_curwin, false);
-}
-
-/// Like check_lnums() but for when check_lnums() was already called.
-void check_lnums_nested(bool do_curwin)
-{
- check_lnums_both(do_curwin, true);
-}
-
/// Reset cursor and topline to its stored values from check_lnums().
/// check_lnums() must have been called first!
void reset_lnums(void)