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

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui