memline: copy in ml_replace() is bool

This commit is contained in:
Jan Edmund Lazo
2018-08-07 12:32:13 -04:00
parent 80df0a8fd2
commit 672449e448
9 changed files with 52 additions and 45 deletions

View File

@@ -1766,8 +1766,8 @@ change_indent (
/* We only put back the new line up to the cursor */ /* We only put back the new line up to the cursor */
new_line[curwin->w_cursor.col] = NUL; new_line[curwin->w_cursor.col] = NUL;
/* Put back original line */ // Put back original line
ml_replace(curwin->w_cursor.lnum, orig_line, FALSE); ml_replace(curwin->w_cursor.lnum, orig_line, false);
curwin->w_cursor.col = orig_col; curwin->w_cursor.col = orig_col;
/* Backspace from cursor to start of line */ /* Backspace from cursor to start of line */
@@ -5770,8 +5770,8 @@ auto_format (
pnew = vim_strnsave(new, len + 2); pnew = vim_strnsave(new, len + 2);
pnew[len] = ' '; pnew[len] = ' ';
pnew[len + 1] = NUL; pnew[len + 1] = NUL;
ml_replace(curwin->w_cursor.lnum, pnew, FALSE); ml_replace(curwin->w_cursor.lnum, pnew, false);
/* remove the space later */ // remove the space later
did_add_space = TRUE; did_add_space = TRUE;
} else } else
/* may remove added space */ /* may remove added space */

View File

@@ -716,11 +716,13 @@ void ex_retab(exarg_T *eap)
memmove(new_line + start_col + len, memmove(new_line + start_col + len,
ptr + col, (size_t)(old_len - col + 1)); ptr + col, (size_t)(old_len - col + 1));
ptr = new_line + start_col; ptr = new_line + start_col;
for (col = 0; col < len; col++) for (col = 0; col < len; col++) {
ptr[col] = (col < num_tabs) ? '\t' : ' '; ptr[col] = (col < num_tabs) ? '\t' : ' ';
ml_replace(lnum, new_line, FALSE); }
if (first_line == 0) ml_replace(lnum, new_line, false);
if (first_line == 0) {
first_line = lnum; first_line = lnum;
}
last_line = lnum; last_line = lnum;
ptr = new_line; ptr = new_line;
col = start_col + len; col = start_col + len;
@@ -3625,7 +3627,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
// before the cursor. // before the cursor.
len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line); len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line);
curwin->w_cursor.col += len_change; curwin->w_cursor.col += len_change;
ml_replace(lnum, new_line, FALSE); ml_replace(lnum, new_line, false);
} }
search_match_lines = regmatch.endpos[0].lnum search_match_lines = regmatch.endpos[0].lnum
@@ -3667,9 +3669,10 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
msg_col = 0; msg_col = 0;
gotocmdline(TRUE); gotocmdline(TRUE);
/* restore the line */ // restore the line
if (orig_line != NULL) if (orig_line != NULL) {
ml_replace(lnum, orig_line, FALSE); ml_replace(lnum, orig_line, false);
}
} }
need_wait_return = FALSE; /* no hit-return prompt */ need_wait_return = FALSE; /* no hit-return prompt */
@@ -3926,9 +3929,10 @@ skip:
prev_matchcol = (colnr_T)STRLEN(sub_firstline) prev_matchcol = (colnr_T)STRLEN(sub_firstline)
- prev_matchcol; - prev_matchcol;
if (u_savesub(lnum) != OK) if (u_savesub(lnum) != OK) {
break; break;
ml_replace(lnum, new_start, TRUE); }
ml_replace(lnum, new_start, true);
if (nmatch_tl > 0) { if (nmatch_tl > 0) {
/* /*

View File

@@ -6100,7 +6100,7 @@ static int open_cmdwin(void)
/* Replace the empty last line with the current command-line and put the /* Replace the empty last line with the current command-line and put the
* cursor there. */ * cursor there. */
ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, true);
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
curwin->w_cursor.col = ccline.cmdpos; curwin->w_cursor.col = ccline.cmdpos;
changed_line_abv_curs(); changed_line_abv_curs();

View File

@@ -1687,7 +1687,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen)
assert(p >= line); assert(p >= line);
memcpy(newline, line, (size_t)(p - line)); memcpy(newline, line, (size_t)(p - line));
STRCPY(newline + (p - line), p + len); STRCPY(newline + (p - line), p + len);
ml_replace(lnum, newline, FALSE); ml_replace(lnum, newline, false);
} }
break; break;
} }

View File

@@ -2378,7 +2378,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
) )
set_keep_msg((char_u *)_(no_lines_msg), 0); set_keep_msg((char_u *)_(no_lines_msg), 0);
i = ml_replace((linenr_T)1, (char_u *)"", TRUE); i = ml_replace((linenr_T)1, (char_u *)"", true);
buf->b_ml.ml_flags |= ML_EMPTY; buf->b_ml.ml_flags |= ML_EMPTY;
return i; return i;

View File

