aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorMatthieu Coudron <matthieu.coudron@upmc.fr>2017-03-13 01:54:35 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-03-13 01:54:35 +0100
commit71d4b81b4cca76cf4c60105460e1ecbc09d9e86b (patch)
treeeaced58e79a8aac0fe9d0f240d4eeec340833d78 /src/nvim/ops.c
parentc42aebf23ef051885e9fe2df5842d9209ed89789 (diff)
downloadrneovim-71d4b81b4cca76cf4c60105460e1ecbc09d9e86b.tar.gz
rneovim-71d4b81b4cca76cf4c60105460e1ecbc09d9e86b.tar.bz2
rneovim-71d4b81b4cca76cf4c60105460e1ecbc09d9e86b.zip
vim-patch:8.0.0453 (#6266)
Problem: Adding fold marker creates new comment. Solution: Use an existing comment if possible. (LemonBoy, closes vim/vim#1549) https://github.com/vim/vim/commit/025a6b708a9bff54c73fb9c641b980da19e943a9
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 530193bd41..1e4d392754 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -3438,43 +3438,47 @@ dis_msg (
os_breakcheck();
}
-/*
- * If "process" is TRUE and the line begins with a comment leader (possibly
- * after some white space), return a pointer to the text after it. Put a boolean
- * value indicating whether the line ends with an unclosed comment in
- * "is_comment".
- * line - line to be processed,
- * process - if FALSE, will only check whether the line ends with an unclosed
- * comment,
- * include_space - whether to also skip space following the comment leader,
- * is_comment - will indicate whether the current line ends with an unclosed
- * comment.
- */
-static char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment)
+/// If \p "process" is true and the line begins with a comment leader (possibly
+/// after some white space), return a pointer to the text after it.
+/// Put a boolean value indicating whether the line ends with an unclosed
+/// comment in "is_comment".
+///
+/// @param line - line to be processed
+/// @param process - if false, will only check whether the line ends
+/// with an unclosed comment,
+/// @param include_space - whether to skip space following the comment leader
+/// @param[out] is_comment - whether the current line ends with an unclosed
+/// comment.
+char_u *skip_comment(
+ char_u *line, bool process, bool include_space, bool *is_comment
+)
{
char_u *comment_flags = NULL;
int lead_len;
int leader_offset = get_last_leader_offset(line, &comment_flags);
- *is_comment = FALSE;
+ *is_comment = false;
if (leader_offset != -1) {
/* Let's check whether the line ends with an unclosed comment.
* If the last comment leader has COM_END in flags, there's no comment.
*/
while (*comment_flags) {
if (*comment_flags == COM_END
- || *comment_flags == ':')
+ || *comment_flags == ':') {
break;
- ++comment_flags;
+ }
+ comment_flags++;
+ }
+ if (*comment_flags != COM_END) {
+ *is_comment = true;
}
- if (*comment_flags != COM_END)
- *is_comment = TRUE;
}
- if (process == FALSE)
+ if (process == false) {
return line;
+ }
- lead_len = get_leader_len(line, &comment_flags, FALSE, include_space);
+ lead_len = get_leader_len(line, &comment_flags, false, include_space);
if (lead_len == 0)
return line;
@@ -3496,8 +3500,9 @@ static char_u *skip_comment(char_u *line, int process, int include_space, int *i
* starting with a closing part of a three-part comment. That's good,
* because we don't want to remove those as this would be annoying.
*/
- if (*comment_flags == ':' || *comment_flags == NUL)
+ if (*comment_flags == ':' || *comment_flags == NUL) {
line += lead_len;
+ }
return line;
}
@@ -3531,7 +3536,7 @@ int do_join(size_t count,
int *comments = NULL;
int remove_comments = (use_formatoptions == TRUE)
&& has_format_option(FO_REMOVE_COMS);
- int prev_was_comment;
+ bool prev_was_comment;
if (save_undo && u_save(curwin->w_cursor.lnum - 1,
curwin->w_cursor.lnum + (linenr_T)count) == FAIL) {