Improve filetype setting #319
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
:set filetype
forces a filetype.:setfiletype
only sets a filetype if it didn't already happen earlier due tothe same event.
Current versions of Vim and Neovim have a
$VIMRUNTIME/filetype.vim
that setsthe
rust
filetype for all files with an.rs
extension.This plugin did that with
set filetype=rust
as well. But now, with thefiletype getting set twice,
ftplugin/rust/*
was sourced twice as well.This got fixed in #301 by changing
set filetype=rust
tosetfiletype rust
.But that fix introduced a regression for all older Vim versions. There is still
a lot of Vim 7.4 around and Debian stable still provides Nvim 0.1.7, both being
very old versions.
The
$VIMRUNTIME/filetype.vim
of these old versions set the filetype tohercules
for all.rs
files viasetfiletype hercules
.Now, usually (it also depends on how plugins gets sourced)
filetype.vim
getssourced before any
ftdetect/*
files from plugins. And since autocmds areprocessed in order, Vim would first do
setfiletype hercules
and so anysubsequent
setfiletype rust
fails.The obvious solution: Force the
rust
filetype for all.rs
extensions unlessthe filetype is already set to
rust
.So, we have the filetype setting working again for older versions and also avoid
setting the filetype twice.
Fixes #306
Fixes #318