aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/textformat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/textformat.c')
-rw-r--r--src/nvim/textformat.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index bfe3ed5972..c427206764 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -86,8 +86,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
// When 'ai' is off we don't want a space under the cursor to be
// deleted. Replace it with an 'x' temporarily.
- if (!curbuf->b_p_ai
- && !(State & VREPLACE_FLAG)) {
+ if (!curbuf->b_p_ai && !(State & VREPLACE_FLAG)) {
cc = gchar_cursor();
if (ascii_iswhite(cc)) {
save_char = (char)cc;
@@ -158,7 +157,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
}
// find column of textwidth border
- coladvance((colnr_T)textwidth);
+ coladvance(curwin, (colnr_T)textwidth);
wantcol = curwin->w_cursor.col;
// If startcol is large (a long line), formatting takes too much
@@ -446,7 +445,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
// Check if cursor is not past the NUL off the line, cindent
// may have added or removed indent.
curwin->w_cursor.col += startcol;
- colnr_T len = (colnr_T)strlen(get_cursor_line_ptr());
+ colnr_T len = get_cursor_line_len();
if (curwin->w_cursor.col > len) {
curwin->w_cursor.col = len;
}
@@ -507,12 +506,11 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char **leader_flags, bo
static bool ends_in_white(linenr_T lnum)
{
char *s = ml_get(lnum);
- size_t l;
if (*s == NUL) {
return false;
}
- l = strlen(s) - 1;
+ colnr_T l = ml_get_len(lnum) - 1;
return ascii_iswhite((uint8_t)s[l]);
}
@@ -545,7 +543,7 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
return false;
}
if (*p == COM_START) {
- int line_len = (int)strlen(ml_get(lnum));
+ int line_len = ml_get_len(lnum);
if (line_len <= leader1_len) {
return false;
}
@@ -648,7 +646,7 @@ void auto_format(bool trailblank, bool prev_line)
// in 'formatoptions' and there is a single character before the cursor.
// Otherwise the line would be broken and when typing another non-white
// next they are not joined back together.
- int wasatend = (pos.col == (colnr_T)strlen(old));
+ bool wasatend = (pos.col == get_cursor_line_len());
if (*old != NUL && !trailblank && wasatend) {
dec_cursor();
int cc = gchar_cursor();
@@ -691,9 +689,9 @@ void auto_format(bool trailblank, bool prev_line)
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
// "cannot happen"
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- coladvance(MAXCOL);
+ coladvance(curwin, MAXCOL);
} else {
- check_cursor_col();
+ check_cursor_col(curwin);
}
// Insert mode: If the cursor is now after the end of the line while it
@@ -702,7 +700,7 @@ void auto_format(bool trailblank, bool prev_line)
// formatted.
if (!wasatend && has_format_option(FO_WHITE_PAR)) {
char *linep = get_cursor_line_ptr();
- colnr_T len = (colnr_T)strlen(linep);
+ colnr_T len = get_cursor_line_len();
if (curwin->w_cursor.col == len) {
char *plinep = xstrnsave(linep, (size_t)len + 2);
plinep[len] = ' ';
@@ -716,7 +714,7 @@ void auto_format(bool trailblank, bool prev_line)
}
}
- check_cursor();
+ check_cursor(curwin);
}
/// When an extra space was added to continue a paragraph for auto-formatting,
@@ -840,7 +838,7 @@ void op_format(oparg_T *oap, bool keep_cursor)
saved_cursor.lnum = 0;
// formatting may have made the cursor position invalid
- check_cursor();
+ check_cursor(curwin);
}
if (oap->is_VIsual) {
@@ -1064,7 +1062,7 @@ void format_lines(linenr_T line_count, bool avoid_fex)
// put cursor on last non-space
State = MODE_NORMAL; // don't go past end-of-line
- coladvance(MAXCOL);
+ coladvance(curwin, MAXCOL);
while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) {
dec_cursor();
}
@@ -1120,7 +1118,7 @@ void format_lines(linenr_T line_count, bool avoid_fex)
}
first_par_line = false;
// If the line is getting long, format it next time
- if (strlen(get_cursor_line_ptr()) > (size_t)max_len) {
+ if (get_cursor_line_len() > max_len) {
force_format = true;
} else {
force_format = false;