[vim/vim] Regression: :resize in :autocmd on :copen fails with E788 (after 8.0.677) (#1804)

221 views
Skip to first unread message

Ingo Karkat

unread,
Jun 28, 2017, 5:24:04 AM6/28/17
to vim/vim, Subscribed

I have an :autocmd that adapts the height of the quickfix window if there are fewer entries in it than the window height (to save screen space). It boils down to this:

:autocmd BufRead quickfix resize [N]

Since Vim 8.0.0677 (setting 'filetype' may switch buffers; found through bisecting), this fails with E788: Not allowed to edit another buffer now.

The patch locks the current buffer. However, I don't see why resizing the current window should be affected by the lock.

I tried following the call chain of :resize, but couldn't locate where this encounters the check of curbuf_lock. All I can offer is the following test (based on Test_cclose_from_copen()) that highlights the regression. It also uses :autocmd FileType qf instead of :autocmd BufRead quickfix; both show the issue.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/1804

Commit Summary

  • Regression: :resize in :autocmd on :copen fails with E788 (after 8.0.0677)

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Christian Brabandt

unread,
Jun 28, 2017, 6:45:21 AM6/28/17
to vim-dev

On Mi, 28 Jun 2017, Ingo Karkat wrote:

> I have an `:autocmd` that adapts the height of the quickfix window if
> there are fewer entries in it than the window height (to save screen
> space). It boils down to this:
>
> :autocmd BufRead quickfix resize [N]
>
> Since Vim 8.0.0677 (_setting 'filetype' may switch buffers_; found
> through bisecting), this fails with `E788: Not allowed to edit another
> buffer now`.
>
> The patch locks the current buffer. However, I don't see why resizing
> the current window should be affected by the lock.
>
> I tried following the call chain of `:resize`, but couldn't locate
> where this encounters the check of `curbuf_lock`. All I can offer is
> the following test (based on `Test_cclose_from_copen()`) that
> highlights the regression. It also uses `:autocmd FileType qf`
> instead of `:autocmd BufRead quickfix`; both show the issue.

Hm, here:

,----[ quickfix.c ]-
| 3428 #ifdef FEAT_AUTOCMD
| 3429 ++curbuf_lock;
| 3430 #endif
| 3431 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL);
| 3432 curbuf->b_p_ma = FALSE;
| 3433
| 3434 #ifdef FEAT_AUTOCMD
| 3435 keep_filetype = TRUE; /* don't detect 'filetype' */
`----

we are setting curbuf_lock. set_option_value() triggers the FileType
autocommand, and will finally call do_one_cmd() to execute the :resize
command. However in do_one_cmd() we do check curbuf_lock before
continuing:

,----[ ex_docmd.c ]-
| 2463 #ifdef FEAT_AUTOCMD
| 2464 /* Disallow editing another buffer when "curbuf_lock" is set.
| 2465 * Do allow ":edit" (check for argument later).
| 2466 * Do allow ":checktime" (it's postponed). */
| 2467 if (!(ea.argt & CMDWIN)
| 2468 && ea.cmdidx != CMD_edit
| 2469 && ea.cmdidx != CMD_checktime
| 2470 && !IS_USER_CMDIDX(ea.cmdidx)
| 2471 && curbuf_locked())
| 2472 goto doend;
| 2473 #endif
`----

However it is not clear to me, why there is the check to curbuf_locked()
there, because as you say, there is no indication that we are going to
move to another buffer. Perhaps that should be changed to this
condition:

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index bdd152dfd..a7946d872 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2468,7 +2468,7 @@ do_one_cmd(
&& ea.cmdidx != CMD_edit
&& ea.cmdidx != CMD_checktime
&& !IS_USER_CMDIDX(ea.cmdidx)
- && curbuf_locked())
+ && (ea.addr_type && curbuf_locked()))
goto doend;
#endif


(Well, this seems to fix your case, while still preventing e.g.
au Filetype qf wincmd p)

Best,
Christian
--
Der Sinn in den Gebräuchen der Gastfreundschaft ist: das feindliche im
Fremden zu lähmen.
-- Friedrich Wilhelm Nietzsche

Christian Brabandt

