neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2f9f77cd722a9dad71df46f39c71dca88815c290
parent 3afe0c67401b6191aa4ae53cc3b8a4d67b130ecb
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue,  9 Dec 2025 09:08:09 +0800

vim-patch:9.1.1962: filetype: Erlang application resource files are not recognized (#36868)

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: vim/vim#18835
closes:  vim/vim#18842

https://github.com/vim/vim/commit/cf5c25526007a5cc39be317b023f55cb266d5ed2

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
Diffstat:
Mruntime/doc/filetype.txt | 1+
Mruntime/lua/vim/filetype.lua | 1+
Mruntime/lua/vim/filetype/detect.lua | 32++++++++++++++++++++++++++++++++
Mtest/old/testdir/test_filetype.vim | 30++++++++++++++++++++++++++++++
4 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt @@ -136,6 +136,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/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua @@ -212,6 +212,7 @@ local extension = { aml = 'aml', run = 'ampl', g4 = 'antlr4', + app = detect.app, applescript = 'applescript', scpt = 'applescript', ino = 'arduino', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua @@ -30,6 +30,38 @@ local matchregex = vim.filetype._matchregex -- luacheck: push no unused args -- luacheck: push ignore 122 +-- Erlang Application Resource Files (*.app.src is matched by extension) +-- See: https://erlang.org/doc/system/applications +--- @type vim.filetype.mapfn +function M.app(path, bufnr) + if vim.g.filetype_app then + return vim.g.filetype_app + end + for lnum, line in ipairs(getlines(bufnr, 1, 100)) do + -- skip Erlang comments, might be something else + if not findany(line, { '^%s*%%', '^%s*$' }) then + if line:find('^%s*{') then + local name = fn.fnamemodify(path, ':t:r:r') + local lines = vim + .iter(getlines(bufnr, lnum, lnum + 9)) + :filter(function(v) + return not v:find('^%s*%%') + end) + :join(' ') + if + findany(lines, { + [[^%s*{%s*application%s*,%s*']] .. name .. [['%s*,]], + [[^%s*{%s*application%s*,%s*]] .. name .. [[%s*,]], + }) + then + return 'erlang' + end + end + return + end + end +end + -- This function checks for the kind of assembly that is wanted by the user, or -- can be detected from the beginning of the file. --- @type vim.filetype.mapfn diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim @@ -3204,4 +3204,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