Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions runtime/autoload/dist/ft.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ export def Check_inp()
endif
enddef

export def FTapp()
if exists("g:filetype_app")
exe "setf " .. g:filetype_app
return
endif
# https://erlang.org/doc/system/applications
const pat = '^\s*{\s*application\s*,\s*\(''\=\)' .. expand("%:t:r:r") .. '\1\s*,'
var line: string
for lnum in range(1, min([line("$"), 100]))
line = getline(lnum)
# skip Erlang comments, might be something else
if line =~ '^\s*%' || line =~ '^\s*$'
continue
elseif line =~ '^\s*{' &&
getline(lnum, lnum + 9)->filter((_, v) => v !~ '^\s*%')->join(' ') =~# pat
setf erlang
return
endif
return
endfor
enddef

# This function checks for the kind of assembly that is wanted by the user, or
# can be detected from the beginning of the file.
export def FTasm()
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/filetype.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ what kind of file it is. This doesn't always work. A number of global
variables can be used to overrule the filetype used for certain extensions:

file name variable ~
*.app g:filetype_app
*.app.src g:filetype_app_src
*.asa g:filetype_asa |ft-aspperl-syntax|
|ft-aspvbs-syntax|
*.asm g:asmsyntax |ft-asm-syntax|
Expand Down
2 changes: 1 addition & 1 deletion runtime/filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ au BufNewFile,BufRead *.e,*.E call dist#ft#FTe()
au BufNewFile,BufRead filter-rules setf elmfilt

" Erlang
au BufNewFile,BufRead *.app.src setf erlang
au BufNewFile,BufRead *.app,*.app.src call dist#ft#FTapp()

" ESMTP rc file
au BufNewFile,BufRead *esmtprc setf esmtprc
Expand Down
35 changes: 34 additions & 1 deletion src/testdir/test_filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def s:GetFilenameChecks(): dict<list<string>>
elsa: ['file.lc'],
elvish: ['file.elv'],
epuppet: ['file.epp'],
erlang: ['file.erl', 'file.hrl', 'file.yaws', 'file.app.src', 'rebar.config'],
erlang: ['file.erl', 'file.hrl', 'file.yaws', 'rebar.config'],
eruby: ['file.erb', 'file.rhtml'],
esdl: ['file.esdl'],
esmtprc: ['anyesmtprc', 'esmtprc', 'some-esmtprc'],
Expand Down Expand Up @@ -3204,4 +3204,37 @@ func Test_m4_format()
filetype off
endfunc

func Test_app_file()
filetype on

for extension in ['app', 'app.src']

call writefile(['% line comment', '{application, xfile,'], $'xfile.{extension}', 'D')
exe $'split xfile.{extension}'
call assert_equal('erlang', &filetype)
bwipe!

call writefile(['% line comment', "{application, 'Xfile',"], $'Xfile.{extension}', 'D')
exe $'split Xfile.{extension}'
call assert_equal('erlang', &filetype)
bwipe!

call writefile([' % line comment',
\ ' ',
\ ' % line comment',
\ ' { ',
\ ' % line comment ',
\ ' application , ',
\ ' % line comment ',
\ ' xfile , '],
\ $'xfile.{extension}', 'D')
exe $'split xfile.{extension}'
call assert_equal('erlang', &filetype)
bwipe!

endfor

filetype off
endfunc

" vim: shiftwidth=2 sts=2 expandtab
Loading