diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-02-22 22:45:55 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-02-22 22:45:55 +0100 |
commit | 0c81d1b11278b2d962aa6fbb4aa974dab97be59d (patch) | |
tree | 25ab018d04c0f46216f2321ad47faa1fc9aaed32 /src/term.c | |
parent | b654103ad1e379348616f354272db86804ab4bdb (diff) |
patch 8.2.0302: setting 'term' may cause error in TermChanged autocommandv8.2.0302
Problem: Setting 'term' may cause error in TermChanged autocommand.
Solution: Use aucmd_prepbuf() to switch to the buffer where the autocommand
is to be executed. (closes #5682)
Diffstat (limited to 'src/term.c')
-rw-r--r-- | src/term.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/term.c b/src/term.c index d269eb83c0..e9a9004a2d 100644 --- a/src/term.c +++ b/src/term.c @@ -2071,21 +2071,24 @@ set_termname(char_u *term) check_map_keycodes(); // check mappings for terminal codes used { - bufref_T old_curbuf; + buf_T *buf; + aco_save_T aco; /* * Execute the TermChanged autocommands for each buffer that is * loaded. */ - set_bufref(&old_curbuf, curbuf); - FOR_ALL_BUFFERS(curbuf) + FOR_ALL_BUFFERS(buf) { if (curbuf->b_ml.ml_mfp != NULL) + { + aucmd_prepbuf(&aco, buf); apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE, curbuf); + // restore curwin/curbuf and a few other things + aucmd_restbuf(&aco); + } } - if (bufref_valid(&old_curbuf)) - curbuf = old_curbuf.br_buf; } } |