mirror of
https://github.com/neovim/neovim.git
synced 2026-03-31 21:02:11 +00:00
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
cf5c255260
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -212,6 +212,7 @@ local extension = {
|
||||
aml = 'aml',
|
||||
run = 'ampl',
|
||||
g4 = 'antlr4',
|
||||
app = detect.app,
|
||||
applescript = 'applescript',
|
||||
scpt = 'applescript',
|
||||
ino = 'arduino',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user