diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-03-29 19:54:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-29 19:54:12 +0100 |
commit | 8b7fb668e440f7793564b764bc9a691e3f45382a (patch) | |
tree | 36f9cbea1440cc8b42b436e36aeb471220793bc9 /src/nvim/autocmd.c | |
parent | 92005db76039094d4a7180c1398b43c06940a1a1 (diff) | |
download | rneovim-8b7fb668e440f7793564b764bc9a691e3f45382a.tar.gz rneovim-8b7fb668e440f7793564b764bc9a691e3f45382a.tar.bz2 rneovim-8b7fb668e440f7793564b764bc9a691e3f45382a.zip |
fix(filetype): avoid recursive FileType autocmds (#22813)
Diffstat (limited to 'src/nvim/autocmd.c')
-rw-r--r-- | src/nvim/autocmd.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index c66ee4286e..b488dd9f8f 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2758,3 +2758,32 @@ void do_autocmd_focusgained(bool gained) recursive = false; } + +void do_filetype_autocmd(buf_T *buf, bool force) +{ + static bool recursive = false; + + if (recursive && !force) { + return; // disallow recursion + } + + char **varp = &buf->b_p_ft; + int secure_save = secure; + + // Reset the secure flag, since the value of 'filetype' has + // been checked to be safe. + secure = 0; + + recursive = true; + did_filetype = true; + // Only pass true for "force" when it is true or + // used recursively, to avoid endless recurrence. + apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, force, buf); + recursive = false; + + // Just in case the old "buf" is now invalid + if (varp != &(buf->b_p_ft)) { + varp = NULL; + } + secure = secure_save; +} |