mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +00:00
ex_getln: Replace global with entry in save_ccline
This commit is contained in:
@@ -11108,13 +11108,10 @@ void get_user_input(const typval_T *const argvars,
|
|||||||
stuffReadbuffSpec(defstr);
|
stuffReadbuffSpec(defstr);
|
||||||
|
|
||||||
const int save_ex_normal_busy = ex_normal_busy;
|
const int save_ex_normal_busy = ex_normal_busy;
|
||||||
const Callback save_getln_input_callback = getln_input_callback;
|
|
||||||
ex_normal_busy = 0;
|
ex_normal_busy = 0;
|
||||||
getln_input_callback = input_callback;
|
|
||||||
rettv->vval.v_string =
|
rettv->vval.v_string =
|
||||||
getcmdline_prompt(inputsecret_flag ? NUL : '@', (char_u *)p, echo_attr,
|
(char_u *)getcmdline_prompt(inputsecret_flag ? NUL : '@', p, echo_attr,
|
||||||
xp_type, (char_u *)xp_arg);
|
xp_type, xp_arg, input_callback);
|
||||||
getln_input_callback = save_getln_input_callback;
|
|
||||||
ex_normal_busy = save_ex_normal_busy;
|
ex_normal_busy = save_ex_normal_busy;
|
||||||
callback_free(&input_callback);
|
callback_free(&input_callback);
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ typedef struct partial_S partial_T;
|
|||||||
typedef struct ufunc ufunc_T;
|
typedef struct ufunc ufunc_T;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kCallbackNone,
|
kCallbackNone = 0,
|
||||||
kCallbackFuncref,
|
kCallbackFuncref,
|
||||||
kCallbackPartial,
|
kCallbackPartial,
|
||||||
} CallbackType;
|
} CallbackType;
|
||||||
|
@@ -189,7 +189,8 @@ void do_debug(char_u *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xfree(cmdline);
|
xfree(cmdline);
|
||||||
cmdline = getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL);
|
cmdline = (char_u *)getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL,
|
||||||
|
CALLBACK_NONE);
|
||||||
|
|
||||||
if (typeahead_saved) {
|
if (typeahead_saved) {
|
||||||
restore_typeahead(&typeaheadbuf);
|
restore_typeahead(&typeaheadbuf);
|
||||||
|
@@ -89,6 +89,7 @@ struct cmdline_info {
|
|||||||
char_u *xp_arg; // user-defined expansion arg
|
char_u *xp_arg; // user-defined expansion arg
|
||||||
int input_fn; // when TRUE Invoked for input() function
|
int input_fn; // when TRUE Invoked for input() function
|
||||||
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
|
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
|
||||||
|
Callback highlight_callback; ///< Callback used for coloring user input.
|
||||||
};
|
};
|
||||||
/// Last value of prompt_id, incremented when doing new prompt
|
/// Last value of prompt_id, incremented when doing new prompt
|
||||||
static unsigned last_prompt_id = 0;
|
static unsigned last_prompt_id = 0;
|
||||||
@@ -148,9 +149,6 @@ typedef struct {
|
|||||||
int attr; ///< Highlight attr.
|
int attr; ///< Highlight attr.
|
||||||
} ColoredCmdlineChunk;
|
} ColoredCmdlineChunk;
|
||||||
|
|
||||||
/// Callback used for coloring input() prompts
|
|
||||||
Callback getln_input_callback = { .type = kCallbackNone };
|
|
||||||
|
|
||||||
kvec_t(ColoredCmdlineChunk) ccline_colors;
|
kvec_t(ColoredCmdlineChunk) ccline_colors;
|
||||||
|
|
||||||
/* The current cmdline_info. It is initialized in getcmdline() and after that
|
/* The current cmdline_info. It is initialized in getcmdline() and after that
|
||||||
@@ -1815,42 +1813,50 @@ getcmdline (
|
|||||||
return command_line_enter(firstc, count, indent);
|
return command_line_enter(firstc, count, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Get a command line with a prompt
|
||||||
* Get a command line with a prompt.
|
///
|
||||||
* This is prepared to be called recursively from getcmdline() (e.g. by
|
/// This is prepared to be called recursively from getcmdline() (e.g. by
|
||||||
* f_input() when evaluating an expression from CTRL-R =).
|
/// f_input() when evaluating an expression from `<C-r>=`).
|
||||||
* Returns the command line in allocated memory, or NULL.
|
///
|
||||||
*/
|
/// @param[in] firstc Prompt type: e.g. '@' for input(), '>' for debug.
|
||||||
char_u *
|
/// @param[in] prompt Prompt string: what is displayed before the user text.
|
||||||
getcmdline_prompt (
|
/// @param[in] attr Prompt highlighting.
|
||||||
int firstc,
|
/// @param[in] xp_context Type of expansion.
|
||||||
char_u *prompt, /* command line prompt */
|
/// @param[in] xp_arg User-defined expansion argument.
|
||||||
int attr, /* attributes for prompt */
|
/// @param[in] highlight_callback Callback used for highlighting user input.
|
||||||
int xp_context, /* type of expansion */
|
///
|
||||||
char_u *xp_arg /* user-defined expansion argument */
|
/// @return [allocated] Command line or NULL.
|
||||||
)
|
char *getcmdline_prompt(const char firstc, const char *const prompt,
|
||||||
|
const int attr, const int xp_context,
|
||||||
|
const char *const xp_arg,
|
||||||
|
const Callback highlight_callback)
|
||||||
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
|
||||||
{
|
{
|
||||||
char_u *s;
|
const int msg_col_save = msg_col;
|
||||||
struct cmdline_info save_ccline;
|
|
||||||
int msg_col_save = msg_col;
|
|
||||||
|
|
||||||
|
struct cmdline_info save_ccline;
|
||||||
save_cmdline(&save_ccline);
|
save_cmdline(&save_ccline);
|
||||||
|
|
||||||
ccline.prompt_id = last_prompt_id++;
|
ccline.prompt_id = last_prompt_id++;
|
||||||
ccline.cmdprompt = prompt;
|
ccline.cmdprompt = (char_u *)prompt;
|
||||||
ccline.cmdattr = attr;
|
ccline.cmdattr = attr;
|
||||||
ccline.xp_context = xp_context;
|
ccline.xp_context = xp_context;
|
||||||
ccline.xp_arg = xp_arg;
|
ccline.xp_arg = (char_u *)xp_arg;
|
||||||
ccline.input_fn = (firstc == '@');
|
ccline.input_fn = (firstc == '@');
|
||||||
s = getcmdline(firstc, 1L, 0);
|
ccline.highlight_callback = highlight_callback;
|
||||||
restore_cmdline(&save_ccline);
|
|
||||||
/* Restore msg_col, the prompt from input() may have changed it.
|
|
||||||
* But only if called recursively and the commandline is therefore being
|
|
||||||
* restored to an old one; if not, the input() prompt stays on the screen,
|
|
||||||
* so we need its modified msg_col left intact. */
|
|
||||||
if (ccline.cmdbuff != NULL)
|
|
||||||
msg_col = msg_col_save;
|
|
||||||
|
|
||||||
return s;
|
char *const ret = (char *)getcmdline(firstc, 1L, 0);
|
||||||
|
|
||||||
|
restore_cmdline(&save_ccline);
|
||||||
|
// Restore msg_col, the prompt from input() may have changed it.
|
||||||
|
// But only if called recursively and the commandline is therefore being
|
||||||
|
// restored to an old one; if not, the input() prompt stays on the screen,
|
||||||
|
// so we need its modified msg_col left intact.
|
||||||
|
if (ccline.cmdbuff != NULL) {
|
||||||
|
msg_col = msg_col_save;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2358,8 +2364,10 @@ static bool color_cmdline(void)
|
|||||||
bool dgc_ret = true;
|
bool dgc_ret = true;
|
||||||
bool tl_ret = true;
|
bool tl_ret = true;
|
||||||
|
|
||||||
if (ccline.input_fn) {
|
if (ccline.highlight_callback.type != kCallbackNone) {
|
||||||
color_cb = getln_input_callback;
|
// Currently this should only happen while processing input() prompts.
|
||||||
|
assert(ccline.input_fn);
|
||||||
|
color_cb = ccline.highlight_callback;
|
||||||
} else if (ccline.cmdfirstc == ':') {
|
} else if (ccline.cmdfirstc == ':') {
|
||||||
try_enter(&tstate);
|
try_enter(&tstate);
|
||||||
err_errmsg = N_(
|
err_errmsg = N_(
|
||||||
|
@@ -52,8 +52,6 @@ typedef struct hist_entry {
|
|||||||
list_T *additional_elements; ///< Additional entries from ShaDa file.
|
list_T *additional_elements; ///< Additional entries from ShaDa file.
|
||||||
} histentry_T;
|
} histentry_T;
|
||||||
|
|
||||||
extern Callback getln_input_callback;
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "ex_getln.h.generated.h"
|
# include "ex_getln.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user