commit 273358651af6b6d172944cd1b1b41a9869d53b10
parent 89f0987bde8124f8fcbbcbf8320dbdabe0d69ba9
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue, 29 Nov 2022 20:09:07 +0800
refactor: buffer_ensure_loaded()
Cherry-picked from Vim patch 8.1.1612.
Diffstat:
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
@@ -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.
///
diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c
@@ -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);
}
}