From cc2b9d5dc08cefa0342a25ece71b21d4b4b32e00 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 13 Dec 2014 03:17:11 +0100 Subject: [PATCH] =?utf8?q?updated=20for=20version=207.4.543=20Problem:=20?= =?utf8?q?=20=20=20Since=20patch=207.4.232=20"1,3s/\n//"=20joins=20two=20l?= =?utf8?q?ines=20instead=20of=20three.=20=20=20=20=20=20=20=20=20=20=20=20?= =?utf8?q?=20(Eliseo=20Mart=C3=ADnez)=20=20Issue=20287=20Solution:=20=20?= =?utf8?q?=20Correct=20the=20line=20count.=20(Christian=20Brabandt)=20=20?= =?utf8?q?=20=20=20=20=20=20=20=20=20=20=20Also=20set=20the=20last=20used?= =?utf8?q?=20search=20pattern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/ex_cmds.c | 27 +++++++++++++++++++++++---- src/proto/search.pro | 1 + src/search.c | 3 +-- src/version.c | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 86dab4797..8195eb71b 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -4408,6 +4408,8 @@ do_sub(eap) && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' || *cmd == 'p' || *cmd == '#')))) { + linenr_T joined_lines_count; + curwin->w_cursor.lnum = eap->line1; if (*cmd == 'l') eap->flags = EXFLAG_LIST; @@ -4416,10 +4418,27 @@ do_sub(eap) else if (*cmd == 'p') eap->flags = EXFLAG_PRINT; - (void)do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE, TRUE); - sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1; - (void)do_sub_msg(FALSE); - ex_may_print(eap); + /* The number of lines joined is the number of lines in the range plus + * one. One less when the last line is included. */ + joined_lines_count = eap->line2 - eap->line1 + 1; + if (eap->line2 < curbuf->b_ml.ml_line_count) + ++joined_lines_count; + if (joined_lines_count > 1) + { + (void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE); + sub_nsubs = joined_lines_count - 1; + sub_nlines = 1; + (void)do_sub_msg(FALSE); + ex_may_print(eap); + } + + if (!cmdmod.keeppatterns) + save_re_pat(RE_SUBST, pat, p_magic); +#ifdef FEAT_CMDHIST + /* put pattern in history */ + add_to_history(HIST_SEARCH, pat, TRUE, NUL); +#endif + return; } diff --git a/src/proto/search.pro b/src/proto/search.pro index f94fb69ab..07f608789 100644 --- a/src/proto/search.pro +++ b/src/proto/search.pro @@ -2,6 +2,7 @@ int search_regcomp __ARGS((char_u *pat, int pat_save, int pat_use, int options, regmmatch_T *regmatch)); char_u *get_search_pat __ARGS((void)); char_u *reverse_text __ARGS((char_u *s)); +void save_re_pat __ARGS((int idx, char_u *pat, int magic)); void save_search_patterns __ARGS((void)); void restore_search_patterns __ARGS((void)); void free_search_patterns __ARGS((void)); diff --git a/src/search.c b/src/search.c index 047a73397..b64b8f6ce 100644 --- a/src/search.c +++ b/src/search.c @@ -12,7 +12,6 @@ #include "vim.h" -static void save_re_pat __ARGS((int idx, char_u *pat, int magic)); #ifdef FEAT_EVAL static void set_vv_searchforward __ARGS((void)); static int first_submatch __ARGS((regmmatch_T *rp)); @@ -272,7 +271,7 @@ reverse_text(s) } #endif - static void + void save_re_pat(idx, pat, magic) int idx; char_u *pat; diff --git a/src/version.c b/src/version.c index 3f439802c..fe317d053 100644 --- a/src/version.c +++ b/src/version.c @@ -741,6 +741,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 543, /**/ 542, /**/ -- 2.40.0