mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 01:46:29 +00:00
vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: vim/vim#14183
94b7c3233e
This commit is contained in:
@@ -445,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;
|
||||
}
|
||||
@@ -506,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]);
|
||||
}
|
||||
|
||||
@@ -544,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;
|
||||
}
|
||||
@@ -647,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();
|
||||
@@ -701,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] = ' ';
|
||||
@@ -1119,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;
|
||||
|
Reference in New Issue
Block a user