mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 07:28:34 +00:00
vim-patch:8.0.0677: setting 'filetype' may switch buffers
Problem: Setting 'filetype' internally may cause the current buffer and
window to change unexpectedly.
Solution: Set curbuf_lock. (closes vim/vim#1734)
1814183b86
This commit is contained in:
@@ -4906,7 +4906,9 @@ void fix_help_buffer(void)
|
|||||||
|
|
||||||
// Set filetype to "help".
|
// Set filetype to "help".
|
||||||
if (STRCMP(curbuf->b_p_ft, "help") != 0) {
|
if (STRCMP(curbuf->b_p_ft, "help") != 0) {
|
||||||
|
curbuf_lock++;
|
||||||
set_option_value("ft", 0L, "help", OPT_LOCAL);
|
set_option_value("ft", 0L, "help", OPT_LOCAL);
|
||||||
|
curbuf_lock--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!syntax_present(curwin)) {
|
if (!syntax_present(curwin)) {
|
||||||
|
@@ -6057,8 +6057,10 @@ static int open_cmdwin(void)
|
|||||||
curbuf->b_p_ma = true;
|
curbuf->b_p_ma = true;
|
||||||
curwin->w_p_fen = false;
|
curwin->w_p_fen = false;
|
||||||
|
|
||||||
/* Do execute autocommands for setting the filetype (load syntax). */
|
// Do execute autocommands for setting the filetype (load syntax).
|
||||||
unblock_autocmds();
|
unblock_autocmds();
|
||||||
|
// But don't allow switching to another buffer.
|
||||||
|
curbuf_lock++;
|
||||||
|
|
||||||
/* Showing the prompt may have set need_wait_return, reset it. */
|
/* Showing the prompt may have set need_wait_return, reset it. */
|
||||||
need_wait_return = FALSE;
|
need_wait_return = FALSE;
|
||||||
@@ -6071,6 +6073,7 @@ static int open_cmdwin(void)
|
|||||||
}
|
}
|
||||||
set_option_value("ft", 0L, "vim", OPT_LOCAL);
|
set_option_value("ft", 0L, "vim", OPT_LOCAL);
|
||||||
}
|
}
|
||||||
|
curbuf_lock--;
|
||||||
|
|
||||||
/* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
|
/* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
|
||||||
* sets 'textwidth' to 78). */
|
* sets 'textwidth' to 78). */
|
||||||
|
@@ -3008,6 +3008,7 @@ static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
|
|||||||
// Set the 'filetype' to "qf" each time after filling the buffer. This
|
// Set the 'filetype' to "qf" each time after filling the buffer. This
|
||||||
// resembles reading a file into a buffer, it's more logical when using
|
// resembles reading a file into a buffer, it's more logical when using
|
||||||
// autocommands.
|
// autocommands.
|
||||||
|
curbuf_lock++;
|
||||||
set_option_value("ft", 0L, "qf", OPT_LOCAL);
|
set_option_value("ft", 0L, "qf", OPT_LOCAL);
|
||||||
curbuf->b_p_ma = false;
|
curbuf->b_p_ma = false;
|
||||||
|
|
||||||
@@ -3017,6 +3018,7 @@ static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
|
|||||||
apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
|
apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
|
||||||
false, curbuf);
|
false, curbuf);
|
||||||
keep_filetype = false;
|
keep_filetype = false;
|
||||||
|
curbuf_lock--;
|
||||||
|
|
||||||
// make sure it will be redrawn
|
// make sure it will be redrawn
|
||||||
redraw_curbuf_later(NOT_VALID);
|
redraw_curbuf_later(NOT_VALID);
|
||||||
|
@@ -2172,7 +2172,7 @@ endfunc
|
|||||||
func Test_cclose_from_copen()
|
func Test_cclose_from_copen()
|
||||||
augroup QF_Test
|
augroup QF_Test
|
||||||
au!
|
au!
|
||||||
au FileType qf :cclose
|
au FileType qf :call assert_fails(':cclose', 'E788')
|
||||||
augroup END
|
augroup END
|
||||||
copen
|
copen
|
||||||
augroup QF_Test
|
augroup QF_Test
|
||||||
@@ -2209,3 +2209,19 @@ func Test_Qf_Size()
|
|||||||
call XsizeTests('c')
|
call XsizeTests('c')
|
||||||
call XsizeTests('l')
|
call XsizeTests('l')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_cclose_in_autocmd()
|
||||||
|
" Problem is only triggered if "starting" is zero, so that the OptionsSet
|
||||||
|
" event will be triggered.
|
||||||
|
" call test_override('starting', 1)
|
||||||
|
augroup QF_Test
|
||||||
|
au!
|
||||||
|
au FileType qf :call assert_fails(':cclose', 'E788')
|
||||||
|
augroup END
|
||||||
|
copen
|
||||||
|
augroup QF_Test
|
||||||
|
au!
|
||||||
|
augroup END
|
||||||
|
augroup! QF_Test
|
||||||
|
" call test_override('starting', 0)
|
||||||
|
endfunc
|
||||||
|
Reference in New Issue
Block a user