mirror of
https://github.com/vim/vim.git
synced 2025-10-13 06:54:15 -04:00
patch 8.1.1610: there is no way to add or load a buffer without side effects
Problem: There is no way to add or load a buffer without side effects. Solution: Add the bufadd() and bufload() functions.
This commit is contained in:
@@ -71,8 +71,10 @@ static void f_balloon_split(typval_T *argvars, typval_T *rettv);
|
||||
#endif
|
||||
static void f_browse(typval_T *argvars, typval_T *rettv);
|
||||
static void f_browsedir(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufadd(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufexists(typval_T *argvars, typval_T *rettv);
|
||||
static void f_buflisted(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufload(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufloaded(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufname(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufnr(typval_T *argvars, typval_T *rettv);
|
||||
@@ -526,11 +528,13 @@ static struct fst
|
||||
#endif
|
||||
{"browse", 4, 4, f_browse},
|
||||
{"browsedir", 2, 2, f_browsedir},
|
||||
{"bufadd", 1, 1, f_bufadd},
|
||||
{"bufexists", 1, 1, f_bufexists},
|
||||
{"buffer_exists", 1, 1, f_bufexists}, /* obsolete */
|
||||
{"buffer_name", 1, 1, f_bufname}, /* obsolete */
|
||||
{"buffer_number", 1, 1, f_bufnr}, /* obsolete */
|
||||
{"buflisted", 1, 1, f_buflisted},
|
||||
{"bufload", 1, 1, f_bufload},
|
||||
{"bufloaded", 1, 1, f_bufloaded},
|
||||
{"bufname", 1, 1, f_bufname},
|
||||
{"bufnr", 1, 2, f_bufnr},
|
||||
@@ -1919,6 +1923,15 @@ find_buffer(typval_T *avar)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufadd(expr)" function
|
||||
*/
|
||||
static void
|
||||
f_bufadd(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
rettv->vval.v_number = buflist_add(tv_get_string(&argvars[0]), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufexists(expr)" function
|
||||
*/
|
||||
@@ -1940,6 +1953,25 @@ f_buflisted(typval_T *argvars, typval_T *rettv)
|
||||
rettv->vval.v_number = (buf != NULL && buf->b_p_bl);
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufload(expr)" function
|
||||
*/
|
||||
static void
|
||||
f_bufload(typval_T *argvars, typval_T *rettv UNUSED)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufloaded(expr)" function
|
||||
*/
|
||||
|
Reference in New Issue
Block a user