diff options
-rw-r--r-- | src/nvim/quickfix.c | 18 | ||||
-rw-r--r-- | src/nvim/version.c | 2 | ||||
-rw-r--r-- | test/functional/legacy/quickfix_spec.lua | 24 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 151b9d3790..f48560007a 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1581,9 +1581,17 @@ win_found: ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, ECMD_HIDE + ECMD_SET_HELP, oldwin == curwin ? curwin : NULL); - } else + } else { ok = buflist_getfile(qf_ptr->qf_fnum, (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); + if (qi != &ql_info && !win_valid(oldwin)) { + EMSG(_("E924: Current window was closed")); + ok = false; + qi = NULL; + qf_ptr = NULL; + opened_window = false; + } + } } if (ok == OK) { @@ -1665,7 +1673,7 @@ win_found: } else { if (opened_window) win_close(curwin, TRUE); /* Close opened window */ - if (qf_ptr->qf_fnum != 0) { + if (qf_ptr != NULL && qf_ptr->qf_fnum != 0) { /* * Couldn't open file, so put index back where it was. This could * happen if the file was readonly and we changed something. @@ -1676,8 +1684,10 @@ failed: } } theend: - qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; - qi->qf_lists[qi->qf_curlist].qf_index = qf_index; + if (qi != NULL) { + qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; + qi->qf_lists[qi->qf_curlist].qf_index = qf_index; + } if (p_swb != old_swb && opened_window) { /* Restore old 'switchbuf' value, but not when an autocommand or * modeline has changed the value. */ diff --git a/src/nvim/version.c b/src/nvim/version.c index 5364fee953..540c253c49 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -100,7 +100,7 @@ static int included_patches[] = { // 1595 NA // 1594 NA // 1593 NA - // 1592, + 1592, // 1591, // 1590, // 1589, diff --git a/test/functional/legacy/quickfix_spec.lua b/test/functional/legacy/quickfix_spec.lua index ca98765336..df8f2625db 100644 --- a/test/functional/legacy/quickfix_spec.lua +++ b/test/functional/legacy/quickfix_spec.lua @@ -258,6 +258,25 @@ describe('helpgrep', function() \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') endfunction + + function Test_locationlist_curwin_was_closed() + augroup testgroup + au! + autocmd BufReadCmd t call R(expand("<amatch>")) + augroup END + + function R(n) + quit + endfunc + + new + let q = [] + call add(q, {'filename': 't' }) + call setloclist(0, q) + call assert_fails('lrewind', 'E924:') + + augroup! testgroup + endfunction ]]) end) @@ -315,4 +334,9 @@ describe('helpgrep', function() execute('copen') eq(':setqflist()', eval('g:foo')) end) + + it('errors when an autocommand closes the location list\'s window', function() + call('Test_locationlist_curwin_was_closed') + expected_empty() + end) end) |