]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1962: filetype: Erlang application resource files are not recognized master v9.1.1962
authorDoug Kearns <dougkearns@gmail.com>
Sun, 7 Dec 2025 18:12:33 +0000 (19:12 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 7 Dec 2025 18:12:33 +0000 (19:12 +0100)
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 <dougkearns@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
runtime/doc/filetype.txt
runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 491521663a11bafe25a875e38ba2b0c856feb9b7..56ac5660621d06fdc12f4b101d4fbca120f09fe5 100644 (file)
@@ -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 <Bram@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") .. '\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()
index 5011b05699ca3a8cc61c421a00765dad66100bdd..8ec0fa43add8e460992c718c6d491d35d06f5788 100644 (file)
@@ -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|
index c733be61fc72a856d08f565bbbc782c07f1331b6..c375db3c51fa9e7357c568d9a9ac2dcd52083d1a 100644 (file)
@@ -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
index 6a6f5053bcffe46434f23a7b5852382126258e19..0681afcd62dcc10798e2cf16b424ac35f9fb6311 100644 (file)
@@ -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
index 9a747725394093390b16ca293a9e3e0303683983..e9ecbef67f30e7a63e0b6c5759a4ac1ff527c0d7 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1962,
 /**/
     1961,
 /**/