aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/textformat.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-14 13:35:04 +0800
committerGitHub <noreply@github.com>2024-03-14 13:35:04 +0800
commit274e414c94a74c7f90952327f69a8a1d65e9f00a (patch)
tree132b06712a25cc34f93883a9ea63c26b4ce4bf45 /src/nvim/textformat.c
parent3502aa63f0f4ea8d8982aea81a819424e71029bc (diff)
parent61b48e91b941258e6945e3eafadc777dccef5b75 (diff)
downloadrneovim-274e414c94a74c7f90952327f69a8a1d65e9f00a.tar.gz
rneovim-274e414c94a74c7f90952327f69a8a1d65e9f00a.tar.bz2
rneovim-274e414c94a74c7f90952327f69a8a1d65e9f00a.zip
Merge pull request #27850 from zeertzjq/vim-9.1.0172
vim-patch:9.1.{0172,0177}: more code can use ml_get_buf_len()
Diffstat (limited to 'src/nvim/textformat.c')
-rw-r--r--src/nvim/textformat.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 41fb543994..c427206764 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -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;