Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@inkarkat
Copy link

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.

…0677)

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.
@chrisbra
Copy link
Member

chrisbra commented Jun 28, 2017

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' */
`----

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

@brammool brammool closed this in 9c4feff Jun 28, 2017
@inkarkat inkarkat deleted the test-resize-from-copen branch June 29, 2017 09:28
@itchyny
Copy link
Contributor

itchyny commented Jul 2, 2017

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

@mckellyln
Copy link

mckellyln commented Jul 9, 2017

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.

brammool added a commit that referenced this pull request Jul 9, 2017
Problem:    Problems with autocommands when opening help.
Solution:   Avoid using invalid "varp" value.  Allow using :wincmd if buffer
            is locked. (closes #1806, closes #1804)
dpelle pushed a commit to dpelle/vim that referenced this pull request Jul 31, 2017
Problem:    Cannot resize the window in a FileType autocommand. (Ingo Karkat)
Solution:   Add the CMDWIN flag to :resize. (test by Ingo Karkat,
            closes vim#1804)
dpelle pushed a commit to dpelle/vim that referenced this pull request Jul 31, 2017
Problem:    Problems with autocommands when opening help.
Solution:   Avoid using invalid "varp" value.  Allow using :wincmd if buffer
            is locked. (closes vim#1806, closes vim#1804)
janlazo added a commit to janlazo/neovim that referenced this pull request Jun 25, 2018
Problem:    Problems with autocommands when opening help.
Solution:   Avoid using invalid "varp" value.  Allow using :wincmd if buffer
            is locked. (closes vim/vim#1806, closes vim/vim#1804)
vim/vim@163095f
janlazo added a commit to janlazo/neovim that referenced this pull request Jun 25, 2018
Problem:    Cannot resize the window in a FileType autocommand. (Ingo Karkat)
Solution:   Add the CMDWIN flag to :resize. (test by Ingo Karkat,
            closes vim/vim#1804)
vim/vim@9c4feff
janlazo added a commit to janlazo/neovim that referenced this pull request Jun 26, 2018
Problem:    Cannot resize the window in a FileType autocommand. (Ingo Karkat)
Solution:   Add the CMDWIN flag to :resize. (test by Ingo Karkat,
            closes vim/vim#1804)
vim/vim@9c4feff
janlazo added a commit to janlazo/neovim that referenced this pull request Jun 26, 2018
Problem:    Cannot resize the window in a FileType autocommand. (Ingo Karkat)
Solution:   Add the CMDWIN flag to :resize. (test by Ingo Karkat,
            closes vim/vim#1804)
vim/vim@9c4feff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants