diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-11-24 12:35:21 +0100 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-11-28 20:00:06 +0100 |
commit | 2072fd30580a95d2fbac7939d2779a963f43e005 (patch) | |
tree | c5b8a20fb624033b40f0cdf07b88dc9f0aa07474 | |
parent | 68cee4c28d6c309e18ae35eeba9d5dffaf1078ca (diff) | |
download | rneovim-2072fd30580a95d2fbac7939d2779a963f43e005.tar.gz rneovim-2072fd30580a95d2fbac7939d2779a963f43e005.tar.bz2 rneovim-2072fd30580a95d2fbac7939d2779a963f43e005.zip |
Fix newline substitution.
Problem : Command `s/\n//` is being translated into a call to do_join
with a count of 1. But do_join asserts its precondition count
>= 2, which is causing the program to abort.
Note : This in fact revealed bigger problems: generated join command
line count, as well as reported substitutions/lines were
wrong in several cases, since patch 7.4.232.
See:
[patch] http://markmail.org/message/vo7ruair5raccawp
[issue] https://code.google.com/p/vim/issues/detail?id=287
Solution : - Don't generate join command for single-line-range case.
- Make generated join command include:
* lines in range + 1, when range doesn't end at last line.
* lines in range, when range ends at last line.
- Make reported substitutions/lines always be
number-of-lines-joined - 1.
-rw-r--r-- | src/nvim/ex_cmds.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 556e0c01e3..0829049e4d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3602,8 +3602,13 @@ void do_sub(exarg_T *eap) eap->flags = EXFLAG_PRINT; } - do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE, true); - sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1; + linenr_T joined_lines_count = eap->line2 < curbuf->b_ml.ml_line_count + ? eap->line2 - eap->line1 + 2 + : eap->line2 - eap->line1 + 1; + if (joined_lines_count >= 2) { + do_join(joined_lines_count, FALSE, TRUE, FALSE, true); + } + sub_nlines = sub_nsubs = joined_lines_count - 1; do_sub_msg(false); ex_may_print(eap); |