refactor: buffer_ensure_loaded()

Cherry-picked from Vim patch 8.1.1612.
This commit is contained in:
zeertzjq
2022-11-29 20:09:07 +08:00
parent 89f0987bde
commit 273358651a
2 changed files with 15 additions and 7 deletions

View File

@@ -175,6 +175,19 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags)
return retval;
}
/// Ensure buffer "buf" is loaded. Does not trigger the swap-exists action.
void buffer_ensure_loaded(buf_T *buf)
{
if (buf->b_ml.ml_mfp == NULL) {
aco_save_T aco;
aucmd_prepbuf(&aco, buf);
swap_exists_action = SEA_NONE;
open_buffer(false, NULL, 0);
aucmd_restbuf(&aco);
}
}
/// Open current buffer, that is: open the memfile and read the file into
/// memory.
///

View File

@@ -302,13 +302,8 @@ void f_bufload(typval_T *argvars, typval_T *unused, EvalFuncData fptr)
{
buf_T *buf = get_buf_arg(&argvars[0]);
if (buf != NULL && buf->b_ml.ml_mfp == NULL) {
aco_save_T aco;
aucmd_prepbuf(&aco, buf);
swap_exists_action = SEA_NONE;
open_buffer(false, NULL, 0);
aucmd_restbuf(&aco);
if (buf != NULL) {
buffer_ensure_loaded(buf);
}
}