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.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 4af629d091..e30580a748 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -127,13 +127,13 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
// Don't break until after the comment leader
if (do_comments) {
- char_u *line = (char_u *)get_cursor_line_ptr();
- leader_len = get_leader_len((char *)line, NULL, false, true);
+ char *line = get_cursor_line_ptr();
+ leader_len = get_leader_len(line, NULL, false, true);
if (leader_len == 0 && curbuf->b_p_cin) {
// Check for a line comment after code.
- int comment_start = check_linecomment((char *)line);
+ int comment_start = check_linecomment(line);
if (comment_start != MAXCOL) {
- leader_len = get_leader_len((char *)line + comment_start, NULL, false, true);
+ leader_len = get_leader_len(line + comment_start, NULL, false, true);
if (leader_len != 0) {
leader_len += comment_start;
}
@@ -477,25 +477,25 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
/// comment leader changes.
static int fmt_check_par(linenr_T lnum, int *leader_len, char **leader_flags, bool do_comments)
{
- char_u *flags = NULL; // init for GCC
- char_u *ptr;
+ char *flags = NULL; // init for GCC
+ char *ptr;
- ptr = (char_u *)ml_get(lnum);
+ ptr = ml_get(lnum);
if (do_comments) {
- *leader_len = get_leader_len((char *)ptr, leader_flags, false, true);
+ *leader_len = get_leader_len(ptr, leader_flags, false, true);
} else {
*leader_len = 0;
}
if (*leader_len > 0) {
// Search for 'e' flag in comment leader flags.
- flags = (char_u *)(*leader_flags);
+ flags = *leader_flags;
while (*flags && *flags != ':' && *flags != COM_END) {
flags++;
}
}
- return *skipwhite((char *)ptr + *leader_len) == NUL
+ return *skipwhite(ptr + *leader_len) == NUL
|| (*leader_len > 0 && *flags == COM_END)
|| startPS(lnum, NUL, false);
}
@@ -544,7 +544,8 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
return false;
}
if (*p == COM_START) {
- if (*(ml_get(lnum) + leader1_len) == NUL) {
+ int line_len = (int)strlen(ml_get(lnum));
+ if (line_len <= leader1_len) {
return false;
}
if (leader2_flags == NULL || leader2_len == 0) {
@@ -587,7 +588,7 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
/// false when the previous line is in the same paragraph.
static bool paragraph_start(linenr_T lnum)
{
- char_u *p;
+ char *p;
int leader_len = 0; // leader len of current line
char *leader_flags = NULL; // flags for leader of current line
int next_leader_len = 0; // leader len of next line
@@ -596,7 +597,7 @@ static bool paragraph_start(linenr_T lnum)
if (lnum <= 1) {
return true; // start of the file
}
- p = (char_u *)ml_get(lnum - 1);
+ p = ml_get(lnum - 1);
if (*p == NUL) {
return true; // after empty line
}
@@ -735,22 +736,24 @@ void check_auto_format(bool end_insert)
int c = ' ';
int cc;
- if (did_add_space) {
- cc = gchar_cursor();
- if (!WHITECHAR(cc)) {
- // Somehow the space was removed already.
+ if (!did_add_space) {
+ return;
+ }
+
+ cc = gchar_cursor();
+ if (!WHITECHAR(cc)) {
+ // Somehow the space was removed already.
+ did_add_space = false;
+ } else {
+ if (!end_insert) {
+ inc_cursor();
+ c = gchar_cursor();
+ dec_cursor();
+ }
+ if (c != NUL) {
+ // The space is no longer at the end of the line, delete it.
+ del_char(false);
did_add_space = false;
- } else {
- if (!end_insert) {
- inc_cursor();
- c = gchar_cursor();
- dec_cursor();
- }
- if (c != NUL) {
- // The space is no longer at the end of the line, delete it.
- del_char(false);
- did_add_space = false;
- }
}
}
}