Commit: patch 9.1.1962: filetype: Erlang application resource files are not recognized

1 view
Skip to first unread message

Christian Brabandt

unread,
Dec 7, 2025, 1:30:44 PM (2 days ago) Dec 7
to vim...@googlegroups.com
patch 9.1.1962: filetype: Erlang application resource files are not recognized

Commit: https://github.com/vim/vim/commit/cf5c25526007a5cc39be317b023f55cb266d5ed2
Author: Doug Kearns <dougk...@gmail.com>
Date: Sun Dec 7 19:12:33 2025 +0100

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 <dougk...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 491521663..56ac56606 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 <https://github.com/vim/vim>
-# Last Change: 2025 Nov 30
+# Last Change: 2025 Dec 07
# Former Maintainer: Bram Moolenaar <Br...@vim.org>

# 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") .. ' \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 5011b0569..8ec0fa43a 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 c733be61f..c375db3c5 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 6a6f5053b..0681afcd6 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 9a7477253..e9ecbef67 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,
/**/
Reply all
Reply to author
Forward
0 new messages