Skip to content

Commit

Permalink
Merge pull request #25396 from bfredl/no_attr
Browse files Browse the repository at this point in the history
refactor(messages): fold msg() functions with and without attr
  • Loading branch information
bfredl committed Sep 27, 2023
2 parents 86b7d8a + 448d483 commit e46f5aa
Show file tree
Hide file tree
Showing 42 changed files with 382 additions and 413 deletions.
35 changes: 16 additions & 19 deletions src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,40 +1699,37 @@ static void write_msg(String message, bool to_err, bool writeln)
{
static StringBuilder out_line_buf = KV_INITIAL_VALUE;
static StringBuilder err_line_buf = KV_INITIAL_VALUE;
StringBuilder *line_buf = to_err ? &err_line_buf : &out_line_buf;

#define PUSH_CHAR(c, line_buf, msg) \
if (kv_max(line_buf) == 0) { \
kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \
#define PUSH_CHAR(c) \
if (kv_max(*line_buf) == 0) { \
kv_resize(*line_buf, LINE_BUFFER_MIN_SIZE); \
} \
if (c == NL) { \
kv_push(line_buf, NUL); \
msg(line_buf.items); \
kv_push(*line_buf, NUL); \
if (to_err) { \
emsg(line_buf->items); \
} else { \
msg(line_buf->items, 0); \
} \
msg_didout = true; \
kv_drop(line_buf, kv_size(line_buf)); \
kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \
kv_drop(*line_buf, kv_size(*line_buf)); \
kv_resize(*line_buf, LINE_BUFFER_MIN_SIZE); \
} else if (c == NUL) { \
kv_push(line_buf, NL); \
kv_push(*line_buf, NL); \
} else { \
kv_push(line_buf, c); \
kv_push(*line_buf, c); \
}

no_wait_return++;
for (uint32_t i = 0; i < message.size; i++) {
if (got_int) {
break;
}
if (to_err) {
PUSH_CHAR(message.data[i], err_line_buf, emsg);
} else {
PUSH_CHAR(message.data[i], out_line_buf, msg);
}
PUSH_CHAR(message.data[i]);
}
if (writeln) {
if (to_err) {
PUSH_CHAR(NL, err_line_buf, emsg);
} else {
PUSH_CHAR(NL, out_line_buf, msg);
}
PUSH_CHAR(NL);
}
no_wait_return--;
msg_end();
Expand Down
6 changes: 3 additions & 3 deletions src/nvim/autocmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void au_show_for_event(int group, event_T event, const char *pat)
}

msg_col = 4;
msg_outtrans(ac->pat->pat);
msg_outtrans(ac->pat->pat, 0);
}

if (got_int) {
Expand All @@ -253,12 +253,12 @@ static void au_show_for_event(int group, event_T event, const char *pat)
} else {
snprintf(msg, msglen, "%s [%s]", exec_to_string, ac->desc);
}
msg_outtrans(msg);
msg_outtrans(msg, 0);
XFREE_CLEAR(msg);
} else if (ac->exec.type == CALLABLE_CB) {
msg_puts_attr(exec_to_string, HL_ATTR(HLF_8));
} else {
msg_outtrans(exec_to_string);
msg_outtrans(exec_to_string, 0);
}
XFREE_CLEAR(exec_to_string);
if (p_verbose > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/nvim/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ void buflist_list(exarg_T *eap)
buf == curbuf ? (int64_t)curwin->w_cursor.lnum : (int64_t)buflist_findlnum(buf));
}

msg_outtrans(IObuff);
msg_outtrans(IObuff, 0);
line_breakcheck();
}

Expand Down Expand Up @@ -3230,10 +3230,10 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
msg_start();
n = msg_scroll;
msg_scroll = true;
msg(buffer);
msg(buffer, 0);
msg_scroll = n;
} else {
p = msg_trunc_attr(buffer, false, 0);
p = msg_trunc(buffer, false, 0);
if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) {
// Need to repeat the message after redrawing when:
// - When restart_edit is set (otherwise there will be a delay
Expand Down
7 changes: 3 additions & 4 deletions src/nvim/bufwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ static int check_mtime(buf_T *buf, FileInfo *file_info)
msg_scroll = true; // Don't overwrite messages here.
msg_silent = 0; // Must give this prompt.
// Don't use emsg() here, don't want to flush the buffers.
msg_attr(_("WARNING: The file has been changed since reading it!!!"),
HL_ATTR(HLF_E));
msg(_("WARNING: The file has been changed since reading it!!!"), HL_ATTR(HLF_E));
if (ask_yesno(_("Do you really want to write to it"), true) == 'n') {
return FAIL;
}
Expand Down Expand Up @@ -1721,7 +1720,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
// This may take a while, if we were interrupted let the user
// know we got the message.
if (got_int) {
msg(_(e_interr));
msg(_(e_interr), 0);
ui_flush();
}

Expand Down Expand Up @@ -1786,7 +1785,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
}
}

