vim-patch:9.0.1632: not all cabal config files are recognized (#24025)

Problem:    Not all cabal config files are recognized.
Solution:   Add a couple of patterns. (Marcin Szamotulski, closes vim/vim#12463)

166cd7b801

Also:
- Do not expand Lua patterns in environment variables used in file patterns.
- Test $XDG_CONFIG_HOME on Windows, as it can be used by Nvim (and the runner
  sets it).

Co-authored-by: Marcin Szamotulski <coot@coot.me>
This commit is contained in:
Jonas Strittmatter 2023-06-26 12:19:13 +02:00 committed by GitHub
parent 7578144cbd
commit 0ca2d11c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 7 deletions

View File

@ -1809,6 +1809,8 @@ local pattern = {
['bzr_log%..*'] = 'bzr',
['.*enlightenment/.*%.cfg'] = 'c',
['${HOME}/cabal%.config'] = 'cabalconfig',
['${HOME}/%.config/cabal/config'] = 'cabalconfig',
['${XDG_CONFIG_HOME}/cabal/config'] = 'cabalconfig',
['cabal%.project%..*'] = starsetf('cabalproject'),
['.*/%.calendar/.*'] = starsetf('calendar'),
['.*/share/calendar/.*/calendar%..*'] = starsetf('calendar'),
@ -2490,7 +2492,7 @@ local function match_pattern(name, path, tail, pat)
return_early = true
return nil
end
return vim.env[env]
return vim.pesc(vim.env[env])
end)
if return_early then
return false

View File

@ -40,9 +40,35 @@ func Test_other_type()
filetype off
endfunc
" If $XDG_CONFIG_HOME is set return "fname" expanded in a list.
" Otherwise return an empty list.
func s:WhenConfigHome(fname)
if exists('$XDG_CONFIG_HOME')
return [expand(a:fname)]
endif
return []
endfunc
" Return the name used for the $XDG_CONFIG_HOME directory.
func s:GetConfigHome()
return getcwd() .. '/Xdg_config_home'
endfunc
" saved value of $XDG_CONFIG_HOME
let s:saveConfigHome = ''
func s:SetupConfigHome()
" Nvim on Windows may use $XDG_CONFIG_HOME, and runnvim.sh sets it.
" if empty(windowsversion())
let s:saveConfigHome = $XDG_CONFIG_HOME
call setenv("XDG_CONFIG_HOME", s:GetConfigHome())
" endif
endfunc
" Filetypes detected just from matching the file name.
" First one is checking that these files have no filetype.
let s:filename_checks = {
func s:GetFilenameChecks() abort
return {
\ 'none': ['bsd', 'some-bsd'],
\ '8th': ['file.8th'],
\ 'a2ps': ['/etc/a2ps.cfg', '/etc/a2ps/file.cfg', 'a2psrc', '.a2psrc', 'any/etc/a2ps.cfg', 'any/etc/a2ps/file.cfg'],
@ -94,7 +120,7 @@ let s:filename_checks = {
\ 'bzr': ['bzr_log.any', 'bzr_log.file'],
\ 'c': ['enlightenment/file.cfg', 'file.qc', 'file.c', 'some-enlightenment/file.cfg'],
\ 'cabal': ['file.cabal'],
\ 'cabalconfig': ['cabal.config'],
\ 'cabalconfig': ['cabal.config', expand("$HOME/.config/cabal/config")] + s:WhenConfigHome('$XDG_CONFIG_HOME/cabal/config'),
\ 'cabalproject': ['cabal.project', 'cabal.project.local'],
\ 'cairo': ['file.cairo'],
\ 'calendar': ['calendar', '/.calendar/file', '/share/calendar/any/calendar.file', '/share/calendar/calendar.file', 'any/share/calendar/any/calendar.file', 'any/share/calendar/calendar.file'],
@ -228,10 +254,10 @@ let s:filename_checks = {
\ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'],
\ 'gemtext': ['file.gmi', 'file.gemini'],
\ 'gift': ['file.gift'],
\ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'],
\ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'] + s:WhenConfigHome('$XDG_CONFIG_HOME/git/attributes'),
\ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG', 'NOTES_EDITMSG', 'EDIT_DESCRIPTION'],
\ 'gitconfig': ['file.git/config', 'file.git/config.worktree', 'file.git/worktrees/x/config.worktree', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig', '/usr/local/etc/gitconfig', '/etc/gitconfig.d/file', 'any/etc/gitconfig.d/file', '/.gitconfig.d/file', 'any/.config/git/config', 'any/.gitconfig.d/file', 'some.git/config', 'some.git/modules/any/config'],
\ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'],
\ 'gitconfig': ['file.git/config', 'file.git/config.worktree', 'file.git/worktrees/x/config.worktree', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig', '/usr/local/etc/gitconfig', '/etc/gitconfig.d/file', 'any/etc/gitconfig.d/file', '/.gitconfig.d/file', 'any/.config/git/config', 'any/.gitconfig.d/file', 'some.git/config', 'some.git/modules/any/config'] + s:WhenConfigHome('$XDG_CONFIG_HOME/git/config'),
\ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'] + s:WhenConfigHome('$XDG_CONFIG_HOME/git/ignore'),
\ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'],
\ 'gitrebase': ['git-rebase-todo'],
\ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'],
@ -702,6 +728,7 @@ let s:filename_checks = {
\
\ 'help': [$VIMRUNTIME . '/doc/help.txt'],
\ }
endfunc
let s:filename_case_checks = {
\ 'modula2': ['file.DEF'],
@ -732,8 +759,14 @@ func CheckItems(checks)
endfunc
func Test_filetype_detection()
call s:SetupConfigHome()
if !empty(s:saveConfigHome)
defer setenv("XDG_CONFIG_HOME", s:saveConfigHome)
endif
call mkdir(s:GetConfigHome(), 'R')
filetype on
call CheckItems(s:filename_checks)
call CheckItems(s:GetFilenameChecks())
if has('fname_case')
call CheckItems(s:filename_case_checks)
endif