aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer_defs.h5
-rw-r--r--src/nvim/ex_cmds.lua12
-rw-r--r--src/nvim/message.c21
-rw-r--r--src/nvim/quickfix.c78
-rw-r--r--src/nvim/testdir/test_quickfix.vim56
-rw-r--r--src/nvim/version.c10
6 files changed, 151 insertions, 31 deletions
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/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
@@ -462,6 +462,12 @@ return {
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),
addr_type=ADDR_LINES,
@@ -1400,6 +1406,12 @@ return {
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),
addr_type=ADDR_LINES,
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..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);
@@ -1282,7 +1283,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)
{
@@ -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;
}
@@ -2105,6 +2107,31 @@ 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) {
+ size_t len = STRLEN(buf);
+
+ if (len < 34) {
+ memset(buf + len, ' ', 34 - len);
+ buf[34] = NUL;
+ }
+ vim_strcat(buf, (char_u *)title, IOSIZE);
+ }
+ trunc_string(buf, buf, (int)Columns - 1, IOSIZE);
+ msg(buf);
+}
+
/*
* ":colder [count]": Up in the quickfix stack.
* ":cnewer [count]": Down in the quickfix stack.
@@ -2145,15 +2172,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 ? "> " : " ");
+ }
+ }
}
/*
@@ -2203,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) {
@@ -2231,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;
}
}
@@ -3451,10 +3490,13 @@ void ex_vimgrep(exarg_T *eap)
col = 0;
while (vim_regexec_multi(&regmatch, 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,
@@ -3508,17 +3550,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 f30902b915..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
@@ -1420,3 +1423,42 @@ 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
+
+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 6f519383ec..3d81788a7e 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
@@ -373,10 +373,10 @@ static int included_patches[] = {
// 2070 NA
// 2069,
// 2068,
- // 2067,
+ 2067,
2066,
2065,
- // 2064,
+ 2064,
// 2063 NA
2062,
// 2061,
@@ -390,8 +390,8 @@ static int included_patches[] = {
// 2053 NA
// 2052 NA
// 2051,
- // 2050,
- // 2049,
+ 2050,
+ 2049,
// 2048 NA
// 2047,
// 2046,