Sunday, February 26, 2023

Re: Augmenting filetype detection for supplemental types

> Attempting to set multiple filetypes based on something like
>
> autocmd FileType foo if ... | set filetype=foo.bar | endif
>
> seems to have an ordering problem with the FileType autocmd that sets
> 'syntax' -- the "foo.bar" filetype is set, requisite files for "bar" are
> loaded, and then the autocmd waiting on the original expansion of <afile>
> to "foo" runs and effectively resets the syntax.
>
> Is there a way to tack on a supplemental filetype without running into
> this problem? The obvious approach of setting the whole string at once
> works, but that requires duplicating everything that could otherwise
> determine the initial filetype...

It's hard to think of an elegant way to deal with this. Once the
FileType event is triggered, it would normally find all matching
autocommands and execute them. Changing the value halfway makes it
unpredictable, easily leading to weird errors.

One way would be to not change 'filetype' directly but set a timer with
a very short timeout to do it later. This can already be done now, you
can try it out. Obvious disadvantage is that all the
indent/syntax/ftplugin files will be sourced twice.

A specific way to handle this would be to add a FileTypePre event, which
would be triggered first and allow for changing 'filetype'. Hmm,
perhaps we would also need this for the Syntax event?
This would be a very specific solution, do we really need it?

--
hundred-and-one symptoms of being an internet addict:
182. You may not know what is happening in the world, but you know
every bit of net-gossip there is.

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20230226144757.A0DCA1C0B1F%40moolenaar.net.

No comments: