cespare / vim-toml

Vim syntax for TOML
MIT License
625 stars 40 forks source link

File type not set to TOML if the file being edited contains a comment at the start #48

Closed jase413 closed 4 years ago

jase413 commented 4 years ago

If the TOML file (with extension .toml) contains a comment at the start of the file, Vim sets the filetype to conf. The conf filetype is set in Vim's filetype.vim file. While the ftdetect/toml.vim file is executed after, setf will not overwrite the filetype which Vim has already set.

This was introduced in commit d257faaa32ffee1794038f2342ba315760c33fc2 A possible fix is to use setlocal filetype=toml rather than setf in the au command in ftdetect/toml.vim. That is, revert the aforementioned commit.

cespare commented 4 years ago

Hi @jase413, thanks for the report.

I'm unable to reproduce the issue you describe. For example, if I load this file (named x.toml):

# hello
a = "b"

it loads with filetype toml using Vim 8.1.2389.

Moreover, I re-read the documentation and it seems to me that using setfiletype is the better behavior here. If the user has already set a filetype (and presumably loaded syntax, etc) for the type in question, my plugin shouldn't second-guess that. And when I look at some other language plugins I use, I see them using setfiletype too.


While looking into this, I developed a hypothesis about what you might be seeing. This is wild speculation so maybe this is all wrong.

Is it possible you're using the rust.vim plugin and that you're editing a file named Cargo.toml?

I saw that rust.vim used to set filetype=cfg for its Cargo.toml file. (This is supposed to give a slightly better syntax than whatever vim's default if the user doesn't have any special toml handling.) In March rust.vim fixed their ftdetect to use the setf FALLBACK mechanism for this purpose.

cespare commented 4 years ago

I'm closing this for now, but please leave a comment if you still think this is a problem to be fixed in vim-toml and you have steps to reproduce.

jase413 commented 4 years ago

Upgrading Vim from 8.0 to 8.2 fixed the issue. In version 8.2, Vim's filetype.vim no longer contains the code that caused the issue. It should be noted, for documentation purposes, that filetype was set to conf, not cfg and I was not using rust.vim.

Thanks for responding so promptly to this issue.