TL;DR, I need to reset did_filetype() in the middle of filetype-detection
autocommands. I have a hack that works, but is inefficient (`new |
bdelete`). Is there another way?
---
I am in a unique situation, trying to develop a plugin for Pollen [1]. It
is similar to a pre-processor, so needs to merge the underlying syntax with
it's own.
I think the simplest path forward is a "clever" syntax file that augments
whatever syntax already exists, using, e.g., `set filetype=markdown.pollen`.
The difficult bit so far is filetype-detection. I'm using a trick [2] to
try and get the filetype set. For example, in a directory on the
runtimepath I have ftdetect/pollen.vim with (simplified)
```
function! PollenDetectFiletype(filename) abort
" HACK: new file resets did_filetype()
" ignore old filetype, probably pascal or some junk
new | bdelete
let out_ext = fnamemodify(a:filename, ':r')
" original filetype detection
execute 'doautocmd filetypedetect BufRead' fnameescape(out_ext)
" add pollen at end, taking care to only add it once
let &l:filetype = substitute(&filetype, '\C\.\<pollen\>', '', 'g') .
'.pollen'
endfunction
autocmd BufNewFile,BufRead *.pp call PollenDetectFiletype(expand("<afile>"))
```
When I edit a file `foo.md.pp`, the filetype is `markdown.pollen`. But see
the HACK.
Because the `*.pp` extension causes `setf pascal` to run from
`$VIMRUNTIME`, the `doautocommand` line (which correctly triggers `setf
markdown`, in the example) is effectively neutralized: `did_filetype()` is
still TRUE. My HACK exploits the fact that editing a new file resets the
counter (`:h did_filetype`), but seems grossly inefficient.
[1]
https://docs.racket-lang.org/pollen/File_formats.html#%28part._.Source_formats%29
[2]
https://vi.stackexchange.com/questions/12436/how-to-tell-vim-to-behave-the-same-for-file-extension-in-and-mako
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/9f8e3409-0e98-455f-ad4a-db352ddf4eb1n%40googlegroups.com.