@@ -772,7 +772,7 @@ open_line (
(void)u_save_cursor(); /* errors are ignored! */ (void)u_save_cursor(); /* errors are ignored! */
vr_lines_changed++; vr_lines_changed++;
} }
ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); ml_replace(curwin->w_cursor.lnum, p_extra, true);
changed_bytes(curwin->w_cursor.lnum, 0); changed_bytes(curwin->w_cursor.lnum, 0);
curwin->w_cursor.lnum--; curwin->w_cursor.lnum--;
did_append = FALSE; did_append = FALSE;
@@ -832,12 +832,13 @@ open_line (
if (dir == FORWARD) { if (dir == FORWARD) {
if (trunc_line || (State & INSERT)) { if (trunc_line || (State & INSERT)) {
/* truncate current line at cursor */ // truncate current line at cursor
saved_line[curwin->w_cursor.col] = NUL; saved_line[curwin->w_cursor.col] = NUL;
/* Remove trailing white space, unless OPENLINE_KEEPTRAIL used. */ // Remove trailing white space, unless OPENLINE_KEEPTRAIL used.
if (trunc_line && !(flags & OPENLINE_KEEPTRAIL)) if (trunc_line && !(flags & OPENLINE_KEEPTRAIL)) {
truncate_spaces(saved_line); truncate_spaces(saved_line);
ml_replace(curwin->w_cursor.lnum, saved_line, FALSE); }
ml_replace(curwin->w_cursor.lnum, saved_line, false);
saved_line = NULL; saved_line = NULL;
if (did_append) { if (did_append) {
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
@@ -913,8 +914,8 @@ open_line (
/* Put new line in p_extra */ /* Put new line in p_extra */
p_extra = vim_strsave(get_cursor_line_ptr()); p_extra = vim_strsave(get_cursor_line_ptr());
/* Put back original line */ // Put back original line
ml_replace(curwin->w_cursor.lnum, next_line, FALSE); ml_replace(curwin->w_cursor.lnum, next_line, false);
/* Insert new stuff into line again */ /* Insert new stuff into line again */
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
@@ -1498,8 +1499,8 @@ void ins_char_bytes(char_u *buf, size_t charlen)
p[i] = ' '; p[i] = ' ';
} }
/* Replace the line in the buffer. */ // Replace the line in the buffer.
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
// mark the buffer as changed and prepare for displaying // mark the buffer as changed and prepare for displaying
changed_bytes(lnum, (colnr_T)col); changed_bytes(lnum, (colnr_T)col);
@@ -1549,7 +1550,7 @@ void ins_str(char_u *s)
memmove(newp, oldp, (size_t)col); memmove(newp, oldp, (size_t)col);
memmove(newp + col, s, (size_t)newlen); memmove(newp + col, s, (size_t)newlen);
memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1)); memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
changed_bytes(lnum, col); changed_bytes(lnum, col);
curwin->w_cursor.col += newlen; curwin->w_cursor.col += newlen;
} }
@@ -1667,8 +1668,9 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
memmove(newp, oldp, (size_t)col); memmove(newp, oldp, (size_t)col);
} }
memmove(newp + col, oldp + col + count, (size_t)movelen); memmove(newp + col, oldp + col + count, (size_t)movelen);
if (!was_alloced) if (!was_alloced) {
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
}
/* mark the buffer as changed and prepare for displaying */ /* mark the buffer as changed and prepare for displaying */
changed_bytes(lnum, curwin->w_cursor.col); changed_bytes(lnum, curwin->w_cursor.col);

View File