set_keep_msg(msg_trunc_attr(IObuff, false, 0), 0);
set_keep_msg(msg_trunc(IObuff, false, 0), 0);
}

// When written everything correctly: reset 'modified'. Unless not
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/cmdexpand.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in
int lastlen = 999;
for (int j = linenr; j < numMatches; j += lines) {
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
msg_outtrans_attr(matches[j], HL_ATTR(HLF_D));
msg_outtrans(matches[j], HL_ATTR(HLF_D));
p = matches[j] + strlen(matches[j]) + 1;
msg_advance(maxlen + 1);
msg_puts(p);
Expand Down Expand Up @@ -1013,7 +1013,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in
isdir = false;
p = SHOW_MATCH(j);
}
lastlen = msg_outtrans_attr(p, isdir ? dir_attr : 0);
lastlen = msg_outtrans(p, isdir ? dir_attr : 0);
}
if (msg_col > 0) { // when not wrapped around
msg_clr_eos();
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/cmdhist.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void ex_history(exarg_T *eap)
char *arg = eap->arg;

if (hislen == 0) {
msg(_("'history' option is zero"));
msg(_("'history' option is zero"), 0);
return;
}

Expand Down Expand Up @@ -672,7 +672,7 @@ void ex_history(exarg_T *eap)
} else {
xstrlcat(IObuff, hist[i].hisstr, IOSIZE);
}
msg_outtrans(IObuff);
msg_outtrans(IObuff, 0);
}
if (i == idx) {
break;
Expand Down
8 changes: 4 additions & 4 deletions src/nvim/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void do_debug(char *cmd)
debug_mode = true;

if (!debug_did_msg) {
msg(_("Entering Debug mode. Type \"cont\" to continue."));
msg(_("Entering Debug mode. Type \"cont\" to continue."), 0);
}
if (debug_oldval != NULL) {
smsg(_("Oldval = \"%s\""), debug_oldval);
Expand All @@ -116,7 +116,7 @@ void do_debug(char *cmd)
}
char *sname = estack_sfile(ESTACK_NONE);
if (sname != NULL) {
msg(sname);
msg(sname, 0);
}
xfree(sname);
if (SOURCING_LNUM != 0) {
Expand Down Expand Up @@ -345,7 +345,7 @@ static void do_checkbacktracelevel(void)
{
if (debug_backtrace_level < 0) {
debug_backtrace_level = 0;
msg(_("frame is zero"));
msg(_("frame is zero"), 0);
} else {
char *sname = estack_sfile(ESTACK_NONE);
int max = get_maxbacktrace_level(sname);
Expand Down Expand Up @@ -719,7 +719,7 @@ void ex_breakdel(exarg_T *eap)
void ex_breaklist(exarg_T *eap)
{
if (GA_EMPTY(&dbg_breakp)) {
msg(_("No breakpoints defined"));
msg(_("No breakpoints defined"), 0);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/nvim/digraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ static void digraph_header(const char *msg)
if (msg_col > 0) {
msg_putchar('\n');
}
msg_outtrans_attr(msg, HL_ATTR(HLF_CM));
msg_outtrans(msg, HL_ATTR(HLF_CM));
msg_putchar('\n');
}

Expand Down Expand Up @@ -1860,7 +1860,7 @@ static void printdigraph(const digr_T *dp, result_T *previous)
*p++ = (char)dp->char2;
*p++ = ' ';
*p = NUL;
msg_outtrans(buf);
msg_outtrans(buf, 0);
p = buf;

// add a space to draw a composing char on
Expand All @@ -1870,14 +1870,14 @@ static void printdigraph(const digr_T *dp, result_T *previous)
p += utf_char2bytes(dp->result, p);

*p = NUL;
msg_outtrans_attr(buf, HL_ATTR(HLF_8));
msg_outtrans(buf, HL_ATTR(HLF_8));
p = buf;
if (char2cells(dp->result) == 1) {
*p++ = ' ';
}
assert(p >= buf);
vim_snprintf(p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result);
msg_outtrans(buf);
msg_outtrans(buf, 0);
}

/// Get the two digraph characters from a typval.
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3492,7 +3492,7 @@ static bool ins_esc(long *count, int cmdchar, bool nomove)
showmode();
} else if (p_smd && (got_int || !skip_showmode())
&& !(p_ch == 0 && !ui_has(kUIMessages))) {
msg("");
msg("", 0);
}
// Exit Insert mode
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -8018,7 +8018,7 @@ void ex_echo(exarg_T *eap)
char *tofree = encode_tv2echo(&rettv, NULL);
if (*tofree != NUL) {
msg_ext_set_kind("echo");
msg_multiline_attr(tofree, echo_attr, true, &need_clear);
msg_multiline(tofree, echo_attr, true, &need_clear);
}
xfree(tofree);
}
Expand Down Expand Up @@ -8102,7 +8102,7 @@ void ex_execute(exarg_T *eap)

if (eap->cmdidx == CMD_echomsg) {
msg_ext_set_kind("echomsg");
msg_attr(ga.ga_data, echo_attr);
msg(ga.ga_data, echo_attr);
} else if (eap->cmdidx == CMD_echoerr) {
// We don't want to abort following commands, restore did_emsg.
int save_did_emsg = did_emsg;
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/eval/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ static void list_one_var(dictitem_T *v, const char *prefix, int *first)
static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t name_len,
const VarType type, const char *string, int *first)
{
// don't use msg() or msg_attr() to avoid overwriting "v:statusmsg"
// don't use msg() to avoid overwriting "v:statusmsg"
msg_start();
msg_puts(prefix);
if (name != NULL) { // "a:" vars don't have a name stored
Expand All @@ -1378,7 +1378,7 @@ static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t
msg_putchar(' ');
}

msg_outtrans(string);
msg_outtrans(string, 0);

if (type == VAR_FUNC || type == VAR_PARTIAL) {
msg_puts("()");
Expand Down
20 changes: 10 additions & 10 deletions src/nvim/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void do_ascii(const exarg_T *const eap)
int cc[MAX_MCO];
int c = utfc_ptr2char(get_cursor_pos_ptr(), cc);
if (c == NUL) {
msg("NUL");
msg("NUL", 0);
return;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ void do_ascii(const exarg_T *const eap)
xstrlcpy(IObuff + iobuff_len, " ...", sizeof(IObuff) - iobuff_len);
}

msg(IObuff);
msg(IObuff, 0);
}

/// ":left", ":center" and ":right": align text.
Expand Down Expand Up @@ -1062,7 +1062,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out
msg_start();
msg_putchar(':');
msg_putchar('!');
msg_outtrans(newcmd);
msg_outtrans(newcmd, 0);
msg_clr_eos();
ui_cursor_goto(msg_row, msg_col);

Expand Down Expand Up @@ -1274,7 +1274,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b
if (do_in) {
vim_snprintf(msg_buf, sizeof(msg_buf),
_("%" PRId64 " lines filtered"), (int64_t)linecount);
if (msg(msg_buf) && !msg_scroll) {
if (msg(msg_buf, 0) && !msg_scroll) {
// save message to display it after redraw
set_keep_msg(msg_buf, 0);
}
Expand Down Expand Up @@ -4250,7 +4250,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_
}
}
if (cmdpreview_ns <= 0 && !do_sub_msg(subflags.do_count) && subflags.do_ask && p_ch > 0) {
msg("");
msg("", 0);
}
} else {
global_need_beginline = true;
Expand All @@ -4265,7 +4265,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_
} else if (got_match) {
// did find something but nothing substituted
if (p_ch > 0) {
msg("");
msg("", 0);
}
} else if (subflags.do_error) {
// nothing found
Expand Down Expand Up @@ -4339,7 +4339,7 @@ bool do_sub_msg(bool count_only)
vim_snprintf_add(msg_buf, sizeof(msg_buf),
NGETTEXT(msg_single, msg_plural, sub_nlines),
(int64_t)sub_nsubs, (int64_t)sub_nlines);
if (msg(msg_buf)) {
if (msg(msg_buf, 0)) {
// save message to display it after redraw
set_keep_msg(msg_buf, 0);
}
Expand Down Expand Up @@ -4468,7 +4468,7 @@ void ex_global(exarg_T *eap)

// pass 2: execute the command for each line that has been marked
if (got_int) {
msg(_(e_interr));
msg(_(e_interr), 0);
} else if (ndone == 0) {
if (type == 'v') {
smsg(_("Pattern found in every line: %s"), used_pat);
Expand Down Expand Up @@ -4775,7 +4775,7 @@ void ex_oldfiles(exarg_T *eap)
long nr = 0;

if (l == NULL) {
msg(_("No old files"));
msg(_("No old files"), 0);
return;
}

Expand All @@ -4790,7 +4790,7 @@ void ex_oldfiles(exarg_T *eap)
if (!message_filtered(fname)) {
msg_outnum(nr);
msg_puts(": ");
msg_outtrans(tv_get_string(TV_LIST_ITEM_TV(li)));
msg_outtrans(tv_get_string(TV_LIST_ITEM_TV(li)), 0);
msg_clr_eos();
msg_putchar('\n');
os_breakcheck();
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/ex_cmds2.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ int buf_write_all(buf_T *buf, int forceit)
false, forceit, true, false));
if (curbuf != old_curbuf) {
msg_source(HL_ATTR(HLF_W));
msg(_("Warning: Entered other buffer unexpectedly (check autocommands)"));
msg(_("Warning: Entered other buffer unexpectedly (check autocommands)"), 0);
}
return retval;
}
Expand Down

0 comments on commit e46f5aa

Please sign in to comment.