aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 85e65f32c2..112f53247c 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3940,34 +3940,30 @@ skip:
if (nmatch == -1)
lnum -= regmatch.startpos[0].lnum;
- // Push the match to preview_lines
- // TODO(KillTheMule): Code duplication at line 3961
- linenr_T match_lines = current_match.end.lnum
- - current_match.start.lnum +1;
- if (preview_lines.subresults.size > 0) {
- linenr_T last_lnum = kv_last(preview_lines.subresults).end.lnum;
- if (last_lnum == current_match.start.lnum) {
- preview_lines.lines_needed += match_lines - 1;
- }
- } else {
- preview_lines.lines_needed += match_lines;
- }
- kv_push(preview_lines.subresults, current_match);
+#define PUSH_PREVIEW_LINES() \
+ do { \
+ linenr_T match_lines = current_match.end.lnum \
+ - current_match.start.lnum +1; \
+ if (preview_lines.subresults.size > 0) { \
+ linenr_T last = kv_last(preview_lines.subresults).end.lnum; \
+ if (last == current_match.start.lnum) { \
+ preview_lines.lines_needed += match_lines - 1; \
+ } \
+ } else { \
+ preview_lines.lines_needed += match_lines; \
+ } \
+ kv_push(preview_lines.subresults, current_match); \
+ } while (0)
+
+ // Push the match to preview_lines.
+ PUSH_PREVIEW_LINES();
+
break;
}
}
- // Push the match to preview_lines
- linenr_T match_lines = current_match.end.lnum
- - current_match.start.lnum +1;
- if (preview_lines.subresults.size > 0) {
- linenr_T last_lnum = kv_last(preview_lines.subresults).end.lnum;
- if (last_lnum == current_match.start.lnum) {
- preview_lines.lines_needed += match_lines - 1;
- }
- } else {
- preview_lines.lines_needed += match_lines;
- }
- kv_push(preview_lines.subresults, current_match);
+ // Push the match to preview_lines.
+ PUSH_PREVIEW_LINES();
+
line_breakcheck();
}
@@ -4061,7 +4057,7 @@ skip:
pre_src_id = bufhl_add_hl(NULL, 0, -1, 0, 0, 0);
}
if (pre_hl_id == 0) {
- pre_hl_id = syn_check_group((char_u *)"Substitute", 13);
+ pre_hl_id = syn_check_group((char_u *)S_LEN("Substitute"));
}
curbuf->b_changed = save_b_changed; // preserve 'modified' during preview
preview_buf = show_sub(eap, old_cursor, &preview_lines,
@@ -4077,6 +4073,7 @@ skip:
return preview_buf;
#undef ADJUST_SUB_FIRSTLNUM
+#undef PUSH_PREVIEW_LINES
} // NOLINT(readability/fn_size)
/*
@@ -6133,7 +6130,6 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
curwin->w_p_fen = false;
if (lines.subresults.size > 0) {
- // Width of the "| lnum|..." column which displays the line numbers.
highest_num_line = kv_last(lines.subresults).end.lnum;
col_width = log10(highest_num_line) + 1 + 3;
}
@@ -6142,9 +6138,9 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
char *str = NULL; // construct the line to show in here
size_t old_line_size = 0;
size_t line_size = 0;
- linenr_T linenr_preview = 0; // # of last line added to preview buffer
- linenr_T linenr_origbuf = 0; // # of last line added to original number
- linenr_T next_linenr = 0; // # of the next line to show for the match
+ linenr_T linenr_preview = 0; // last line added to preview buffer
+ linenr_T linenr_origbuf = 0; // last line added to original buffer
+ linenr_T next_linenr = 0; // next line to show for the match
for (size_t matchidx = 0; matchidx < lines.subresults.size; matchidx++) {
SubResult match = lines.subresults.items[matchidx];
@@ -6172,12 +6168,12 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
if (next_linenr == match.end.lnum) {
p_end.lnum = linenr_preview + 1;
}
- char_u *line;
+ char *line;
if (next_linenr == orig_buf->b_ml.ml_line_count + 1) {
- line = (char_u *)"";
+ line = "";
} else {
- line = ml_get_buf(orig_buf, next_linenr, false);
- line_size = STRLEN(line) + col_width + 1;
+ line = (char *)ml_get_buf(orig_buf, next_linenr, false);
+ line_size = strlen(line) + col_width + 1;
// Reallocate if line not long enough
if (line_size > old_line_size) {