move truncate_line

This commit is contained in:
Daniel Hahler 2019-06-10 14:59:32 +02:00
parent 33e6cffb9b
commit be08d52e11
2 changed files with 20 additions and 54 deletions

View File

@ -1749,35 +1749,31 @@ theend:
/* /*
* Delete from cursor to end of line. * Delete from cursor to end of line.
* Caller must have prepared for undo. * Caller must have prepared for undo.
* If "fixpos" is TRUE fix the cursor position when done.
*
* Return FAIL for failure, OK otherwise.
*/ */
int void
truncate_line(int fixpos) truncate_line (
int fixpos /* if TRUE fix the cursor position when done */
)
{ {
char_u *newp; char_u *newp;
linenr_T lnum = curwin->w_cursor.lnum; linenr_T lnum = curwin->w_cursor.lnum;
colnr_T col = curwin->w_cursor.col; colnr_T col = curwin->w_cursor.col;
if (col == 0) if (col == 0) {
newp = vim_strsave((char_u *)""); newp = vim_strsave((char_u *)"");
else } else {
newp = vim_strnsave(ml_get(lnum), col); newp = vim_strnsave(ml_get(lnum), (size_t)col);
}
ml_replace(lnum, newp, false);
if (newp == NULL) /* mark the buffer as changed and prepare for displaying */
return FAIL; changed_bytes(lnum, curwin->w_cursor.col);
ml_replace(lnum, newp, FALSE); /*
* If "fixpos" is TRUE we don't want to end up positioned at the NUL.
// mark the buffer as changed and prepare for displaying */
changed_bytes(lnum, curwin->w_cursor.col); if (fixpos && curwin->w_cursor.col > 0)
--curwin->w_cursor.col;
// If "fixpos" is TRUE we don't want to end up positioned at the NUL.
if (fixpos && curwin->w_cursor.col > 0)
--curwin->w_cursor.col;
return OK;
} }
/* /*

View File

@ -525,36 +525,6 @@ void ins_char(int c)
ins_char_bytes(buf, n); ins_char_bytes(buf, n);
} }
/*
* Delete from cursor to end of line.
* Caller must have prepared for undo.
*/
void
truncate_line (
int fixpos /* if TRUE fix the cursor position when done */
)
{
char_u *newp;
linenr_T lnum = curwin->w_cursor.lnum;
colnr_T col = curwin->w_cursor.col;
if (col == 0) {
newp = vim_strsave((char_u *)"");
} else {
newp = vim_strnsave(ml_get(lnum), (size_t)col);
}
ml_replace(lnum, newp, false);
/* mark the buffer as changed and prepare for displaying */
changed_bytes(lnum, curwin->w_cursor.col);
/*
* If "fixpos" is TRUE we don't want to end up positioned at the NUL.
*/
if (fixpos && curwin->w_cursor.col > 0)
--curwin->w_cursor.col;
}
/* /*
* Delete "nlines" lines at the cursor. * Delete "nlines" lines at the cursor.
* Saves the lines for undo first if "undo" is TRUE. * Saves the lines for undo first if "undo" is TRUE.