From 6ad6dcd5d4ca2cbe28de8ea5ffe77cfee40a7004 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 17 Sep 2026 16:56:45 -0400 Subject: 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. --- runtime/doc/options.txt | 11 ++++++----- runtime/doc/vimfn.txt | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'runtime/doc') diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 5581733fbc..d82b7a2f88 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -462,15 +462,16 @@ reads back as the function (from Lua) or a `""` hint (Vimscript/RPC). Setting the filetype :setf[iletype] [FALLBACK] {filetype} *:setf* *:setfiletype* - Set the 'filetype' option to {filetype}, but only if - not done yet in a sequence of (nested) autocommands. + Set the 'filetype' option to {filetype}, unless it was + already set (non-empty) in a sequence of (nested) + autocommands. This is short for: > :if !did_filetype() : setlocal filetype={filetype} :endif -< This command is used in a filetype.vim file to avoid - setting the 'filetype' option twice, causing different - settings and syntax files to be loaded. +< Used in a filetype.vim file to avoid setting the + 'filetype' option twice, causing different settings + and syntax files to be loaded. When the optional FALLBACK argument is present, a later :setfiletype command will override the diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt index f8e33e6d36..2ad24365fb 100644 --- a/runtime/doc/vimfn.txt +++ b/runtime/doc/vimfn.txt @@ -1743,10 +1743,11 @@ dictwatcherdel({dict}, {pattern}, {callback}) *dictwatcherdel()* did_filetype() *did_filetype()* 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 -- cgit