]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0953: filetype: APKBUILD files not correctly detected v9.1.0953
authorHugo Osvaldo Barrera' via vim_dev <vim_dev@googlegroups.com>
Wed, 18 Dec 2024 16:52:48 +0000 (17:52 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 22 Dec 2024 14:11:50 +0000 (15:11 +0100)
Problem:  filetype: APKBUILD files not correctly detected
Solution: detect 'APKBUILD' files as apkbuild filetype,
          include a apkbuild syntax script (which basically
          just sources the sh.vim syntax file)
          (Hugo Osvaldo Barrera)

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.

Signed-off-by: Hugo Osvaldo Barrera' via vim_dev <vim_dev@googlegroups.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/filetype.vim
runtime/syntax/apkbuild.vim [new file with mode: 0644]
src/testdir/test_filetype.vim
src/version.c

index fe3d4b554c8c1bcaea52366fe5927ebb160feaba..8b3d44db55404d61f61c530ee4efec1467a9875a 100644 (file)
@@ -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 and 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 POSIX sh 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 (file)
index 0000000..f969ff0
--- /dev/null
@@ -0,0 +1,17 @@
+" Vim syntax file
+" Language:    apkbuild
+" Maintainer:  The Vim Project <https://github.com/vim/vim>
+" Last Change: 2024 Dec 22
+
+" 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 b:is_kornshell
+let b:is_sh = 1
+
+runtime! syntax/sh.vim
+
+let b:current_syntax = 'apkbuild'
index 4761e7137e1738e1116dc9b8d2b883853f74555e..b5e2dc0b150629293e99a1b75e891b4a24d525f8 100644 (file)
@@ -107,6 +107,7 @@ def s:GetFilenameChecks(): dict<list<string>>
       '/etc/httpd/sites-some/file', '/etc/httpd/conf.file/conf'],
     apachestyle: ['/etc/proftpd/file.config,/etc/proftpd/conf.file/file', '/etc/proftpd/conf.file/file', '/etc/proftpd/file.conf', '/etc/proftpd/file.conf-file',
       'any/etc/proftpd/conf.file/file', 'any/etc/proftpd/file.conf', 'any/etc/proftpd/file.conf-file', 'proftpd.conf', 'proftpd.conf-file'],
+    apkbuild: ['APKBUILD'],
     applescript: ['file.scpt'],
     aptconf: ['apt.conf', '/.aptitude/config', 'any/.aptitude/config'],
     arch: ['.arch-inventory', '=tagging-method'],
@@ -683,7 +684,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     setserial: ['/etc/serial.conf', 'any/etc/serial.conf'],
     sexplib: ['file.sexp'],
     sh: ['.bashrc', '.bash_profile', '.bash-profile', '.bash_logout', '.bash-logout', '.bash_aliases', '.bash-aliases', '.bash_history', '.bash-history',
-         '/tmp/bash-fc-3Ozjlw', '/tmp/bash-fc.3Ozjlw', 'PKGBUILD', 'APKBUILD', 'file.bash', '/usr/share/doc/bash-completion/filter.sh',
+         '/tmp/bash-fc-3Ozjlw', '/tmp/bash-fc.3Ozjlw', 'PKGBUILD', 'file.bash', '/usr/share/doc/bash-completion/filter.sh',
          '/etc/udev/cdsymlinks.conf', 'any/etc/udev/cdsymlinks.conf', 'file.bats', '.ash_history', 'any/etc/neofetch/config.conf', '.xprofile',
          'user-dirs.defaults', 'user-dirs.dirs', 'makepkg.conf', '.makepkg.conf', 'file.mdd', 'file.cygport', '.env', '.envrc', 'devscripts.conf',
          '.devscripts', 'file.lo', 'file.la', 'file.lai'],
index dc7a029f4bca94a6161c2e66c55c9792f7c4a436..51498fd16305dcc30025654050770ee371f909d5 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    953,
 /**/
     952,
 /**/