Pregunta:
Estoy tratando de configurar la sintaxis de los archivos de procesamiento (* .pde) en java
con un ftplugin.
.vim/
after/
ftdetect/
pde.vim
ftplugin/
processing.vim
En after/ftdetect/pde.vim
detecto el tipo de archivo:
autocmd BufNewFile,BufReadPost *.pde set filetype=processing
En after/ftplugin/processing.vim
configuré la sintaxis.
setlocal syntax=java
Cuando abro file.pde
:set ft?
dice processing
. Sin embargo :set syntax?
también da processing
!
Me aseguré de que ftplugin on
esté configurado, y la configuración de otras opciones (como, por ejemplo, tabstop=4
) surte efecto.
Además :scriptnames
da ~/.vim/after/ftplugin/processing.vim
como última entrada.
¿Alguien tiene una idea de lo que va mal?
Respuesta:
No está claro por qué está utilizando el directorio after
. De :help after-directory
:
5. In the "after" directory in your home directory. This is for
personal preferences to overrule or add to the distributed defaults
or system-wide settings (rarely needed).
Entonces, a menos que esté sobrescribiendo las preferencias de ftplugin
de un complemento, debe usar el .vim/ftplugin/processing.vim
. Para obtener más información, consulte :help filetype-plugin
y :help write-filetype-plugin
.
La detección del tipo de archivo también se puede realizar sin el after
, como se explica en :help new-filetype
. Una de las formas recomendadas de usar filetype.vim
:
C. If your file type can be detected by the file name.
1. Create your user runtime directory. You would normally use the first
item of the 'runtimepath' option. Example for Unix: >
:!mkdir ~/.vim
2. Create a file that contains autocommands to detect the file type.
Example: >
" my filetype file
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au! BufRead,BufNewFile *.mine setfiletype mine
au! BufRead,BufNewFile *.xyz setfiletype drawing
augroup END
Write this file as "filetype.vim" in your user runtime directory. For
example, for Unix: >
:w ~/.vim/filetype.vim
Editar:
Moví ftdetect y ftplugin de ~ / .vim / after / a ~ / .vim / pero no cambia nada.
De hecho, lo probé aquí con los mismos resultados. Como se sugiere en los comentarios :verbose set syntax?
mostró al culpable:
" Set up the connection between FileType and Syntax autocommands.
" This makes the syntax automatically set when the file type is detected.
augroup syntaxset
au! FileType * exe "set syntax=" . expand("<amatch>")
augroup END
De :help FileType
:
FileType When the 'filetype' option has been set. (...)
Entonces, a pesar de que configuró la sintaxis correctamente, después de que se ftplugin
su ftplugin
el autocmd anterior lo sobrescribe.
Como está en los archivos de tiempo de ejecución de Vim, no debería cambiarlo. Entonces, una opción sería establecer el tipo de archivo en java, y en el ftplugin
java verifique la extensión del archivo (por ejemplo: usando expand("%:e")
) y establezca las opciones pde en lugar de las opciones java.
Otro enfoque sería retrasar la configuración de la sintaxis hasta que finalice el tipo de archivo:
" ~/.vim/ftplugin/pde.vim
if exists("b:did_ftplugin")
finish
endif
augroup pdeSyntax
au!
autocmd Syntax <buffer> call SetPdeSyntax()
augroup END
function! SetPdeSyntax()
" remove the augroup
au! pdeSyntax
set syntax=java
endfunction