-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The previous work had some problems: * it was working for nvim but not at all for vim. * it did not provide any loop-breaking checks before launching doautocmd * it was setting `filetype` from within the syntax file instead of the ftdetect file. This reworks the code to fix most of the above issues. The changes are almost verbatim what Time Pope wrote for the eruby syntax and ftplugin files in vim/nvim. With the changes, vim now is able to correctly identify the subtype based on the file name's extension prior to .epp. This covers most of the basic cases. However, I was not able to find a good way to solve finding the filetype based on parsing file contents and the paths leading to the file. We don't want to reimplement the whole of builtin file detection, which is why @shadowwa was trying to reuse the autocommands already determined. Until we find a way to fix the above issue, we at least now have most of the filetype detection working, which is better than nothing. NOTE: I'm intentionally keeping the tests that are failing for vim in this commit. This way ppl who will investigate this project in the future will be able to see that the tests actually pass on nvim, but not on vim. The next commit will comment out the failing tests though, since vader.vim still doesn't have a SkipIf instruction. See: junegunn/vader.vim#201
- Loading branch information
Showing
5 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
" vint: -ProhibitAutocmdWithNoGroup | ||
" Vim's own filetypes.vim runs before all ftdetect scripts (why?) and matches | ||
" detects the .pp extension as being a 'pascal' file. Since the script uses | ||
" `setf`, we can nullify the filetype detection by removing all commands bound | ||
" to BufRead and BufNewFile for .pp files with `au!`. Hopefully, if there were | ||
" any other commands set they were associated with the pascal type and we want | ||
" to get rid of them. | ||
" However, this has the effect of completely nullifying pascal type detection | ||
" for .pp files. | ||
au! BufRead,BufNewFile *.pp setfiletype puppet | ||
" Some epp files may get marked as "mason" type before this script is reached. | ||
" Vim's own scripts.vim forces the type if it detects a `<%` at the start of | ||
" the file. All files ending in .epp should be epuppet | ||
if !has('nvim-0.8.0') | ||
autocmd! BufRead,BufNewFile *.epp call DetectOriginalType() | ||
function! DetectOriginalType() | ||
execute 'doautocmd filetypedetect BufRead ' .fnameescape(expand('<afile>:r')) | ||
if &filetype !=# '' && !( &filetype ==# 'mason' && expand('<afile>') !~# 'mason') | ||
let b:original_filetype = &filetype | ||
endif | ||
setlocal filetype=epuppet | ||
endfunction | ||
" Vim has fixed puppet vs pascal detection in patch 8.2.2334 so we can rely on | ||
" their type detection from that point on. | ||
if !has("patch-8.2.2334") && !has("nvim-0.5.0") | ||
" Vim's own filetypes.vim runs before all ftdetect scripts (why?) and matches | ||
" detects the .pp extension as being a 'pascal' file. Since the script uses | ||
" `setf`, we can nullify the filetype detection by removing all commands bound | ||
" to BufRead and BufNewFile for .pp files with `au!`. Hopefully, if there were | ||
" any other commands set they were associated with the pascal type and we want | ||
" to get rid of them. | ||
" However, this has the effect of completely nullifying pascal type detection | ||
" for .pp files. | ||
au! BufRead,BufNewFile *.pp setfiletype puppet | ||
endif | ||
" Vim now has autodetection for epuppet and Puppetfile. We only need to add | ||
" autocommands for older versions of vim / neovim | ||
if !has("patch-8.2.2402") && !has("nvim-0.5.0") | ||
" Some epp files may get marked as "mason" type before this script is reached. | ||
" Vim's own scripts.vim forces the type if it detects a `<%` at the start of | ||
" the file. All files ending in .epp should be epuppet | ||
au! BufRead,BufNewFile *.epp setf epuppet | ||
au BufRead,BufNewFile Puppetfile setfiletype ruby | ||
endif | ||
au BufRead,BufNewFile Puppetfile setfiletype ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters