aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c7
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/ex_docmd.c13
-rw-r--r--src/nvim/globals.h6
-rw-r--r--src/nvim/main.c7
-rw-r--r--src/nvim/option.c30
6 files changed, 52 insertions, 17 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index a28d9774ab..68f6ff303b 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -4533,9 +4533,10 @@ do_arg_all (
use_firstwin = true;
}
- for (i = 0; i < count && i < opened_len && !got_int; ++i) {
- if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1)
- arg_had_last = TRUE;
+ for (i = 0; i < count && i < opened_len && !got_int; i++) {
+ if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1) {
+ arg_had_last = true;
+ }
if (opened[i] > 0) {
/* Move the already present window to below the current window */
if (curwin->w_arg_idx != i) {
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 44560792f0..41a9eeeb40 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -14664,6 +14664,7 @@ static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
static char *e_invact = N_("E927: Invalid action: '%s'");
const char *title = NULL;
int action = ' ';
+ static int recursive = 0;
rettv->vval.v_number = -1;
dict_T *d = NULL;
@@ -14671,6 +14672,9 @@ static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
if (list_arg->v_type != VAR_LIST) {
EMSG(_(e_listreq));
return;
+ } else if (recursive != 0) {
+ EMSG(_(e_au_recursive));
+ return;
}
typval_T *action_arg = &args[1];
@@ -14712,10 +14716,12 @@ skip_args:
title = (wp ? "setloclist()" : "setqflist()");
}
+ recursive++;
list_T *const l = list_arg->vval.v_list;
if (set_errorlist(wp, l, action, (char_u *)title, d) == OK) {
rettv->vval.v_number = 0;
}
+ recursive--;
}
/*
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index ad51de46ee..f8d4e7d980 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6536,6 +6536,13 @@ void alist_expand(int *fnum_list, int fnum_len)
void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum_list, int fnum_len)
{
int i;
+ static int recursive = 0;
+
+ if (recursive) {
+ EMSG(_(e_au_recursive));
+ return;
+ }
+ recursive++;
alist_clear(al);
ga_grow(&al->al_ga, count);
@@ -6560,8 +6567,10 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum
xfree(files);
}
- if (al == &global_alist)
- arg_had_last = FALSE;
+ if (al == &global_alist) {
+ arg_had_last = false;
+ }
+ recursive--;
}
/*
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 9bba2379cd..2dc8073b1e 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -528,8 +528,8 @@ EXTERN buf_T *curbuf INIT(= NULL); // currently active buffer
*/
EXTERN alist_T global_alist; /* global argument list */
EXTERN int max_alist_id INIT(= 0); ///< the previous argument list id
-EXTERN int arg_had_last INIT(= FALSE); /* accessed last file in
- global_alist */
+EXTERN bool arg_had_last INIT(= false); // accessed last file in
+ // global_alist
EXTERN int ru_col; /* column for ruler */
EXTERN int ru_wid; /* 'rulerfmt' width of ruler when non-zero */
@@ -1099,6 +1099,8 @@ EXTERN char_u e_notset[] INIT(= N_("E764: Option '%s' is not set"));
EXTERN char_u e_invalidreg[] INIT(= N_("E850: Invalid register name"));
EXTERN char_u e_dirnotf[] INIT(= N_(
"E919: Directory not found in '%s': \"%s\""));
+EXTERN char_u e_au_recursive[] INIT(= N_(
+ "E952: Autocommand caused recursive behavior"));
EXTERN char_u e_unsupportedoption[] INIT(= N_("E519: Option not supported"));
EXTERN char_u e_fnametoolong[] INIT(= N_("E856: Filename too long"));
EXTERN char_u e_float_as_string[] INIT(= N_("E806: using Float as a String"));
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 4b838a837c..371c8d824e 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1624,9 +1624,10 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
win_close(curwin, true);
advance = false;
}
- if (arg_idx == GARGCOUNT - 1)
- arg_had_last = TRUE;
- ++arg_idx;
+ if (arg_idx == GARGCOUNT - 1) {
+ arg_had_last = true;
+ }
+ arg_idx++;
}
os_breakcheck();
if (got_int) {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index b4ee89d128..eb2780ce7a 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2434,7 +2434,7 @@ did_set_string_option (
int did_chartab = FALSE;
char_u **gvarp;
bool free_oldval = (options[opt_idx].flags & P_ALLOCED);
- int ft_changed = false;
+ bool value_changed = false;
/* Get the global option to compare with, otherwise we would have to check
* two values for all local options. */
@@ -3155,11 +3155,13 @@ did_set_string_option (
if (!valid_filetype(*varp)) {
errmsg = e_invarg;
} else {
- ft_changed = STRCMP(oldval, *varp) != 0;
+ value_changed = STRCMP(oldval, *varp) != 0;
}
} else if (gvarp == &p_syn) {
if (!valid_filetype(*varp)) {
errmsg = e_invarg;
+ } else {
+ value_changed = STRCMP(oldval, *varp) != 0;
}
} else if (varp == &curwin->w_p_winhl) {
if (!parse_winhl_opt(curwin)) {
@@ -3235,14 +3237,28 @@ did_set_string_option (
*/
/* When 'syntax' is set, load the syntax of that name */
if (varp == &(curbuf->b_p_syn)) {
- apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
- curbuf->b_fname, TRUE, curbuf);
+ static int syn_recursive = 0;
+
+ syn_recursive++;
+ // Only pass true for "force" when the value changed or not used
+ // recursively, to avoid endless recurrence.
+ apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
+ value_changed || syn_recursive == 1, curbuf);
+ syn_recursive--;
} else if (varp == &(curbuf->b_p_ft)) {
// 'filetype' is set, trigger the FileType autocommand
- if (!(opt_flags & OPT_MODELINE) || ft_changed) {
+ // Skip this when called from a modeline and the filetype was
+ // already set to this value.
+ if (!(opt_flags & OPT_MODELINE) || value_changed) {
+ static int ft_recursive = 0;
+
+ ft_recursive++;
did_filetype = true;
- apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
- curbuf->b_fname, true, curbuf);
+ // Only pass true for "force" when the value changed or not
+ // used recursively, to avoid endless recurrence.
+ apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
+ value_changed || ft_recursive == 1, curbuf);
+ ft_recursive--;
// Just in case the old "curbuf" is now invalid
if (varp != &(curbuf->b_p_ft)) {
varp = NULL;