unread,
Jun 28, 2017, 6:49:29 AM6/28/17
to vim/vim, Subscribed

Copying here my message from the vim-dev ml:
Hm, here:

,----[ quickfix.c ]-
| 3428 #ifdef FEAT_AUTOCMD
| 3429 ++curbuf_lock;
| 3430 #endif

| 3431 set_option_value((char_u *)"ft", 0L, (char_u )"qf", OPT_LOCAL);


| 3432 curbuf->b_p_ma = FALSE;
| 3433
| 3434 #ifdef FEAT_AUTOCMD

| 3435 keep_filetype = TRUE; / don't detect 'filetype' */
`----

  •           && curbuf_locked())
    
  •           && (ea.addr_type && curbuf_locked()))
          goto doend;
    

#endif

(Well, this seems to fix your case, while still preventing e.g.
au Filetype qf wincmd p)

Best,
Christian

Bram Moolenaar

unread,
Jun 28, 2017, 4:27:22 PM6/28/17
to vim...@googlegroups.com, Christian Brabandt, vim-dev
What does ea.addr_type has to do with editing another buffer?

I think the problem is that the resize command is missing the CMDWIN
flag. Don't see a reason why it is missing.

--
From "know your smileys":
<>:-) Bishop

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Jun 28, 2017, 4:27:32 PM6/28/17
to vim/vim, Subscribed

Closed #1804 via 9c4feff.

Christian Brabandt

unread,
Jun 28, 2017, 4:49:26 PM6/28/17
to vim...@googlegroups.com

On Mi, 28 Jun 2017, Bram Moolenaar wrote:

> What does ea.addr_type has to do with editing another buffer?

If addr_type is zero it is using lines as address, so it is not using
windows or buffers as address (and I thought it would be unprobable to
change buffers for commands that work on lines).

> I think the problem is that the resize command is missing the CMDWIN
> flag. Don't see a reason why it is missing.

works also, however it is not obvious, that the CMDWIN flag means
editing another buffer won't happen.

Best,
Christian
--
Menschen werden schlecht und schuldig, weil sie reden und handeln,
ohne die Folgen ihrer Worte und Taten vorauszusehen.
-- Franz Kafka

Bram Moolenaar

unread,
Jun 28, 2017, 5:01:32 PM6/28/17
to vim...@googlegroups.com, Christian Brabandt

Christian Brabandt wrote:

> On Mi, 28 Jun 2017, Bram Moolenaar wrote:
>
> > What does ea.addr_type has to do with editing another buffer?
>
> If addr_type is zero it is using lines as address, so it is not using
> windows or buffers as address (and I thought it would be unprobable to
> change buffers for commands that work on lines).
>
> > I think the problem is that the resize command is missing the CMDWIN
> > flag. Don't see a reason why it is missing.
>
> works also, however it is not obvious, that the CMDWIN flag means
> editing another buffer won't happen.

That's why I updated the comment (before you even asked :-).

--
From "know your smileys":
2B|^2B Message from Shakespeare

itchyny

unread,
Jul 2, 2017, 9:30:25 AM7/2/17
to vim/vim, Subscribed

Hello. I configure as moving help window by autocmd FileType help if &l:buftype ==# 'help' | wincmd K | endif. It worked with no errors before but emits E788 error recently. I believe my issue is related to this.
Ken Hamada

Mark Kelly

unread,
Jul 8, 2017, 10:02:27 PM7/8/17
to vim/vim, Subscribed

I also have the same [new] E788 problem recently and still in 8.0.702 with this -

au FileType qf call AdjustWindowHeight(5, 10)
function! AdjustWindowHeight(minheight, maxheight)
let l = 1
let n_lines = 0
let w_width = winwidth(0)
while l <= line('$')
" number to float for division
let l_len = strlen(getline(l)) + 0.0
let line_width = l_len/w_width
let n_lines += float2nr(ceil(line_width))
let l += 2
endw
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _"
endfunction

This ex_docmd.c change (from above):

  •           && curbuf_locked())
    
  •           && (ea.addr_type && curbuf_locked()))
    

resolves it.

Reply all
Reply to author
Forward
0 new messages