aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_getln.c
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2024-02-20 17:25:57 +0100
committerLuuk van Baal <luukvbaal@gmail.com>2024-11-08 13:21:35 +0100
commit5cfa7a72f8c40cdcc0fa93693689915e913806f1 (patch)
tree2c482565d5667dc0ec9caca6e893da7d5a37359a /src/nvim/ex_getln.c
parent5a86360400691e55fae66d60485b61360a1d3d6c (diff)
downloadrneovim-5cfa7a72f8c40cdcc0fa93693689915e913806f1.tar.gz
rneovim-5cfa7a72f8c40cdcc0fa93693689915e913806f1.tar.bz2
rneovim-5cfa7a72f8c40cdcc0fa93693689915e913806f1.zip
refactor(message): propagate highlight id instead of attrs
Problem: Highlight group id is not propagated to the end of the message call stack, where ext_messages are emitted. Solution: Refactor message functions to pass along highlight group id instead of attr id.
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r--src/nvim/ex_getln.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 389e935557..17474f2642 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -811,7 +811,7 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
if (!tl_ret && ERROR_SET(&err)) {
msg_putchar('\n');
msg_scroll = true;
- msg_puts_attr(err.msg, HL_ATTR(HLF_E)|MSG_HIST);
+ msg_puts_hl(err.msg, HLF_E + 1, true);
api_clear_error(&err);
redrawcmd();
}
@@ -2657,7 +2657,7 @@ static void do_autocmd_cmdlinechanged(int firstc)
if (!tl_ret && ERROR_SET(&err)) {
msg_putchar('\n');
msg_scroll = true;
- msg_puts_attr(err.msg, HL_ATTR(HLF_E)|MSG_HIST);
+ msg_puts_hl(err.msg, HLF_E + 1, true);
api_clear_error(&err);
redrawcmd();
}
@@ -2755,13 +2755,13 @@ char *getcmdline(int firstc, int count, int indent, bool do_concat FUNC_ATTR_UNU
///
/// @param[in] firstc Prompt type: e.g. '@' for input(), '>' for debug.
/// @param[in] prompt Prompt string: what is displayed before the user text.
-/// @param[in] attr Prompt highlighting.
+/// @param[in] hl_id Prompt highlight id.
/// @param[in] xp_context Type of expansion.
/// @param[in] xp_arg User-defined expansion argument.
/// @param[in] highlight_callback Callback used for highlighting user input.
///
/// @return [allocated] Command line or NULL.
-char *getcmdline_prompt(const int firstc, const char *const prompt, const int attr,
+char *getcmdline_prompt(const int firstc, const char *const prompt, const int hl_id,
const int xp_context, const char *const xp_arg,
const Callback highlight_callback)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
@@ -2779,7 +2779,7 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at
}
ccline.prompt_id = last_prompt_id++;
ccline.cmdprompt = (char *)prompt;
- ccline.cmdattr = attr;
+ ccline.hl_id = hl_id;
ccline.xp_context = xp_context;
ccline.xp_arg = (char *)xp_arg;
ccline.input_fn = (firstc == '@');
@@ -3095,15 +3095,13 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)prev_end,
.end = (int)chunk.start.col,
- .attr = 0,
+ .hl_id = 0,
}));
}
- const int id = syn_name2id(chunk.group);
- const int attr = (id == 0 ? 0 : syn_id2attr(id));
kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)chunk.start.col,
.end = (int)chunk.end_col,
- .attr = attr,
+ .hl_id = syn_name2id(chunk.group),
}));
prev_end = chunk.end_col;
}
@@ -3111,7 +3109,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)prev_end,
.end = colored_ccline->cmdlen,
- .attr = 0,
+ .hl_id = 0,
}));
}
kvi_destroy(colors);
@@ -3140,7 +3138,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
#define PRINT_ERRMSG(...) \
do { \
msg_putchar('\n'); \
- msg_printf_attr(HL_ATTR(HLF_E)|MSG_HIST, __VA_ARGS__); \
+ msg_printf_hl(HLF_E + 1, __VA_ARGS__); \
printed_errmsg = true; \
} while (0)
bool ret = true;
@@ -3275,7 +3273,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
kv_push(ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)prev_end,
.end = (int)start,
- .attr = 0,
+ .hl_id = 0,
}));
}
const varnumber_T end =
@@ -3299,12 +3297,10 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
if (group == NULL) {
goto color_cmdline_error;
}
- const int id = syn_name2id(group);
- const int attr = (id == 0 ? 0 : syn_id2attr(id));
kv_push(ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)start,
.end = (int)end,
- .attr = attr,
+ .hl_id = syn_name2id(group),
}));
i++;
});
@@ -3312,7 +3308,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
kv_push(ccline_colors->colors, ((CmdlineColorChunk) {
.start = (int)prev_end,
.end = colored_ccline->cmdlen,
- .attr = 0,
+ .hl_id = 0,
}));
}
prev_prompt_errors = 0;
@@ -3374,10 +3370,10 @@ static void draw_cmdline(int start, int len)
continue;
}
const int chunk_start = MAX(chunk.start, start);
- msg_outtrans_len(ccline.cmdbuff + chunk_start, chunk.end - chunk_start, chunk.attr);
+ msg_outtrans_len(ccline.cmdbuff + chunk_start, chunk.end - chunk_start, chunk.hl_id, false);
}
} else {
- msg_outtrans_len(ccline.cmdbuff + start, len, 0);
+ msg_outtrans_len(ccline.cmdbuff + start, len, 0, false);
}
}
}
@@ -3403,7 +3399,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line)
for (size_t i = 0; i < kv_size(line->last_colors.colors); i++) {
CmdlineColorChunk chunk = kv_A(line->last_colors.colors, i);
Array item = arena_array(&arena, 2);
- ADD_C(item, INTEGER_OBJ(chunk.attr));
+ ADD_C(item, INTEGER_OBJ(chunk.hl_id == 0 ? 0 : syn_id2attr(chunk.hl_id)));
assert(chunk.end >= chunk.start);
ADD_C(item, STRING_OBJ(cbuf_as_string(line->cmdbuff + chunk.start,
@@ -3813,7 +3809,7 @@ static void redrawcmdprompt(void)
msg_putchar(ccline.cmdfirstc);
}
if (ccline.cmdprompt != NULL) {
- msg_puts_attr(ccline.cmdprompt, ccline.cmdattr);
+ msg_puts_hl(ccline.cmdprompt, ccline.hl_id, false);
ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
// do the reverse of cmd_startcol()
if (ccline.cmdfirstc != NUL) {
@@ -4801,7 +4797,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
p = lastnl + 1;
msg_start();
msg_clr_eos();
- msg_puts_len(prompt, p - prompt, get_echo_attr());
+ msg_puts_len(prompt, p - prompt, get_echo_hl_id(), false);
msg_didout = false;
msg_starthere();
}
@@ -4812,7 +4808,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
const int save_ex_normal_busy = ex_normal_busy;
ex_normal_busy = 0;
- rettv->vval.v_string = getcmdline_prompt(secret ? NUL : '@', p, get_echo_attr(),
+ rettv->vval.v_string = getcmdline_prompt(secret ? NUL : '@', p, get_echo_hl_id(),
xp_type, xp_arg, input_callback);
ex_normal_busy = save_ex_normal_busy;
callback_free(&input_callback);