@@ -466,8 +466,8 @@ static void shift_block(oparg_T *oap, int amount)
memset(newp + verbatim_diff, ' ', fill); memset(newp + verbatim_diff, ' ', fill);
STRMOVE(newp + verbatim_diff + fill, non_white); STRMOVE(newp + verbatim_diff + fill, non_white);
} }
/* replace the line */ // replace the line
ml_replace(curwin->w_cursor.lnum, newp, FALSE); ml_replace(curwin->w_cursor.lnum, newp, false);
changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol);
State = oldstate; State = oldstate;
curwin->w_cursor.col = oldcol; curwin->w_cursor.col = oldcol;
@@ -561,7 +561,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
offset += count; offset += count;
STRMOVE(newp + offset, oldp); STRMOVE(newp + offset, oldp);
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
if (lnum == oap->end.lnum) { if (lnum == oap->end.lnum) {
/* Set "']" mark to the end of the block instead of the end of /* Set "']" mark to the end of the block instead of the end of
@@ -1749,8 +1749,8 @@ int op_replace(oparg_T *oap, int c)
after_p = (char_u *)xmalloc(after_p_len); after_p = (char_u *)xmalloc(after_p_len);
memmove(after_p, oldp, after_p_len); memmove(after_p, oldp, after_p_len);
} }
/* replace the line */ // replace the line
ml_replace(curwin->w_cursor.lnum, newp, FALSE); ml_replace(curwin->w_cursor.lnum, newp, false);
if (after_p != NULL) { if (after_p != NULL) {
ml_append(curwin->w_cursor.lnum++, after_p, (int)after_p_len, false); ml_append(curwin->w_cursor.lnum++, after_p, (int)after_p_len, false);
appended_lines_mark(curwin->w_cursor.lnum, 1L); appended_lines_mark(curwin->w_cursor.lnum, 1L);
@@ -2265,7 +2265,7 @@ int op_change(oparg_T *oap)
offset += ins_len; offset += ins_len;
oldp += bd.textcol; oldp += bd.textcol;
STRMOVE(newp + offset, oldp); STRMOVE(newp + offset, oldp);
ml_replace(linenr, newp, FALSE); ml_replace(linenr, newp, false);
} }
} }
check_cursor(); check_cursor();
@@ -3119,10 +3119,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
ptr += yanklen; ptr += yanklen;
} }
STRMOVE(ptr, oldp + col); STRMOVE(ptr, oldp + col);
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
/* Place cursor on last putted char. */ // Place cursor on last putted char.
if (lnum == curwin->w_cursor.lnum) { if (lnum == curwin->w_cursor.lnum) {
/* make sure curwin->w_virtcol is updated */ // make sure curwin->w_virtcol is updated
changed_cline_bef_curs(); changed_cline_bef_curs();
curwin->w_cursor.col += (colnr_T)(totlen - 1); curwin->w_cursor.col += (colnr_T)(totlen - 1);
} }
@@ -3166,7 +3166,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
memmove(newp, oldp, (size_t)col); memmove(newp, oldp, (size_t)col);
/* append to first line */ /* append to first line */
memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); memmove(newp + col, y_array[0], (size_t)(yanklen + 1));
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, false);
curwin->w_cursor.lnum = lnum; curwin->w_cursor.lnum = lnum;
i = 1; i = 1;
@@ -3695,7 +3695,7 @@ int do_join(size_t count,
curr = skipwhite(curr); curr = skipwhite(curr);
currsize = (int)STRLEN(curr); currsize = (int)STRLEN(curr);
} }
ml_replace(curwin->w_cursor.lnum, newp, FALSE); ml_replace(curwin->w_cursor.lnum, newp, false);
if (setmark) { if (setmark) {
// Set the '] mark. // Set the '] mark.

View File

@@ -2944,7 +2944,7 @@ void spell_suggest(int count)
memmove(p, line, c); memmove(p, line, c);
STRCPY(p + c, stp->st_word); STRCPY(p + c, stp->st_word);
STRCAT(p, sug.su_badptr + stp->st_orglen); STRCAT(p, sug.su_badptr + stp->st_orglen);
ml_replace(curwin->w_cursor.lnum, p, FALSE); ml_replace(curwin->w_cursor.lnum, p, false);
curwin->w_cursor.col = c; curwin->w_cursor.col = c;
// For redo we use a change-word command. // For redo we use a change-word command.
@@ -3062,7 +3062,7 @@ void ex_spellrepall(exarg_T *eap)
memmove(p, line, curwin->w_cursor.col); memmove(p, line, curwin->w_cursor.col);
STRCPY(p + curwin->w_cursor.col, repl_to); STRCPY(p + curwin->w_cursor.col, repl_to);
STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from)); STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
ml_replace(curwin->w_cursor.lnum, p, FALSE); ml_replace(curwin->w_cursor.lnum, p, false);
changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
if (curwin->w_cursor.lnum != prev_lnum) { if (curwin->w_cursor.lnum != prev_lnum) {

View File

@@ -2233,10 +2233,11 @@ static void u_undoredo(int undo, bool do_buf_event)
* If the file is empty, there is an empty line 1 that we * If the file is empty, there is an empty line 1 that we
* should get rid of, by replacing it with the new line * should get rid of, by replacing it with the new line
*/ */
if (empty_buffer && lnum == 0) if (empty_buffer && lnum == 0) {
ml_replace((linenr_T)1, uep->ue_array[i], TRUE); ml_replace((linenr_T)1, uep->ue_array[i], true);
else } else {
ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE); ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE);
}
xfree(uep->ue_array[i]); xfree(uep->ue_array[i]);
} }
xfree((char_u *)uep->ue_array); xfree((char_u *)uep->ue_array);
@@ -2902,7 +2903,7 @@ void u_undoline(void)
curbuf->b_u_line_lnum + 1, (linenr_T)0, FALSE) == FAIL) curbuf->b_u_line_lnum + 1, (linenr_T)0, FALSE) == FAIL)
return; return;
oldp = u_save_line(curbuf->b_u_line_lnum); oldp = u_save_line(curbuf->b_u_line_lnum);
ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, true);
changed_bytes(curbuf->b_u_line_lnum, 0); changed_bytes(curbuf->b_u_line_lnum, 0);
xfree(curbuf->b_u_line_ptr); xfree(curbuf->b_u_line_ptr);
curbuf->b_u_line_ptr = oldp; curbuf->b_u_line_ptr = oldp;