From 1a06a3948861b11a9bae0b044f0342fc2190584d Mon Sep 17 00:00:00 2001 From: lonerover Date: Tue, 17 Jan 2017 15:36:00 +0800 Subject: vim-patch:7.4.2049 Problem: There is no way to get a list of the error lists. Solution: Add ":chistory" and ":lhistory". https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954 --- src/nvim/ex_cmds.lua | 12 ++++++++++ src/nvim/message.c | 21 +++++++++++++++--- src/nvim/quickfix.c | 45 +++++++++++++++++++++++++++++++++----- src/nvim/testdir/test_quickfix.vim | 24 ++++++++++++++++++++ src/nvim/version.c | 2 +- 5 files changed, 94 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 88095602ba..5f81306fc1 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -461,6 +461,12 @@ return { addr_type=ADDR_LINES, func='ex_checktime', }, + { + command='chistory', + flags=bit.bor(TRLBAR), + addr_type=ADDR_LINES, + func='qf_history', + }, { command='clist', flags=bit.bor(BANG, EXTRA, TRLBAR, CMDWIN), @@ -1399,6 +1405,12 @@ return { addr_type=ADDR_LINES, func='ex_helpgrep', }, + { + command='lhistory', + flags=bit.bor(TRLBAR), + addr_type=ADDR_LINES, + func='qf_history', + }, { command='ll', flags=bit.bor(RANGE, NOTADR, COUNT, TRLBAR, BANG), diff --git a/src/nvim/message.c b/src/nvim/message.c index 2f8feda6ec..749fa8a706 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -297,8 +297,22 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) len += n; } - /* Set the middle and copy the last part. */ - if (e + 3 < buflen) { + if (i <= e + 3) { + // text fits without truncating + if (s != buf) { + len = STRLEN(s); + if (len >= buflen) { + len = buflen - 1; + } + len = len - e + 1; + if (len < 1) { + buf[e - 1] = NUL; + } else { + memmove(buf + e, s + e, len); + } + } + } else if (e + 3 < buflen) { + // set the middle and copy the last part memmove(buf + e, "...", (size_t)3); len = (int)STRLEN(s + i) + 1; if (len >= buflen - e - 3) @@ -306,7 +320,8 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) memmove(buf + e + 3, s + i, len); buf[e + 3 + len - 1] = NUL; } else { - buf[e - 1] = NUL; /* make sure it is truncated */ + // can't fit in the "...", just truncate it + buf[e - 1] = NUL; } } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 33a84660c1..2fa0fb9840 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2105,6 +2105,28 @@ static void qf_fmt_text(char_u *text, char_u *buf, int bufsize) buf[i] = NUL; } +static void qf_msg(qf_info_T *qi, int which, char *lead) +{ + char *title = (char *)qi->qf_lists[which].qf_title; + int count = qi->qf_lists[which].qf_count; + char_u buf[IOSIZE]; + + vim_snprintf((char *)buf, IOSIZE, _("%serror list %d of %d; %d errors "), + lead, + which + 1, + qi->qf_listcount, + count); + + if (title != NULL) { + while (STRLEN(buf) < 34) { + STRCAT(buf, " "); + } + STRCAT(buf, title); + } + trunc_string(buf, buf, Columns - 1, IOSIZE); + msg(buf); +} + /* * ":colder [count]": Up in the quickfix stack. * ":cnewer [count]": Down in the quickfix stack. @@ -2145,15 +2167,26 @@ void qf_age(exarg_T *eap) ++qi->qf_curlist; } } - qf_msg(qi); + qf_msg(qi, qi->qf_curlist, ""); + qf_update_buffer(qi, NULL); } -static void qf_msg(qf_info_T *qi) +void qf_history(exarg_T *eap) { - smsg(_("error list %d of %d; %d errors"), - qi->qf_curlist + 1, qi->qf_listcount, - qi->qf_lists[qi->qf_curlist].qf_count); - qf_update_buffer(qi, NULL); + qf_info_T *qi = &ql_info; + int i; + + if (eap->cmdidx == CMD_lhistory) { + qi = GET_LOC_LIST(curwin); + } + if (qi == NULL || (qi->qf_listcount == 0 + && qi->qf_lists[qi->qf_curlist].qf_count == 0)) { + MSG(_("No entries")); + } else { + for (i = 0; i < qi->qf_listcount; i++) { + qf_msg(qi, i, i == qi->qf_curlist ? "> " : " "); + } + } } /* diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index f30902b915..17f0bde6d3 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1420,3 +1420,27 @@ function Test_cbottom() call XbottomTests('c') call XbottomTests('l') endfunction + +function HistoryTest(cchar) + call s:setup_commands(a:cchar) + + call assert_fails(a:cchar . 'older 99', 'E380:') + " clear all lists after the first one, then replace the first one. + call g:Xsetlist([]) + Xolder + let entry = {'filename': 'foo', 'lnum': 42} + call g:Xsetlist([entry], 'r') + call g:Xsetlist([entry, entry]) + call g:Xsetlist([entry, entry, entry]) + let res = split(execute(a:cchar . 'hist'), "\n") + call assert_equal(3, len(res)) + let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()' + call assert_equal(' error list 1 of 3; 1 ' . common, res[0]) + call assert_equal(' error list 2 of 3; 2 ' . common, res[1]) + call assert_equal('> error list 3 of 3; 3 ' . common, res[2]) +endfunc + +func Test_history() + call HistoryTest('c') + call HistoryTest('l') +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 3dfc32fc6d..98cfdd1b4a 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -391,7 +391,7 @@ static int included_patches[] = { // 2052 NA // 2051, // 2050, - // 2049, + 2049, // 2048 NA // 2047, // 2046, -- cgit From 827f2f9f6b75ba182d27c30a6a056968bed65eaa Mon Sep 17 00:00:00 2001 From: lonerover Date: Tue, 17 Jan 2017 16:33:53 +0800 Subject: vim-patch:7.4.2050 Problem: When using ":vimgrep" may end up with duplicate buffers. Solution: When adding an error list entry pass the buffer number if possible. https://github.com/vim/vim/commit/015102e91e978a0bb42a14461c132a85e8f7e1ea --- src/nvim/quickfix.c | 21 +++++++++++++++------ src/nvim/testdir/test_quickfix.vim | 15 +++++++++++++++ src/nvim/version.c | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 2fa0fb9840..3b5fa67f63 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1282,7 +1282,7 @@ void copy_loclist(win_T *from, win_T *to) to->w_llist->qf_curlist = qi->qf_curlist; /* current list */ } -// Get buffer number for file "dir.name". +// Get buffer number for file "directory.fname". // Also sets the b_has_qf_entry flag. static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname) { @@ -2123,7 +2123,7 @@ static void qf_msg(qf_info_T *qi, int which, char *lead) } STRCAT(buf, title); } - trunc_string(buf, buf, Columns - 1, IOSIZE); + trunc_string(buf, buf, (int)Columns - 1, IOSIZE); msg(buf); } @@ -3484,10 +3484,13 @@ void ex_vimgrep(exarg_T *eap) col = 0; while (vim_regexec_multi(®match, curwin, buf, lnum, col, NULL) > 0) { + // Pass the buffer number so that it gets used even for a + // dummy buffer, unless duplicate_name is set, then the + // buffer will be wiped out below. if (qf_add_entry(qi, NULL, // dir fname, - 0, + duplicate_name ? 0 : buf->b_fnum, ml_get_buf(buf, regmatch.startpos[0].lnum + lnum, false), regmatch.startpos[0].lnum + lnum, @@ -3541,17 +3544,23 @@ void ex_vimgrep(exarg_T *eap) buf = NULL; } else if (buf != first_match_buf || (flags & VGR_NOJUMP)) { unload_dummy_buffer(buf, dirname_start); + // Keeping the buffer, remove the dummy flag. + buf->b_flags &= ~BF_DUMMY; buf = NULL; } } if (buf != NULL) { - /* If the buffer is still loaded we need to use the - * directory we jumped to below. */ + // Keeping the buffer, remove the dummy flag. + buf->b_flags &= ~BF_DUMMY; + + // If the buffer is still loaded we need to use the + // directory we jumped to below. if (buf == first_match_buf && target_dir == NULL - && STRCMP(dirname_start, dirname_now) != 0) + && STRCMP(dirname_start, dirname_now) != 0) { target_dir = vim_strsave(dirname_now); + } /* The buffer is still loaded, the Filetype autocommands * need to be done now, in that buffer. And the modelines diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 17f0bde6d3..008cc6c11b 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1444,3 +1444,18 @@ func Test_history() call HistoryTest('c') call HistoryTest('l') endfunc + +func Test_duplicate_buf() + " make sure we can get the highest buffer number + edit DoesNotExist + edit DoesNotExist2 + let last_buffer = bufnr("$") + + " make sure only one buffer is created + call writefile(['this one', 'that one'], 'Xgrepthis') + vimgrep one Xgrepthis + vimgrep one Xgrepthis + call assert_equal(last_buffer + 1, bufnr("$")) + + call delete('Xgrepthis') +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 98cfdd1b4a..6e94846907 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -390,7 +390,7 @@ static int included_patches[] = { // 2053 NA // 2052 NA // 2051, - // 2050, + 2050, 2049, // 2048 NA // 2047, -- cgit From 480b02fdb2f862d427beee189b82c40aa7bb4174 Mon Sep 17 00:00:00 2001 From: lonerover Date: Wed, 18 Jan 2017 12:04:43 +0800 Subject: vim-patch:7.4.2064 Problem: Coverity warns for possible buffer overflow. Solution: Use vim_strcat() instead of strcat(). https://github.com/vim/vim/commit/4f5c5f29806e53251b7a7b68ce7de86a21ff8015 --- src/nvim/quickfix.c | 2 +- src/nvim/version.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 3b5fa67f63..ca2b356863 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2121,7 +2121,7 @@ static void qf_msg(qf_info_T *qi, int which, char *lead) while (STRLEN(buf) < 34) { STRCAT(buf, " "); } - STRCAT(buf, title); + vim_strcat(buf, title, IOSIZE); } trunc_string(buf, buf, (int)Columns - 1, IOSIZE); msg(buf); diff --git a/src/nvim/version.c b/src/nvim/version.c index 6e94846907..0f0666ddf9 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -376,7 +376,7 @@ static int included_patches[] = { // 2067, 2066, 2065, - // 2064, + 2064, // 2063 NA 2062, // 2061, -- cgit From 86f76108f78ed2b94fb2ddfafcbbb06f396a0b8c Mon Sep 17 00:00:00 2001 From: lonerover Date: Wed, 18 Jan 2017 12:09:20 +0800 Subject: vim-patch:7.4.2067 Problem: Compiler warning for char/char_u conversion. (Tony Mechelynck) Inefficient code. Solution: Use more lines to fill with spaces. (Nikolai Pavlov) Add type cast. https://github.com/vim/vim/commit/16ec3c9be3fcdc38530bddb12978bc5a7b98c0f6 --- src/nvim/quickfix.c | 9 ++++++--- src/nvim/version.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ca2b356863..9a4d413358 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2118,10 +2118,13 @@ static void qf_msg(qf_info_T *qi, int which, char *lead) count); if (title != NULL) { - while (STRLEN(buf) < 34) { - STRCAT(buf, " "); + size_t len = STRLEN(buf); + + if (len < 34) { + memset(buf + len, ' ', 34 - len); + buf[34] = NUL; } - vim_strcat(buf, title, IOSIZE); + vim_strcat(buf, (char_u *)title, IOSIZE); } trunc_string(buf, buf, (int)Columns - 1, IOSIZE); msg(buf); diff --git a/src/nvim/version.c b/src/nvim/version.c index 0f0666ddf9..9f801be548 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -373,7 +373,7 @@ static int included_patches[] = { // 2070 NA // 2069, // 2068, - // 2067, + 2067, 2066, 2065, 2064, -- cgit From 0060974b2bdd28edf9d34a53daa7862ce55b1f43 Mon Sep 17 00:00:00 2001 From: lonerover Date: Wed, 18 Jan 2017 12:13:51 +0800 Subject: vim-patch:7.4.2081 Problem: Line numbers in the error list are not always adjusted. Solution: Set b_has_qf_entry properly. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/c1542744e788d96fed24dd421f43009288092504 --- src/nvim/buffer_defs.h | 5 ++++- src/nvim/quickfix.c | 11 +++++++---- src/nvim/testdir/test_quickfix.vim | 17 ++++++++++------- src/nvim/version.c | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 2b66a07f48..29f4dfe4fb 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -454,6 +454,9 @@ typedef struct { } synblock_T; +#define BUF_HAS_QF_ENTRY 1 +#define BUF_HAS_LL_ENTRY 2 + /* * buffer: structure that holds information about one file * @@ -611,7 +614,7 @@ struct file_buffer { int b_p_bomb; ///< 'bomb' char_u *b_p_bh; ///< 'bufhidden' char_u *b_p_bt; ///< 'buftype' - bool b_has_qf_entry; ///< quickfix exists for buffer + int b_has_qf_entry; ///< quickfix exists for buffer int b_p_bl; ///< 'buflisted' int b_p_cin; ///< 'cindent' char_u *b_p_cino; ///< 'cinoptions' diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 9a4d413358..19287ecffb 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1105,7 +1105,8 @@ static int qf_add_entry(qf_info_T *qi, char_u *dir, char_u *fname, int bufnum, qfp->qf_fnum = bufnum; if (buf != NULL) { - buf->b_has_qf_entry = true; + buf->b_has_qf_entry |= + (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; } } else { qfp->qf_fnum = qf_get_fnum(qi, dir, fname); @@ -1322,7 +1323,8 @@ static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname) if (buf == NULL) { return 0; } - buf->b_has_qf_entry = true; + buf->b_has_qf_entry = + (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; return buf->b_fnum; } @@ -2239,8 +2241,9 @@ void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long int idx; qf_info_T *qi = &ql_info; bool found_one = false; + int buf_has_flag = wp == NULL ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; - if (!curbuf->b_has_qf_entry) { + if (!(curbuf->b_has_qf_entry & buf_has_flag)) { return; } if (wp != NULL) { @@ -2267,7 +2270,7 @@ void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long } if (!found_one) { - curbuf->b_has_qf_entry = false; + curbuf->b_has_qf_entry &= ~buf_has_flag; } } diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 008cc6c11b..7464a11abd 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1299,13 +1299,14 @@ function! Xadjust_qflnum(cchar) enew | only - call s:create_test_file('Xqftestfile') - edit Xqftestfile + let fname = 'Xqftestfile' . a:cchar + call s:create_test_file(fname) + exe 'edit ' . fname - Xgetexpr ['Xqftestfile:5:Line5', - \ 'Xqftestfile:10:Line10', - \ 'Xqftestfile:15:Line15', - \ 'Xqftestfile:20:Line20'] + Xgetexpr [fname . ':5:Line5', + \ fname . ':10:Line10', + \ fname . ':15:Line15', + \ fname . ':20:Line20'] 6,14delete call append(6, ['Buffer', 'Window']) @@ -1317,11 +1318,13 @@ function! Xadjust_qflnum(cchar) call assert_equal(13, l[3].lnum) enew! - call delete('Xqftestfile') + call delete(fname) endfunction function! Test_adjust_lnum() + call setloclist(0, []) call Xadjust_qflnum('c') + call setqflist([]) call Xadjust_qflnum('l') endfunction diff --git a/src/nvim/version.c b/src/nvim/version.c index 9f801be548..3bf87da376 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -359,7 +359,7 @@ static int included_patches[] = { // 2084, // 2083, // 2082, - // 2081, + 2081, // 2080, // 2079 NA // 2078 NA -- cgit