Vim plugins (e.g.: ALE, nvim-lspconfig, etc) rely on filetype to
determine which integrations/helpers are applicable. They expect
filetype=apkbuild for APKBUILD files.
On the other hand, plugins also enable bash-specific linters and
functionality when filetype=bash, but APKBUILD files are POSIX sh, not
bash, so these often provide bogus results.
Change the filetype for APKBUILD to a 'apkbuild', so that tools and
ftplugin can properly target these files. This filetype will use the
existing `sh` syntax rules, since these are applicable for them.
---
runtime/filetype.vim | 7 ++++---
runtime/syntax/apkbuild.vim | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
create mode 100644 runtime/syntax/apkbuild.vim
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 413eb6eb9..775fac53e 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -2273,12 +2273,13 @@ au BufNewFile,BufRead *.decl,*.dcl,*.dec
au BufNewFile,BufRead catalog setf catalog
" Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
-" Gentoo ebuilds, Arch Linux PKGBUILDs and Alpine Linux APKBUILDs are actually
-" bash scripts.
+" Gentoo ebuilds, Arch Linux PKGBUILDs are actually bash scripts.
" NOTE: Patterns ending in a star are further down, these have lower priority.
-au BufNewFile,BufRead
.bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,.bash[_-]history,bash-fc[-.],*.ebuild,*.bash,*.eclass,PKGBUILD,APKBUILD,*.bats,*.cygport
call dist#ft#SetFileTypeSH("bash")
+au BufNewFile,BufRead
.bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,.bash[_-]history,bash-fc[-.],*.ebuild,*.bash,*.eclass,PKGBUILD,bats,*.cygport
call dist#ft#SetFileTypeSH("bash")
au BufNewFile,BufRead .kshrc,*.ksh call dist#ft#SetFileTypeSH("ksh")
au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.env{rc,} call
dist#ft#SetFileTypeSH(getline(1))
+" Alpine Linux APKBUILDs are actually ash scripts with special treatment.
+au BufNewFile,BufRead APKBUILD setf apkbuild
" Shell script (Arch Linux) or PHP file (Drupal)
au BufNewFile,BufRead *.install
diff --git a/runtime/syntax/apkbuild.vim b/runtime/syntax/apkbuild.vim
new file mode 100644
index 000000000..288faf962
--- /dev/null
+++ b/runtime/syntax/apkbuild.vim
@@ -0,0 +1,20 @@
+" Vim syntax file
+" Language: apkbuild
+" Maintainer: The Vim Project <https://github.com/vim/vim>
+" Last Change: 2023 Oct 20
+
+" quit when a syntax file was already loaded
+if exists("b:current_syntax")
+ finish
+endif
+
+" The actual syntax is in sh.vim and controlled by buffer-local variables.
+unlet! b:is_bash
+unlet! b:is_kornshell
+let b:is_sh = 1
+
+runtime! syntax/sh.vim
+
+let b:current_syntax = 'apkbuild'
+
+" vim: ts=8
--
2.47.1
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/20241218165247.23696-2-hugo%40whynothugo.nl.