patch 9.1.1687: filetype: autoconf filetype not always correct
Problem: filetype: autoconf filetype not always correct
Solution: Detect aclocal.m4 as config filetype, detect configure.ac as
config filetype, fall back to POSIX m4 (Damien Lejay).
closes: #18065
Signed-off-by: Damien Lejay <damien@lejay.be>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
3571388ded
commit
2b55474f0a
46
runtime/autoload/dist/ft.vim
vendored
46
runtime/autoload/dist/ft.vim
vendored
@ -3,7 +3,7 @@ vim9script
|
||||
# Vim functions for file type detection
|
||||
#
|
||||
# Maintainer: The Vim Project <https://github.com/vim/vim>
|
||||
# Last Change: 2025 Jul 09
|
||||
# Last Change: 2025 Aug 26
|
||||
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||
|
||||
# These functions are moved here from runtime/filetype.vim to make startup
|
||||
@ -599,6 +599,50 @@ export def FTm()
|
||||
endif
|
||||
enddef
|
||||
|
||||
# For files ending in *.m4, distinguish:
|
||||
# – *.html.m4 files
|
||||
# – files in the Autoconf M4 dialect
|
||||
# – files in POSIX M4
|
||||
export def FTm4()
|
||||
var fname = expand('%:t')
|
||||
var path = expand('%:p:h')
|
||||
|
||||
# Case 0: canonical Autoconf file
|
||||
if fname ==# 'aclocal.m4'
|
||||
setf config
|
||||
return
|
||||
endif
|
||||
|
||||
# Case 1: html.m4
|
||||
if fname =~# 'html\.m4$'
|
||||
setf htmlm4
|
||||
return
|
||||
endif
|
||||
|
||||
# Case 2: repo heuristic (nearby configure.ac)
|
||||
if filereadable(path .. '/../configure.ac') || filereadable(path .. '/configure.ac')
|
||||
setf config
|
||||
return
|
||||
endif
|
||||
|
||||
# Case 3: content heuristic (scan first ~200 lines)
|
||||
# Signals:
|
||||
# - Autoconf macro prefixes: AC_/AM_/AS_/AU_/AT_
|
||||
var n = 1
|
||||
var max = min([200, line('$')])
|
||||
while n <= max
|
||||
var line = getline(n)
|
||||
if line =~# '^\s*A[CMSUT]_'
|
||||
setf config
|
||||
return
|
||||
endif
|
||||
n += 1
|
||||
endwhile
|
||||
|
||||
# Case 4: default to POSIX M4
|
||||
setf m4
|
||||
enddef
|
||||
|
||||
export def FTmake()
|
||||
# Check if it is a BSD, GNU, or Microsoft Makefile
|
||||
unlet! b:make_flavor
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
" Vim support file to detect file types
|
||||
"
|
||||
" Maintainer: The Vim Project <https://github.com/vim/vim>
|
||||
" Last Change: 2025 Aug 10
|
||||
" Last Change: 2025 Aug 26
|
||||
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||
|
||||
" Listen very carefully, I will say this only once
|
||||
@ -219,8 +219,8 @@ au BufNewFile,BufRead *.au3 setf autoit
|
||||
" Autohotkey
|
||||
au BufNewFile,BufRead *.ahk setf autohotkey
|
||||
|
||||
" Autotest .at files are actually m4
|
||||
au BufNewFile,BufRead *.at setf m4
|
||||
" Autotest .at files are actually Autoconf M4
|
||||
au BufNewFile,BufRead *.at setf config
|
||||
|
||||
" Avenue
|
||||
au BufNewFile,BufRead *.ave setf ave
|
||||
@ -1157,9 +1157,6 @@ au BufNewFile,BufRead *.http setf http
|
||||
" HTML with Ruby - eRuby
|
||||
au BufNewFile,BufRead *.erb,*.rhtml setf eruby
|
||||
|
||||
" HTML with M4
|
||||
au BufNewFile,BufRead *.html.m4 setf htmlm4
|
||||
|
||||
" Some template. Used to be HTML Cheetah.
|
||||
au BufNewFile,BufRead *.tmpl setf template
|
||||
|
||||
@ -1519,8 +1516,8 @@ au BufNewFile,BufRead *.lsl call dist#ft#FTlsl()
|
||||
au BufNewFile,BufRead *.lss setf lss
|
||||
|
||||
" M4
|
||||
au BufNewFile,BufRead *.m4
|
||||
\ if expand("<afile>") !~? 'html.m4$\|fvwm2rc' | setf m4 | endif
|
||||
au BufNewFile,BufRead *.m4 call dist#ft#FTm4()
|
||||
|
||||
au BufNewFile,BufRead .m4_history setf m4
|
||||
|
||||
" MaGic Point
|
||||
|
||||
Reference in New Issue
Block a user