From: Doug Kearns Date: Sun, 7 Dec 2025 18:12:33 +0000 (+0100) Subject: patch 9.1.1962: filetype: Erlang application resource files are not recognized X-Git-Tag: v9.1.1962^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fvim.git patch 9.1.1962: filetype: Erlang application resource files are not recognized Problem: filetype: Erlang application resource files are not recognized Solution: Add content-based filetype detection for application resource files matching extension '*.app' (Doug Kearns) related: #18835 closes: #18842 Signed-off-by: Doug Kearns Signed-off-by: Christian Brabandt --- diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim index 491521663a..56ac566062 100644 --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -3,7 +3,7 @@ vim9script # Vim functions for file type detection # # Maintainer: The Vim Project -# Last Change: 2025 Nov 30 +# Last Change: 2025 Dec 07 # Former Maintainer: Bram Moolenaar # These functions are moved here from runtime/filetype.vim to make startup @@ -29,6 +29,28 @@ export def Check_inp() endif enddef +# Erlang Application Resource Files (*.app.src is matched by extension) +# See: https://erlang.org/doc/system/applications +export def FTapp() + if exists("g:filetype_app") + exe "setf " .. g:filetype_app + return + endif + 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 + 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() diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 5011b05699..8ec0fa43ad 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 9.1. Last change: 2025 Nov 09 +*filetype.txt* For Vim version 9.1. Last change: 2025 Dec 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -138,6 +138,7 @@ 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 *.asa g:filetype_asa |ft-aspperl-syntax| |ft-aspvbs-syntax| *.asm g:asmsyntax |ft-asm-syntax| diff --git a/runtime/filetype.vim b/runtime/filetype.vim index c733be61fc..c375db3c51 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -427,8 +427,9 @@ au BufNewFile,BufRead *.e,*.E call dist#ft#FTe() " Elm Filter Rules file au BufNewFile,BufRead filter-rules setf elmfilt -" Erlang +" Erlang Application Resource Files au BufNewFile,BufRead *.app.src setf erlang +au BufNewFile,BufRead *.app call dist#ft#FTapp() " ESMTP rc file au BufNewFile,BufRead *esmtprc setf esmtprc diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index 6a6f5053bc..0681afcd62 100644 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -3248,4 +3248,34 @@ func Test_m4_format() filetype off endfunc +" Erlang Application Resource File +func Test_app_file() + filetype on + + call writefile(['% line comment', '{application, xfile1,'], 'xfile1.app', 'D') + split xfile1.app + call assert_equal('erlang', &filetype) + bwipe! + + call writefile(['% line comment', "{application, 'Xfile2',"], 'Xfile2.app', 'D') + split Xfile2.app + call assert_equal('erlang', &filetype) + bwipe! + + call writefile([' % line comment', + \ ' ', + \ ' % line comment', + \ ' { ', + \ ' % line comment ', + \ ' application , ', + \ ' % line comment ', + \ ' xfile3 , '], + \ 'xfile3.app', 'D') + split xfile3.app + call assert_equal('erlang', &filetype) + bwipe! + + filetype off +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 9a74772539..e9ecbef67f 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1962, /**/ 1961, /**/