From c6aa475a27e3ed1645446b014c32ebf68d005d49 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 7 Jan 2017 15:39:43 +0100 Subject: [PATCH 1/3] patch 8.0.0148: wrong indent in C preprocessor with line continuation Problem: When a C preprocessor statement has two line continuations the following line does not have the right indent. (Ken Takata) Solution: Add the indent of the previous continuation line. (Hirohito Higashi) --- src/misc1.c | 30 +++++++++++++++++++----------- src/testdir/test3.in | 19 +++++++++++++++++++ src/testdir/test3.ok | 14 ++++++++++++++ src/version.c | 2 ++ 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/misc1.c b/src/misc1.c index 3630d7b3b3..b9bd99716f 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -5422,7 +5422,6 @@ static int skip_label(linenr_T, char_u **pp); static int cin_first_id_amount(void); static int cin_get_equal_amount(linenr_T lnum); static int cin_ispreproc(char_u *); -static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump); static int cin_iscomment(char_u *); static int cin_islinecomment(char_u *); static int cin_isterminated(char_u *, int, int); @@ -6002,13 +6001,18 @@ cin_ispreproc(char_u *s) * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a * continuation line of a preprocessor statement. Decrease "*lnump" to the * start and return the line in "*pp". + * Put the amount of indent in "*amount". */ static int -cin_ispreproc_cont(char_u **pp, linenr_T *lnump) +cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount) { char_u *line = *pp; linenr_T lnum = *lnump; int retval = FALSE; + int candidate_amount = *amount; + + if (*line != NUL && line[STRLEN(line) - 1] == '\\') + candidate_amount = get_indent_lnum(lnum); for (;;) { @@ -6027,6 +6031,8 @@ cin_ispreproc_cont(char_u **pp, linenr_T *lnump) if (lnum != *lnump) *pp = ml_get(*lnump); + if (retval) + *amount = candidate_amount; return retval; } @@ -7390,7 +7396,7 @@ get_c_indent(void) l = skipwhite(ml_get(lnum)); if (cin_nocode(l)) /* skip comment lines */ continue; - if (cin_ispreproc_cont(&l, &lnum)) + if (cin_ispreproc_cont(&l, &lnum, &amount)) continue; /* ignore #define, #if, etc. */ curwin->w_cursor.lnum = lnum; @@ -7803,10 +7809,10 @@ get_c_indent(void) */ if (curwin->w_cursor.lnum <= ourscope) { - /* we reached end of scope: - * if looking for a enum or structure initialization + /* We reached end of scope: + * If looking for a enum or structure initialization * go further back: - * if it is an initializer (enum xxx or xxx =), then + * If it is an initializer (enum xxx or xxx =), then * don't add ind_continuation, otherwise it is a variable * declaration: * int x, @@ -7845,7 +7851,8 @@ get_c_indent(void) /* * Skip preprocessor directives and blank lines. */ - if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) + if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, + &amount)) continue; if (cin_nocode(l)) @@ -7962,7 +7969,8 @@ get_c_indent(void) } /* Skip preprocessor directives and blank lines. */ - if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) + if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, + &amount)) continue; /* Finally the actual check for "namespace". */ @@ -8138,7 +8146,7 @@ get_c_indent(void) * unlocked it) */ l = ml_get_curline(); - if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum) + if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount) || cin_nocode(l)) continue; @@ -8859,7 +8867,7 @@ term_again: /* * Skip preprocessor directives and blank lines. */ - if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) + if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) continue; if (cin_nocode(l)) @@ -8960,7 +8968,7 @@ term_again: { look = ml_get(--curwin->w_cursor.lnum); if (!(cin_nocode(look) || cin_ispreproc_cont( - &look, &curwin->w_cursor.lnum))) + &look, &curwin->w_cursor.lnum, &amount))) break; } if (curwin->w_cursor.lnum > 0 diff --git a/src/testdir/test3.in b/src/testdir/test3.in index 096f15219d..e8648d382c 100644 --- a/src/testdir/test3.in +++ b/src/testdir/test3.in @@ -2317,6 +2317,25 @@ h, i; JSEND +STARTTEST +:set cin cino& +/start of define +=/end of define +ENDTEST + +/* start of define */ +{ +} +#define AAA \ +BBB\ +CCC + +#define CNT \ +1 + \ +2 + \ +4 +/* end of define */ + STARTTEST :g/^STARTTEST/.,/^ENDTEST/d :1;/start of AUTO/,$wq! test.out diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok index 2f9572cc13..cfb519bdf4 100644 --- a/src/testdir/test3.ok +++ b/src/testdir/test3.ok @@ -2080,3 +2080,17 @@ var a, i; JSEND + +/* start of define */ +{ +} +#define AAA \ + BBB\ + CCC + +#define CNT \ + 1 + \ + 2 + \ + 4 +/* end of define */ + diff --git a/src/version.c b/src/version.c index bd0220ff61..b49f01f7f2 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 148, /**/ 147, /**/ From cbd4de44e8d08fba3c09eb40ad6e36e83faf020a Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 7 Jan 2017 16:14:57 +0100 Subject: [PATCH 2/3] patch 8.0.0149: :earlier does not work after reading the undo file Problem: ":earlier" and ":later" do not work after startup or reading the undo file. Solution: Use absolute time stamps instead of relative to the Vim start time. (Christian Brabandt, Pavel Juhas, closes #1300, closes #1254) --- src/testdir/test_undo.vim | 28 ++++++++++++++++++++++++++++ src/undo.c | 8 +++----- src/version.c | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim index fb1cdc836a..f2ac6a8eab 100644 --- a/src/testdir/test_undo.vim +++ b/src/testdir/test_undo.vim @@ -235,3 +235,31 @@ func Test_insert_expr() close! endfunc + +func Test_undofile_earlier() + " Issue #1254 + " create undofile with timestamps older than Vim startup time. + let t0 = localtime() - 43200 + call test_settime(t0) + new Xfile + call feedkeys("ione\", 'xt') + set ul=100 + call test_settime(t0 + 1) + call feedkeys("otwo\", 'xt') + set ul=100 + call test_settime(t0 + 2) + call feedkeys("othree\", 'xt') + set ul=100 + w + wundo Xundofile + bwipe! + " restore normal timestamps. + call test_settime(0) + new Xfile + rundo Xundofile + earlier 1d + call assert_equal('', getline(1)) + bwipe! + call delete('Xfile') + call delete('Xundofile') +endfunc diff --git a/src/undo.c b/src/undo.c index 57c3c2021d..607f35fdd8 100644 --- a/src/undo.c +++ b/src/undo.c @@ -2298,10 +2298,8 @@ undo_time( } else { - /* When doing computations with time_t subtract starttime, because - * time_t converted to a long may result in a wrong number. */ if (dosec) - target = (long)(curbuf->b_u_time_cur - starttime) + step; + target = (long)(curbuf->b_u_time_cur) + step; else if (dofile) { if (step < 0) @@ -2350,7 +2348,7 @@ undo_time( else { if (dosec) - closest = (long)(vim_time() - starttime + 1); + closest = (long)(vim_time() + 1); else if (dofile) closest = curbuf->b_u_save_nr_last + 2; else @@ -2388,7 +2386,7 @@ undo_time( { uhp->uh_walk = mark; if (dosec) - val = (long)(uhp->uh_time - starttime); + val = (long)(uhp->uh_time); else if (dofile) val = uhp->uh_save_nr; else diff --git a/src/version.c b/src/version.c index b49f01f7f2..7b47461cac 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 149, /**/ 148, /**/ From 7069bf18e1b1b7bc7640335e07d1022b5acc9048 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 7 Jan 2017 20:39:53 +0100 Subject: [PATCH 3/3] patch 8.0.0150: completion for :filter does not skip the pattern Problem: When the pattern of :filter does not have a separator then completion of the command fails. Solution: Skip over the pattern. (Ozaki Kiichi, clodes #1299) --- src/ex_docmd.c | 11 ++++++++++- src/testdir/test_filter_cmd.vim | 22 ++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ex_docmd.c b/src/ex_docmd.c index b73eb95c9d..134a488384 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -3871,7 +3871,6 @@ set_one_cmd_context( case CMD_cfdo: case CMD_confirm: case CMD_debug: - case CMD_filter: case CMD_folddoclosed: case CMD_folddoopen: case CMD_hide: @@ -3896,6 +3895,16 @@ set_one_cmd_context( case CMD_windo: return arg; + case CMD_filter: + if (*arg != NUL) + arg = skip_vimgrep_pat(arg, NULL, NULL); + if (arg == NULL || *arg == NUL) + { + xp->xp_context = EXPAND_NOTHING; + return NULL; + } + return skipwhite(arg); + #ifdef FEAT_CMDL_COMPL # ifdef FEAT_SEARCH_EXTRA case CMD_match: diff --git a/src/testdir/test_filter_cmd.vim b/src/testdir/test_filter_cmd.vim index 0bbd905c85..5aa5fa64df 100644 --- a/src/testdir/test_filter_cmd.vim +++ b/src/testdir/test_filter_cmd.vim @@ -52,3 +52,25 @@ func Test_filter_fails() call assert_fails('filter! /pat/', 'E476:') call assert_fails('filter! /pat/ asdf', 'E492:') endfunc + +function s:complete_filter_cmd(filtcmd) + let keystroke = "\\=execute('let cmdline = getcmdline()')\\" + let cmdline = '' + call feedkeys(':' . a:filtcmd . keystroke, 'ntx') + return cmdline +endfunction + +func Test_filter_cmd_completion() + " Do not complete pattern + call assert_equal("filter \t", s:complete_filter_cmd('filter ')) + call assert_equal("filter pat\t", s:complete_filter_cmd('filter pat')) + call assert_equal("filter /pat\t", s:complete_filter_cmd('filter /pat')) + call assert_equal("filter /pat/\t", s:complete_filter_cmd('filter /pat/')) + + " Complete after string pattern + call assert_equal('filter pat print', s:complete_filter_cmd('filter pat pri')) + + " Complete after regexp pattern + call assert_equal('filter /pat/ print', s:complete_filter_cmd('filter /pat/ pri')) + call assert_equal('filter #pat# print', s:complete_filter_cmd('filter #pat# pri')) +endfunc diff --git a/src/version.c b/src/version.c index 7b47461cac..0c16c28977 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 150, /**/ 149, /**/