aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-09-17 16:56:45 -0400
committerGitHub <noreply@github.com>2026-09-17 16:56:45 -0400
commit6ad6dcd5d4ca2cbe28de8ea5ffe77cfee40a7004 (patch)
tree321be87303392ebcaa9f9f985373c8aa53772fdc /src
parentd1fd8158de63107d2ada9f69c1a491d76edfc9aa (diff)
downloadrneovim-6ad6dcd5d4ca2cbe28de8ea5ffe77cfee40a7004.tar.gz
rneovim-6ad6dcd5d4ca2cbe28de8ea5ffe77cfee40a7004.tar.bz2
rneovim-6ad6dcd5d4ca2cbe28de8ea5ffe77cfee40a7004.zip
fix(filetype): empty 'filetype' skips :setfiletype #41958
Problem: After `:restart` a restored buffer can have an empty 'filetype'. Lazy LSP setup during the read replays FileType via `:doautoall`, which sets `did_filetype` even though `filetype=''`. :e foo.md :restart :set ft? " filetype= Solution: Set `did_filetype` only if 'filetype' is non-empty.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/autocmd.c4
-rw-r--r--src/nvim/eval.lua7
2 files changed, 6 insertions, 5 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 0b529f0757..909c8263bc 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -1710,8 +1710,8 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
filechangeshell_busy = (event == EVENT_FILECHANGEDSHELL);
nesting++; // see matching decrement below
- // Remember that FileType was triggered. Used for did_filetype().
- if (event == EVENT_FILETYPE) {
+ // Remember that FileType was triggered, if 'filetype' was actually set. For :setf.
+ if (event == EVENT_FILETYPE && *curbuf->b_p_ft != NUL) {
curbuf->b_did_filetype = true;
}
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 2e37a8bc76..3e4e535970 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -1952,10 +1952,11 @@ M.funcs = {
did_filetype = {
desc = [=[
Returns |TRUE| when autocommands are being executed and the
- FileType event has been triggered at least once. Can be used
- to avoid triggering the FileType event again in the scripts
- that detect the file type. |FileType|
+ FileType event triggered at least once for a buffer with
+ a non-empty 'filetype'. Can be used to avoid triggering
+ the FileType event again in the |ftdetect| scripts. |FileType|
Returns |FALSE| when `:setf FALLBACK` was used.
+
When editing another file, the counter is reset, thus this
really checks if the FileType event has been triggered for the
current buffer. This allows an autocommand that starts