API: Context: save/restore

This commit is contained in:
Abdelhakeem
2019-07-21 21:41:04 +02:00
committed by Justin M. Keyes
parent 691deca2e8
commit b6278bbf12
8 changed files with 218 additions and 28 deletions

View File

@@ -8064,6 +8064,10 @@ static void f_ctxpush(typval_T *argvars, typval_T *rettv, FunPtr fptr)
types |= kCtxBuflist;
} else if (strequal((char *)tv_li->vval.v_string, "gvars")) {
types |= kCtxGVars;
} else if (strequal((char *)tv_li->vval.v_string, "sfuncs")) {
types |= kCtxSFuncs;
} else if (strequal((char *)tv_li->vval.v_string, "funcs")) {
types |= kCtxFuncs;
}
}
});
@@ -20981,7 +20985,7 @@ void ex_function(exarg_T *eap)
continue;
}
if (!func_name_refcount(fp->uf_name)) {
list_func_head(fp, false);
list_func_head(fp, false, false);
}
}
}
@@ -21012,7 +21016,7 @@ void ex_function(exarg_T *eap)
fp = HI2UF(hi);
if (!isdigit(*fp->uf_name)
&& vim_regexec(&regmatch, fp->uf_name, 0))
list_func_head(fp, FALSE);
list_func_head(fp, false, false);
}
}
vim_regfree(regmatch.regprog);
@@ -21062,9 +21066,12 @@ void ex_function(exarg_T *eap)
saved_did_emsg = did_emsg;
did_emsg = FALSE;
/*
* ":function func" with only function name: list function.
*/
//
// ":function func" with only function name: list function.
// If bang is given:
// - include "!" in function head
// - exclude line numbers from function body
//
if (!paren) {
if (!ends_excmd(*skipwhite(p))) {
EMSG(_(e_trailing));
@@ -21076,17 +21083,20 @@ void ex_function(exarg_T *eap)
if (!eap->skip && !got_int) {
fp = find_func(name);
if (fp != NULL) {
list_func_head(fp, TRUE);
for (int j = 0; j < fp->uf_lines.ga_len && !got_int; ++j) {
if (FUNCLINE(fp, j) == NULL)
list_func_head(fp, !eap->forceit, eap->forceit);
for (int j = 0; j < fp->uf_lines.ga_len && !got_int; j++) {
if (FUNCLINE(fp, j) == NULL) {
continue;
msg_putchar('\n');
msg_outnum((long)j + 1);
if (j < 9) {
msg_putchar(' ');
}
if (j < 99) {
msg_putchar(' ');
msg_putchar('\n');
if (!eap->forceit) {
msg_outnum((long)j + 1);
if (j < 9) {
msg_putchar(' ');
}
if (j < 99) {
msg_putchar(' ');
}
}
msg_prt_line(FUNCLINE(fp, j), false);
ui_flush(); // show a line at a time
@@ -21094,7 +21104,7 @@ void ex_function(exarg_T *eap)
}
if (!got_int) {
msg_putchar('\n');
msg_puts(" endfunction");
msg_puts(eap->forceit ? "endfunction" : " endfunction");
}
} else
emsg_funcname(N_("E123: Undefined function: %s"), name);
@@ -21784,15 +21794,17 @@ static inline bool eval_fname_sid(const char *const name)
return *name == 's' || TOUPPER_ASC(name[2]) == 'I';
}
/*
* List the head of the function: "name(arg1, arg2)".
*/
static void list_func_head(ufunc_T *fp, int indent)
/// List the head of the function: "name(arg1, arg2)".
///
/// @param[in] fp Function pointer.
/// @param[in] indent Indent line.
/// @param[in] force Include bang "!" (i.e.: "function!").
static void list_func_head(ufunc_T *fp, int indent, bool force)
{
msg_start();
if (indent)
MSG_PUTS(" ");
MSG_PUTS("function ");
MSG_PUTS(force ? "function! " : "function ");
if (fp->uf_name[0] == K_SPECIAL) {
MSG_PUTS_ATTR("<SNR>", HL_ATTR(HLF_8));
msg_puts((const char *)fp->uf_name + 3);