diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-01-31 09:27:22 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-01-31 17:16:41 +0000 |
commit | cb3be2c766b79cf7a9ba642a565fa87aab76d2ab (patch) | |
tree | 16a8123c3e8aff9dd8fe969fbfe2464f8398f753 | |
parent | 842cf780a6aa11df0411b41573f263bc5c151405 (diff) | |
download | rneovim-cb3be2c766b79cf7a9ba642a565fa87aab76d2ab.tar.gz rneovim-cb3be2c766b79cf7a9ba642a565fa87aab76d2ab.tar.bz2 rneovim-cb3be2c766b79cf7a9ba642a565fa87aab76d2ab.zip |
refactor(fileio.c): factor out buf_write post autocmds
-rw-r--r-- | src/nvim/fileio.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index c5c5a26d9d..047abebde0 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2252,6 +2252,35 @@ static int buf_write_do_autocmds(buf_T *buf, char **fnamep, char **sfnamep, char return NOTDONE; } +static void buf_write_do_post_autocmds(buf_T *buf, char *fname, exarg_T *eap, bool append, + bool filtering, bool reset_changed, bool whole) +{ + aco_save_T aco; + + curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read + + // Apply POST autocommands. + // Careful: The autocommands may call buf_write() recursively! + aucmd_prepbuf(&aco, buf); + + if (append) { + apply_autocmds_exarg(EVENT_FILEAPPENDPOST, fname, fname, + false, curbuf, eap); + } else if (filtering) { + apply_autocmds_exarg(EVENT_FILTERWRITEPOST, NULL, fname, + false, curbuf, eap); + } else if (reset_changed && whole) { + apply_autocmds_exarg(EVENT_BUFWRITEPOST, fname, fname, + false, curbuf, eap); + } else { + apply_autocmds_exarg(EVENT_FILEWRITEPOST, fname, fname, + false, curbuf, eap); + } + + // restore curwin/curbuf and a few other things + aucmd_restbuf(&aco); +} + static inline Error_T set_err_num(const char *num, const char *msg) { return (Error_T){ .num = num, .msg = (char *)msg, .arg = 0 }; @@ -3555,31 +3584,7 @@ nofail: } if (!should_abort(retval)) { - aco_save_T aco; - - curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read - - // Apply POST autocommands. - // Careful: The autocommands may call buf_write() recursively! - aucmd_prepbuf(&aco, buf); - - if (append) { - apply_autocmds_exarg(EVENT_FILEAPPENDPOST, fname, fname, - false, curbuf, eap); - } else if (filtering) { - apply_autocmds_exarg(EVENT_FILTERWRITEPOST, NULL, fname, - false, curbuf, eap); - } else if (reset_changed && whole) { - apply_autocmds_exarg(EVENT_BUFWRITEPOST, fname, fname, - false, curbuf, eap); - } else { - apply_autocmds_exarg(EVENT_FILEWRITEPOST, fname, fname, - false, curbuf, eap); - } - - // restore curwin/curbuf and a few other things - aucmd_restbuf(&aco); - + buf_write_do_post_autocmds(buf, fname, eap, append, filtering, reset_changed, whole); if (aborting()) { // autocmds may abort script processing retval = false; } |