aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/eval.c22
-rw-r--r--src/nvim/eval/typval.c43
-rw-r--r--src/nvim/eval/typval.h2
-rw-r--r--src/nvim/event/multiqueue.c6
-rw-r--r--src/nvim/event/multiqueue.h2
-rw-r--r--src/nvim/ex_cmds.c30
-rw-r--r--src/nvim/option.c5
-rw-r--r--src/nvim/quickfix.c143
-rw-r--r--src/nvim/testdir/test_autocmd.vim75
-rw-r--r--src/nvim/testdir/test_global.vim4
-rw-r--r--src/nvim/testdir/test_quickfix.vim67
12 files changed, 311 insertions, 90 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 6a50264e0f..0b72dd1885 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5665,7 +5665,7 @@ bool buf_contents_changed(buf_T *buf)
void
wipe_buffer(
buf_T *buf,
- int aucmd // When true trigger autocommands.
+ bool aucmd // When true trigger autocommands.
)
{
if (!aucmd) {
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a3fa9c986f..1b78147ec2 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7200,12 +7200,15 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
r = FAIL;
} else if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) {
char_u *name = arg->vval.v_string;
- if (name != NULL) {
+ if (name == NULL) {
+ r = FAIL;
+ } else if (*name == NUL) {
+ callback->type = kCallbackNone;
+ callback->data.funcref = NULL;
+ } else {
func_ref(name);
callback->data.funcref = vim_strsave(name);
callback->type = kCallbackFuncref;
- } else {
- r = FAIL;
}
} else if (nlua_is_table_from_lua(arg)) {
char_u *name = nlua_register_table_as_callable(arg);
@@ -7216,8 +7219,10 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
} else {
r = FAIL;
}
- } else if (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0) {
+ } else if (arg->v_type == VAR_SPECIAL
+ || (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0)) {
callback->type = kCallbackNone;
+ callback->data.funcref = NULL;
} else {
r = FAIL;
}
@@ -7324,14 +7329,7 @@ void add_timer_info(typval_T *rettv, timer_T *timer)
return;
}
- if (timer->callback.type == kCallbackPartial) {
- di->di_tv.v_type = VAR_PARTIAL;
- di->di_tv.vval.v_partial = timer->callback.data.partial;
- timer->callback.data.partial->pt_refcount++;
- } else if (timer->callback.type == kCallbackFuncref) {
- di->di_tv.v_type = VAR_FUNC;
- di->di_tv.vval.v_string = vim_strsave(timer->callback.data.funcref);
- }
+ callback_put(&timer->callback, &di->di_tv);
}
void add_timer_info_all(typval_T *rettv)
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 61de83fc21..4275ff7c61 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1162,6 +1162,49 @@ void callback_free(Callback *callback)
}
}
callback->type = kCallbackNone;
+ callback->data.funcref = NULL;
+}
+
+/// Copy a callback into a typval_T.
+void callback_put(Callback *cb, typval_T *tv)
+ FUNC_ATTR_NONNULL_ALL
+{
+ switch (cb->type) {
+ case kCallbackPartial:
+ tv->v_type = VAR_PARTIAL;
+ tv->vval.v_partial = cb->data.partial;
+ cb->data.partial->pt_refcount++;
+ break;
+ case kCallbackFuncref:
+ tv->v_type = VAR_FUNC;
+ tv->vval.v_string = vim_strsave(cb->data.funcref);
+ func_ref(cb->data.funcref);
+ break;
+ default:
+ tv->v_type = VAR_SPECIAL;
+ tv->vval.v_special = kSpecialVarNull;
+ break;
+ }
+}
+
+// Copy callback from "src" to "dest", incrementing the refcounts.
+void callback_copy(Callback *dest, Callback *src)
+ FUNC_ATTR_NONNULL_ALL
+{
+ dest->type = src->type;
+ switch (src->type) {
+ case kCallbackPartial:
+ dest->data.partial = src->data.partial;
+ dest->data.partial->pt_refcount++;
+ break;
+ case kCallbackFuncref:
+ dest->data.funcref = vim_strsave(src->data.funcref);
+ func_ref(src->data.funcref);
+ break;
+ default:
+ dest->data.funcref = NULL;
+ break;
+ }
}
/// Remove watcher from a dictionary
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 2b4612016b..050b84efec 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -120,7 +120,7 @@ typedef enum {
VAR_DICT, ///< Dictionary, .v_dict is used.
VAR_FLOAT, ///< Floating-point value, .v_float is used.
VAR_BOOL, ///< true, false
- VAR_SPECIAL, ///< Special value (true, false, null), .v_special
+ VAR_SPECIAL, ///< Special value (null), .v_special
///< is used.
VAR_PARTIAL, ///< Partial, .v_partial is used.
} VarType;
diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c
index 1e6d62135c..f534fc483f 100644
--- a/src/nvim/event/multiqueue.c
+++ b/src/nvim/event/multiqueue.c
@@ -73,7 +73,7 @@ struct multiqueue_item {
struct multiqueue {
MultiQueue *parent;
QUEUE headtail; // circularly-linked
- put_callback put_cb;
+ PutCallback put_cb;
void *data;
size_t size;
};
@@ -91,7 +91,7 @@ typedef struct {
static Event NILEVENT = { .handler = NULL, .argv = {NULL} };
-MultiQueue *multiqueue_new_parent(put_callback put_cb, void *data)
+MultiQueue *multiqueue_new_parent(PutCallback put_cb, void *data)
{
return multiqueue_new(NULL, put_cb, data);
}
@@ -104,7 +104,7 @@ MultiQueue *multiqueue_new_child(MultiQueue *parent)
return multiqueue_new(parent, NULL, NULL);
}
-static MultiQueue *multiqueue_new(MultiQueue *parent, put_callback put_cb,
+static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb,
void *data)
{
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h
index a688107665..dc60fbb4c7 100644
--- a/src/nvim/event/multiqueue.h
+++ b/src/nvim/event/multiqueue.h
@@ -7,7 +7,7 @@
#include "nvim/lib/queue.h"
typedef struct multiqueue MultiQueue;
-typedef void (*put_callback)(MultiQueue *multiq, void *data);
+typedef void (*PutCallback)(MultiQueue *multiq, void *data);
#define multiqueue_put(q, h, ...) \
multiqueue_put_event(q, event_create(h, __VA_ARGS__));
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 6a0a08eee8..c399d47b7e 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3344,6 +3344,15 @@ static char_u *sub_parse_flags(char_u *cmd, subflags_T *subflags,
return cmd;
}
+static int check_regexp_delim(int c)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ if (isalpha(c)) {
+ EMSG(_("E146: Regular expressions can't be delimited by letters"));
+ return FAIL;
+ }
+ return OK;
+}
/// Perform a substitution from line eap->line1 to line eap->line2 using the
/// command pointed to by eap->arg which should be of the form:
@@ -3408,16 +3417,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
/* new pattern and substitution */
if (eap->cmd[0] == 's' && *cmd != NUL && !ascii_iswhite(*cmd)
&& vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) {
- /* don't accept alphanumeric for separator */
- if (isalpha(*cmd)) {
- EMSG(_("E146: Regular expressions can't be delimited by letters"));
+ // don't accept alphanumeric for separator
+ if (check_regexp_delim(*cmd) == FAIL) {
return NULL;
}
- /*
- * undocumented vi feature:
- * "\/sub/" and "\?sub?" use last used search pattern (almost like
- * //sub/r). "\&sub&" use last substitute pattern (like //sub/).
- */
+
+ // undocumented vi feature:
+ // "\/sub/" and "\?sub?" use last used search pattern (almost like
+ // //sub/r). "\&sub&" use last substitute pattern (like //sub/).
if (*cmd == '\\') {
++cmd;
if (vim_strchr((char_u *)"/?&", *cmd) == NULL) {
@@ -4455,6 +4462,8 @@ void ex_global(exarg_T *eap)
} else if (*cmd == NUL) {
EMSG(_("E148: Regular expression missing from global"));
return;
+ } else if (check_regexp_delim(*cmd) == FAIL) {
+ return;
} else {
delim = *cmd; /* get the delimiter */
if (delim)
@@ -4773,8 +4782,9 @@ void ex_help(exarg_T *eap)
* window. */
if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) {
buf = buflist_findnr(empty_fnum);
- if (buf != NULL && buf->b_nwindows == 0)
- wipe_buffer(buf, TRUE);
+ if (buf != NULL && buf->b_nwindows == 0) {
+ wipe_buffer(buf, true);
+ }
}
/* keep the previous alternate file */
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 57b8fe1a2e..f57abe89cc 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -85,6 +85,7 @@
#include "nvim/api/private/helpers.h"
#include "nvim/os/input.h"
#include "nvim/os/lang.h"
+#include "nvim/quickfix.h"
/*
* The options that are local to a window or buffer have "indir" set to one of
@@ -3182,6 +3183,10 @@ ambw_end:
}
}
}
+ } else if (varp == &p_qftf) {
+ if (!qf_process_qftf_option()) {
+ errmsg = e_invarg;
+ }
} else {
// Options that are a list of flags.
p = NULL;
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 1a9bbe26f0..3e8d623ed4 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -100,7 +100,7 @@ typedef struct qf_list_S {
char_u *qf_title; ///< title derived from the command that created
///< the error list or set by setqflist
typval_T *qf_ctx; ///< context set by setqflist/setloclist
- char_u *qf_qftf; ///< 'quickfixtextfunc' setting for this list
+ Callback qftf_cb; ///< 'quickfixtextfunc' callback function
struct dir_stack_T *qf_dir_stack;
char_u *qf_directory;
@@ -541,6 +541,9 @@ static int efm_to_regpat(const char_u *efm, int len, efm_T *fmt_ptr,
static efm_T *fmt_start = NULL; // cached across qf_parse_line() calls
+// callback function for 'quickfixtextfunc'
+static Callback qftf_cb;
+
static void free_efm_list(efm_T **efm_first)
{
for (efm_T *efm_ptr = *efm_first; efm_ptr != NULL; efm_ptr = *efm_first) {
@@ -1978,7 +1981,7 @@ static int copy_loclist_entries(const qf_list_T *from_qfl, qf_list_T *to_qfl)
}
/// Copy the specified location list 'from_qfl' to 'to_qfl'.
-static int copy_loclist(const qf_list_T *from_qfl, qf_list_T *to_qfl)
+static int copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl)
FUNC_ATTR_NONNULL_ALL
{
// Some of the fields are populated by qf_add_entry()
@@ -2000,11 +2003,7 @@ static int copy_loclist(const qf_list_T *from_qfl, qf_list_T *to_qfl)
} else {
to_qfl->qf_ctx = NULL;
}
- if (from_qfl->qf_qftf != NULL) {
- to_qfl->qf_qftf = vim_strsave(from_qfl->qf_qftf);
- } else {
- to_qfl->qf_qftf = NULL;
- }
+ callback_copy(&to_qfl->qftf_cb, &from_qfl->qftf_cb);
if (from_qfl->qf_count) {
if (copy_loclist_entries(from_qfl, to_qfl) == FAIL) {
@@ -3385,7 +3384,7 @@ static void qf_free(qf_list_T *qfl)
XFREE_CLEAR(qfl->qf_title);
tv_free(qfl->qf_ctx);
qfl->qf_ctx = NULL;
- XFREE_CLEAR(qfl->qf_qftf);
+ callback_free(&qfl->qftf_cb);
qfl->qf_id = 0;
qfl->qf_changedtick = 0L;
}
@@ -3860,6 +3859,41 @@ static buf_T *qf_find_buf(qf_info_T *qi)
return NULL;
}
+// Process the 'quickfixtextfunc' option value.
+bool qf_process_qftf_option(void)
+{
+ typval_T *tv;
+ Callback cb;
+
+ if (p_qftf == NULL || *p_qftf == NUL) {
+ callback_free(&qftf_cb);
+ return true;
+ }
+
+ if (*p_qftf == '{') {
+ // Lambda expression
+ tv = eval_expr(p_qftf);
+ if (tv == NULL) {
+ return false;
+ }
+ } else {
+ // treat everything else as a function name string
+ tv = xcalloc(1, sizeof(*tv));
+ tv->v_type = VAR_STRING;
+ tv->vval.v_string = vim_strsave(p_qftf);
+ }
+
+ if (!callback_from_typval(&cb, tv)) {
+ tv_free(tv);
+ return false;
+ }
+
+ callback_free(&qftf_cb);
+ qftf_cb = cb;
+ tv_free(tv);
+ return true;
+}
+
/// Update the w:quickfix_title variable in the quickfix/location list window in
/// all the tab pages.
static void qf_update_win_titlevar(qf_info_T *qi)
@@ -3928,7 +3962,9 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum,
int len;
buf_T *errbuf;
- if (qftf_str != NULL) {
+ // If the 'quickfixtextfunc' function returned an non-empty custom string
+ // for this entry, then use it.
+ if (qftf_str != NULL && *qftf_str != NUL) {
STRLCPY(IObuff, qftf_str, IOSIZE);
} else {
if (qfp->qf_module != NULL) {
@@ -3997,22 +4033,25 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum,
return OK;
}
+// Call the 'quickfixtextfunc' function to get the list of lines to display in
+// the quickfix window for the entries 'start_idx' to 'end_idx'.
static list_T *call_qftf_func(qf_list_T *qfl,
int qf_winid,
long start_idx,
long end_idx)
{
- char_u *qftf = p_qftf;
+ Callback *cb = &qftf_cb;
list_T *qftf_list = NULL;
// If 'quickfixtextfunc' is set, then use the user-supplied function to get
// the text to display. Use the local value of 'quickfixtextfunc' if it is
// set.
- if (qfl->qf_qftf != NULL) {
- qftf = qfl->qf_qftf;
+ if (qfl->qftf_cb.type != kCallbackNone) {
+ cb = &qfl->qftf_cb;
}
- if (qftf != NULL && *qftf != NUL) {
+ if (cb != NULL && cb->type != kCallbackNone) {
typval_T args[1];
+ typval_T rettv;
// create the dict argument
dict_T *const dict = tv_dict_alloc_lock(VAR_FIXED);
@@ -4026,8 +4065,16 @@ static list_T *call_qftf_func(qf_list_T *qfl,
args[0].v_type = VAR_DICT;
args[0].vval.v_dict = dict;
- qftf_list = call_func_retlist(qftf, 1, args);
- dict->dv_refcount--;
+ qftf_list = NULL;
+
+ if (callback_call(cb, 1, args, &rettv)) {
+ if (rettv.v_type == VAR_LIST) {
+ qftf_list = rettv.vval.v_list;
+ tv_list_ref(qftf_list);
+ }
+ tv_clear(&rettv);
+ }
+ tv_dict_unref(dict);
}
return qftf_list;
@@ -4064,6 +4111,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last,
if (qfl != NULL) {
char_u dirname[MAXPATHL];
int prev_bufnr = -1;
+ bool invalid_val = false;
*dirname = NUL;
@@ -4086,10 +4134,15 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last,
while (lnum < qfl->qf_count) {
char_u *qftf_str = NULL;
- if (qftf_li != NULL) {
- // Use the text supplied by the user defined function
- qftf_str = (char_u *)tv_get_string_chk(TV_LIST_ITEM_TV(qftf_li));
+ // Use the text supplied by the user defined function (if any).
+ // If the returned value is not string, then ignore the rest
+ // of the returned values and use the default.
+ if (qftf_li != NULL && !invalid_val) {
+ qftf_str = (char_u *)tv_get_string_chk(TV_LIST_ITEM_TV(qftf_li));
+ if (qftf_str == NULL) {
+ invalid_val = true;
}
+ }
if (qf_buf_add_line(qfl, buf, lnum, qfp, dirname, qftf_str,
prev_bufnr != qfp->qf_fnum) == FAIL) {
@@ -5660,7 +5713,7 @@ static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start)
// work when got_int is set.
enter_cleanup(&cs);
- wipe_buffer(buf, FALSE);
+ wipe_buffer(buf, true);
// Restore the error/interrupt/exception state if not discarded by a
// new aborting error, interrupt, or uncaught exception.
@@ -5796,7 +5849,9 @@ enum {
QF_GETLIST_SIZE = 0x80,
QF_GETLIST_TICK = 0x100,
QF_GETLIST_FILEWINID = 0x200,
- QF_GETLIST_ALL = 0x3FF,
+ QF_GETLIST_QFBUFNR = 0x400,
+ QF_GETLIST_QFTF = 0x800,
+ QF_GETLIST_ALL = 0xFFF,
};
/// Parse text from 'di' and return the quickfix list items.
@@ -5894,6 +5949,9 @@ static int qf_getprop_keys2flags(const dict_T *what, bool loclist)
if (loclist && tv_dict_find(what, S_LEN("filewinid")) != NULL) {
flags |= QF_GETLIST_FILEWINID;
}
+ if (tv_dict_find(what, S_LEN("quickfixtextfunc")) != NULL) {
+ flags |= QF_GETLIST_QFTF;
+ }
return flags;
}
@@ -5985,6 +6043,9 @@ static int qf_getprop_defaults(qf_info_T *qi,
if ((status == OK) && locstack && (flags & QF_GETLIST_FILEWINID)) {
status = tv_dict_add_nr(retdict, S_LEN("filewinid"), 0);
}
+ if ((status == OK) && (flags & QF_GETLIST_QFTF)) {
+ status = tv_dict_add_str(retdict, S_LEN("quickfixtextfunc"), "");
+ }
return status;
}
@@ -6060,6 +6121,26 @@ static int qf_getprop_idx(qf_list_T *qfl, int eidx, dict_T *retdict)
return tv_dict_add_nr(retdict, S_LEN("idx"), eidx);
}
+/// Return the 'quickfixtextfunc' function of a quickfix/location list
+/// @return OK or FAIL
+static int qf_getprop_qftf(qf_list_T *qfl, dict_T *retdict)
+ FUNC_ATTR_NONNULL_ALL
+{
+ int status;
+
+ if (qfl->qftf_cb.type != kCallbackNone) {
+ typval_T tv;
+
+ callback_put(&qfl->qftf_cb, &tv);
+ status = tv_dict_add_tv(retdict, S_LEN("quickfixtextfunc"), &tv);
+ tv_clear(&tv);
+ } else {
+ status = tv_dict_add_str(retdict, S_LEN("quickfixtextfunc"), "");
+ }
+
+ return status;
+}
+
/// Return quickfix/location list details (title) as a dictionary.
/// 'what' contains the details to return. If 'list_idx' is -1,
/// then current list is used. Otherwise the specified list is used.
@@ -6133,19 +6214,25 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID)) {
status = qf_getprop_filewinid(wp, qi, retdict);
}
+ if ((status == OK) && (flags & QF_GETLIST_QFTF)) {
+ status = qf_getprop_qftf(qfl, retdict);
+ }
return status;
}
/// Set the current index in the specified quickfix list
-static int qf_setprop_qftf(qf_info_T *qi, qf_list_T *qfl,
- dictitem_T *di)
+/// @return OK
+static int qf_setprop_qftf(qf_list_T *qfl, dictitem_T *di)
+ FUNC_ATTR_NONNULL_ALL
{
- XFREE_CLEAR(qfl->qf_qftf);
- if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) {
- qfl->qf_qftf = vim_strsave(di->di_tv.vval.v_string);
- }
- return OK;
+ Callback cb;
+
+ callback_free(&qfl->qftf_cb);
+ if (callback_from_typval(&cb, &di->di_tv)) {
+ qfl->qftf_cb = cb;
+ }
+ return OK;
}
/// Add a new quickfix entry to list at 'qf_idx' in the stack 'qi' from the
@@ -6514,7 +6601,7 @@ static int qf_set_properties(qf_info_T *qi, const dict_T *what, int action,
retval = qf_setprop_curidx(qi, qfl, di);
}
if ((di = tv_dict_find(what, S_LEN("quickfixtextfunc"))) != NULL) {
- retval = qf_setprop_qftf(qi, qfl, di);
+ retval = qf_setprop_qftf(qfl, di);
}
if (newlist || retval == OK) {
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index bb84fa498e..ad28118f16 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -108,19 +108,19 @@ func Test_bufunload()
autocmd BufWipeout * call add(s:li, "bufwipeout")
augroup END
- let s:li=[]
+ let s:li = []
new
setlocal bufhidden=
bunload
call assert_equal(["bufunload", "bufdelete"], s:li)
- let s:li=[]
+ let s:li = []
new
setlocal bufhidden=delete
bunload
call assert_equal(["bufunload", "bufdelete"], s:li)
- let s:li=[]
+ let s:li = []
new
setlocal bufhidden=unload
bwipeout
@@ -196,6 +196,29 @@ func Test_autocmd_bufunload_avoiding_SEGV_02()
bwipe! a.txt
endfunc
+func Test_autocmd_dummy_wipeout()
+ " prepare files
+ call writefile([''], 'Xdummywipetest1.txt')
+ call writefile([''], 'Xdummywipetest2.txt')
+ augroup test_bufunload_group
+ autocmd!
+ autocmd BufUnload * call add(s:li, "bufunload")
+ autocmd BufDelete * call add(s:li, "bufdelete")
+ autocmd BufWipeout * call add(s:li, "bufwipeout")
+ augroup END
+
+ let s:li = []
+ split Xdummywipetest1.txt
+ silent! vimgrep /notmatched/ Xdummywipetest*
+ call assert_equal(["bufunload", "bufwipeout"], s:li)
+
+ bwipeout
+ call delete('Xdummywipetest1.txt')
+ call delete('Xdummywipetest2.txt')
+ au! test_bufunload_group
+ augroup! test_bufunload_group
+endfunc
+
func Test_win_tab_autocmd()
let g:record = []
@@ -428,7 +451,7 @@ func Test_autocmd_bufwipe_in_SessLoadPost()
let content =<< trim [CODE]
set nocp noswapfile
- let v:swapchoice="e"
+ let v:swapchoice = "e"
augroup test_autocmd_sessionload
autocmd!
autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"
@@ -537,92 +560,92 @@ func Test_OptionSet()
au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>"))
" 1: Setting number option"
- let g:options=[['number', 0, 1, 'global']]
+ let g:options = [['number', 0, 1, 'global']]
set nu
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 2: Setting local number option"
- let g:options=[['number', 1, 0, 'local']]
+ let g:options = [['number', 1, 0, 'local']]
setlocal nonu
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 3: Setting global number option"
- let g:options=[['number', 1, 0, 'global']]
+ let g:options = [['number', 1, 0, 'global']]
setglobal nonu
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 4: Setting local autoindent option"
- let g:options=[['autoindent', 0, 1, 'local']]
+ let g:options = [['autoindent', 0, 1, 'local']]
setlocal ai
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 5: Setting global autoindent option"
- let g:options=[['autoindent', 0, 1, 'global']]
+ let g:options = [['autoindent', 0, 1, 'global']]
setglobal ai
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 6: Setting global autoindent option"
- let g:options=[['autoindent', 1, 0, 'global']]
+ let g:options = [['autoindent', 1, 0, 'global']]
set ai!
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" Should not print anything, use :noa
" 7: don't trigger OptionSet"
- let g:options=[['invalid', 1, 1, 'invalid']]
+ let g:options = [['invalid', 1, 1, 'invalid']]
noa set nonu
call assert_equal([['invalid', 1, 1, 'invalid']], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 8: Setting several global list and number option"
- let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']]
+ let g:options = [['list', 0, 1, 'global'], ['number', 0, 1, 'global']]
set list nu
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 9: don't trigger OptionSet"
- let g:options=[['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']]
+ let g:options = [['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']]
noa set nolist nonu
call assert_equal([['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 10: Setting global acd"
- let g:options=[['autochdir', 0, 1, 'local']]
+ let g:options = [['autochdir', 0, 1, 'local']]
setlocal acd
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 11: Setting global autoread (also sets local value)"
- let g:options=[['autoread', 0, 1, 'global']]
+ let g:options = [['autoread', 0, 1, 'global']]
set ar
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 12: Setting local autoread"
- let g:options=[['autoread', 1, 1, 'local']]
+ let g:options = [['autoread', 1, 1, 'local']]
setlocal ar
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 13: Setting global autoread"
- let g:options=[['autoread', 1, 0, 'global']]
+ let g:options = [['autoread', 1, 0, 'global']]
setglobal invar
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 14: Setting option backspace through :let"
- let g:options=[['backspace', '', 'eol,indent,start', 'global']]
- let &bs="eol,indent,start"
+ let g:options = [['backspace', '', 'eol,indent,start', 'global']]
+ let &bs = "eol,indent,start"
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 15: Setting option backspace through setbufvar()"
- let g:options=[['backup', 0, 1, 'local']]
+ let g:options = [['backup', 0, 1, 'local']]
" try twice, first time, shouldn't trigger because option name is invalid,
" second time, it should trigger
call assert_fails("call setbufvar(1, '&l:bk', 1)", "E355")
@@ -632,13 +655,13 @@ func Test_OptionSet()
call assert_equal(g:opt[0], g:opt[1])
" 16: Setting number option using setwinvar"
- let g:options=[['number', 0, 1, 'local']]
+ let g:options = [['number', 0, 1, 'local']]
call setwinvar(0, '&number', 1)
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 17: Setting key option, shouldn't trigger"
- let g:options=[['key', 'invalid', 'invalid1', 'invalid']]
+ let g:options = [['key', 'invalid', 'invalid1', 'invalid']]
setlocal key=blah
setlocal key=
call assert_equal([['key', 'invalid', 'invalid1', 'invalid']], g:options)
@@ -646,13 +669,13 @@ func Test_OptionSet()
" 18: Setting string option"
let oldval = &tags
- let g:options=[['tags', oldval, 'tagpath', 'global']]
+ let g:options = [['tags', oldval, 'tagpath', 'global']]
set tags=tagpath
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 1l: Resetting string option"
- let g:options=[['tags', 'tagpath', oldval, 'global']]
+ let g:options = [['tags', 'tagpath', oldval, 'global']]
set tags&
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
@@ -672,7 +695,7 @@ func Test_OptionSet_diffmode()
call test_override('starting', 1)
" 18: Changing an option when entering diff mode
new
- au OptionSet diff :let &l:cul=v:option_new
+ au OptionSet diff :let &l:cul = v:option_new
call setline(1, ['buffer 1', 'line2', 'line3', 'line4'])
call assert_equal(0, &l:cul)
@@ -1754,7 +1777,7 @@ func Test_autocmd_CmdWinEnter()
autocmd CmdWinEnter * quit
let winnr = winnr('$')
END
- let filename='XCmdWinEnter'
+ let filename = 'XCmdWinEnter'
call writefile(lines, filename)
let buf = RunVimInTerminal('-S '.filename, #{rows: 6})
diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim
index 2de2c412de..8edc9c2608 100644
--- a/src/nvim/testdir/test_global.vim
+++ b/src/nvim/testdir/test_global.vim
@@ -36,4 +36,8 @@ func Test_global_error()
call assert_fails('g/\(/y', 'E476:')
endfunc
+func Test_wrong_delimiter()
+ call assert_fails('g x^bxd', 'E146:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim
index 14240f0d5f..c63613ab1b 100644
--- a/src/nvim/testdir/test_quickfix.vim
+++ b/src/nvim/testdir/test_quickfix.vim
@@ -3483,12 +3483,13 @@ func Xgetlist_empty_tests(cchar)
if a:cchar == 'c'
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
\ 'items' : [], 'nr' : 0, 'size' : 0,
- \ 'title' : '', 'winid' : 0, 'changedtick': 0},
- \ g:Xgetlist({'all' : 0}))
+ \ 'title' : '', 'winid' : 0, 'changedtick': 0,
+ \ 'quickfixtextfunc' : ''}, g:Xgetlist({'all' : 0}))
else
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
\ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
- \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0},
+ \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
+ \ 'quickfixtextfunc' : ''},
\ g:Xgetlist({'all' : 0}))
endif
@@ -3526,11 +3527,13 @@ func Xgetlist_empty_tests(cchar)
if a:cchar == 'c'
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
+ \ 'quickfixtextfunc' : '',
\ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
else
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
- \ 'changedtick' : 0, 'filewinid' : 0},
+ \ 'changedtick' : 0, 'filewinid' : 0,
+ \ 'quickfixtextfunc' : ''},
\ g:Xgetlist({'id' : qfid, 'all' : 0}))
endif
@@ -3547,12 +3550,13 @@ func Xgetlist_empty_tests(cchar)
if a:cchar == 'c'
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
- \ 'changedtick' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0}))
+ \ 'changedtick' : 0,
+ \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0}))
else
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
- \ 'changedtick' : 0, 'filewinid' : 0},
- \ g:Xgetlist({'nr' : 5, 'all' : 0}))
+ \ 'changedtick' : 0, 'filewinid' : 0,
+ \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0}))
endif
endfunc
@@ -4994,6 +4998,9 @@ func Xtest_qftextfunc(cchar)
set efm=%f:%l:%c:%m
set quickfixtextfunc=Tqfexpr
+ call assert_equal('Tqfexpr', &quickfixtextfunc)
+ call assert_equal('',
+ \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc)
Xexpr ['F1:10:2:green', 'F1:20:4:blue']
Xwindow
call assert_equal('F1-L10C2-green', getline(1))
@@ -5030,12 +5037,15 @@ func Xtest_qftextfunc(cchar)
call assert_equal('Line 10, Col 2', getline(1))
call assert_equal('Line 20, Col 4', getline(2))
Xclose
+ call assert_equal(function('PerQfText'),
+ \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc)
" Add entries to the list when the quickfix buffer is hidden
Xaddexpr ['F1:30:6:red']
Xwindow
call assert_equal('Line 30, Col 6', getline(3))
Xclose
call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''})
+ call assert_equal('', g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc)
set quickfixtextfunc&
delfunc PerQfText
@@ -5074,12 +5084,53 @@ func Xtest_qftextfunc(cchar)
" \ 'E730:')
Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']
call assert_fails('Xwindow', 'E730:')
- call assert_equal(['one', 'F1|20 col 4| blue', 'two'], getline(1, '$'))
+ call assert_equal(['one', 'F1|20 col 4| blue', 'F1|30 col 6| red'],
+ \ getline(1, '$'))
Xclose
set quickfixtextfunc&
delfunc Xqftext
delfunc Xqftext2
+
+ " set the global option to a lambda function
+ set quickfixtextfunc={d\ ->\ map(g:Xgetlist({'id'\ :\ d.id,\ 'items'\ :\ 1}).items[d.start_idx-1:d.end_idx-1],\ 'v:val.text')}
+ Xexpr ['F1:10:2:green', 'F1:20:4:blue']
+ Xwindow
+ call assert_equal(['green', 'blue'], getline(1, '$'))
+ Xclose
+ call assert_equal("{d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1], 'v:val.text')}", &quickfixtextfunc)
+ set quickfixtextfunc&
+
+ " use a lambda function that returns an empty list
+ set quickfixtextfunc={d\ ->\ []}
+ Xexpr ['F1:10:2:green', 'F1:20:4:blue']
+ Xwindow
+ call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'],
+ \ getline(1, '$'))
+ Xclose
+ set quickfixtextfunc&
+
+ " use a lambda function that returns a list with empty strings
+ set quickfixtextfunc={d\ ->\ ['',\ '']}
+ Xexpr ['F1:10:2:green', 'F1:20:4:blue']
+ Xwindow
+ call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'],
+ \ getline(1, '$'))
+ Xclose
+ set quickfixtextfunc&
+
+ " set the per-quickfix list text function to a lambda function
+ call g:Xsetlist([], ' ',
+ \ {'quickfixtextfunc' :
+ \ {d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1],
+ \ "'Line ' .. v:val.lnum .. ', Col ' .. v:val.col")}})
+ Xaddexpr ['F1:10:2:green', 'F1:20:4:blue']
+ Xwindow
+ call assert_equal('Line 10, Col 2', getline(1))
+ call assert_equal('Line 20, Col 4', getline(2))
+ Xclose
+ call assert_match("function('<lambda>\\d\\+')", string(g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc))
+ call g:Xsetlist([], 'f')
endfunc
func Test_qftextfunc()