aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c9
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/normal.c6
-rw-r--r--src/nvim/ops.c39
-rw-r--r--src/nvim/ops.h7
-rw-r--r--src/nvim/testdir/Makefile3
-rw-r--r--src/nvim/testdir/test_autoformat_join.in23
-rw-r--r--src/nvim/testdir/test_autoformat_join.ok8
-rw-r--r--src/nvim/version.c2
10 files changed, 72 insertions, 29 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 1dcc86b7db..bbb4ea0c03 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -7244,11 +7244,12 @@ static void ins_del(void)
return;
if (gchar_cursor() == NUL) { /* delete newline */
temp = curwin->w_cursor.col;
- if (!can_bs(BS_EOL) /* only if "eol" included */
- || do_join(2, FALSE, TRUE, FALSE) == FAIL)
+ if (!can_bs(BS_EOL) // only if "eol" included
+ || do_join(2, FALSE, TRUE, FALSE, false) == FAIL) {
vim_beep();
- else
+ } else {
curwin->w_cursor.col = temp;
+ }
} else if (del_char(FALSE) == FAIL) /* delete char under cursor */
vim_beep();
did_ai = FALSE;
@@ -7387,7 +7388,7 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
ptr[len - 1] = NUL;
}
- (void)do_join(2, FALSE, FALSE, FALSE);
+ do_join(2, FALSE, FALSE, FALSE, false);
if (temp == NUL && gchar_cursor() != NUL)
inc_cursor();
} else
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index fa17986028..6c297f399b 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3588,7 +3588,7 @@ void do_sub(exarg_T *eap)
eap->flags = EXFLAG_PRINT;
}
- do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE);
+ do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE, true);
sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1;
do_sub_msg(FALSE);
ex_may_print(eap);
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 0ff62a3726..ae55c5b65a 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6804,7 +6804,7 @@ static void ex_join(exarg_T *eap)
}
++eap->line2;
}
- (void)do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE, TRUE);
+ do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE, TRUE, true);
beginline(BL_WHITE | BL_FIX);
ex_may_print(eap);
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index bdd6a2a266..b505c349ae 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -730,7 +730,7 @@ getcount:
}
if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) {
- /* This command is not allowed while editing a ccmdline: beep. */
+ // This command is not allowed while editing a cmdline: beep.
clearopbeep(oap);
text_locked_msg();
goto normal_end;
@@ -1622,7 +1622,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
curbuf->b_ml.ml_line_count)
beep_flush();
else {
- (void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE);
+ do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE, true);
auto_format(FALSE, TRUE);
}
break;
@@ -7326,7 +7326,7 @@ static void nv_join(cmdarg_T *cap)
else {
prep_redo(cap->oap->regname, cap->count0,
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
- (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE);
+ do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, true);
}
}
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index dccc3e6324..05ca402d39 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -1623,8 +1623,9 @@ int op_delete(oparg_T *oap)
);
curwin->w_cursor = curpos; /* restore curwin->w_cursor */
}
- if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
- (void)do_join(2, FALSE, FALSE, FALSE);
+ if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
+ do_join(2, FALSE, FALSE, FALSE, false);
+ }
}
}
@@ -3381,15 +3382,19 @@ static char_u *skip_comment(char_u *line, int process, int include_space, int *i
return line;
}
-/*
- * Join 'count' lines (minimal 2) at cursor position.
- * When "save_undo" is TRUE save lines for undo first.
- * Set "use_formatoptions" to FALSE when e.g. processing
- * backspace and comment leaders should not be removed.
- *
- * return FAIL for failure, OK otherwise
- */
-int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
+// Join 'count' lines (minimal 2) at cursor position.
+// When "save_undo" is TRUE save lines for undo first.
+// Set "use_formatoptions" to FALSE when e.g. processing backspace and comment
+// leaders should not be removed.
+// When setmark is true, sets the '[ and '] mark, else, the caller is expected
+// to set those marks.
+//
+// return FAIL for failure, OK otherwise
+int do_join(long count,
+ int insert_space,
+ int save_undo,
+ int use_formatoptions,
+ bool setmark)
{
char_u *curr = NULL;
char_u *curr_start = NULL;
@@ -3427,7 +3432,7 @@ int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
*/
for (t = 0; t < count; ++t) {
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
- if (t == 0) {
+ if (t == 0 && setmark) {
// Set the '[ mark.
curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum;
curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr);
@@ -3527,9 +3532,11 @@ int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
}
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
- // Set the '] mark.
- curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum;
- curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp);
+ if (setmark) {
+ // Set the '] mark.
+ curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum;
+ curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp);
+ }
/* Only report the change in the first line here, del_lines() will report
* the deleted line. */
@@ -3953,7 +3960,7 @@ format_lines (
}
}
curwin->w_cursor.lnum--;
- if (do_join(2, TRUE, FALSE, FALSE) == FAIL) {
+ if (do_join(2, TRUE, FALSE, FALSE, false) == FAIL) {
beep_flush();
break;
}
diff --git a/src/nvim/ops.h b/src/nvim/ops.h
index 83175eb89d..12dd8351d5 100644
--- a/src/nvim/ops.h
+++ b/src/nvim/ops.h
@@ -40,8 +40,11 @@ void adjust_cursor_eol(void);
int preprocs_left(void);
int get_register_name(int num);
void ex_display(exarg_T *eap);
-int do_join(long count, int insert_space, int save_undo,
- int use_formatoptions);
+int do_join(long count,
+ int insert_space,
+ int save_undo,
+ int use_formatoptions,
+ bool setmark);
void op_format(oparg_T *oap, int keep_cursor);
void op_formatexpr(oparg_T *oap);
int fex_format(linenr_T lnum, long count, int c);
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile
index 2497f8a5ba..5582a9f159 100644
--- a/src/nvim/testdir/Makefile
+++ b/src/nvim/testdir/Makefile
@@ -6,7 +6,8 @@ export SHELL := sh
VIMPROG := ../../../build/bin/nvim
-SCRIPTS := test_eval.out \
+SCRIPTS := test_autoformat_join.out \
+ test_eval.out \
test1.out test2.out test3.out test4.out test5.out \
test6.out test7.out test8.out test9.out test10.out \
test11.out test12.out test13.out test14.out test15.out \
diff --git a/src/nvim/testdir/test_autoformat_join.in b/src/nvim/testdir/test_autoformat_join.in
new file mode 100644
index 0000000000..f1e1c868d3
--- /dev/null
+++ b/src/nvim/testdir/test_autoformat_join.in
@@ -0,0 +1,23 @@
+Tests for setting the '[,'] marks when joining lines.
+
+STARTTEST
+:so small.vim
+:/^\t\t/
+0gqj
+:let a=string(getpos("'[")).'/'.string(getpos("']"))
+:/^This line/;'}-join
+:let b=string(getpos("'[")).'/'.string(getpos("']"))
+:$put ='First test: Start/End '.string(a)
+:$put ='Second test: Start/End '.string(b)
+:/^\t\t/,$wq! test.out
+ENDTEST
+
+
+ O sodales, ludite, vos qui
+attamen consulite per voster honur. Tua pulchra facies me fay planszer milies
+
+This line.
+Should be joined with the next line
+and with this line
+
+Results:
diff --git a/src/nvim/testdir/test_autoformat_join.ok b/src/nvim/testdir/test_autoformat_join.ok
new file mode 100644
index 0000000000..3b1df79514
--- /dev/null
+++ b/src/nvim/testdir/test_autoformat_join.ok
@@ -0,0 +1,8 @@
+ O sodales, ludite, vos qui attamen consulite per voster honur.
+Tua pulchra facies me fay planszer milies
+
+This line. Should be joined with the next line and with this line
+
+Results:
+First test: Start/End '[0, 16, 1, 0]/[0, 17, 1, 0]'
+Second test: Start/End '[0, 19, 11, 0]/[0, 19, 67, 0]'
diff --git a/src/nvim/version.c b/src/nvim/version.c
index eac5854ff0..0b899532e3 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -219,7 +219,7 @@ static int included_patches[] = {
//270,
269,
268,
- //267,
+ 267,
266,
265,
264,