Skip to content

Commit 4a33462

Browse files
smjonascoot
authored andcommitted
vim-patch:9.0.1632: not all cabal config files are recognized
Problem: Not all cabal config files are recognized. Solution: Add a couple of patterns. (Marcin Szamotulski, closes vim/vim#12463) vim/vim@166cd7b 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 <[email protected]>
1 parent b697c0c commit 4a33462

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

runtime/lua/vim/filetype.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,8 @@ local pattern = {
18091809
['bzr_log%..*'] = 'bzr',
18101810
['.*enlightenment/.*%.cfg'] = 'c',
18111811
['${HOME}/cabal%.config'] = 'cabalconfig',
1812+
['${HOME}/%.config/cabal/config'] = 'cabalconfig',
1813+
['${XDG_CONFIG_HOME}/cabal/config'] = 'cabalconfig',
18121814
['cabal%.project%..*'] = starsetf('cabalproject'),
18131815
['.*/%.calendar/.*'] = starsetf('calendar'),
18141816
['.*/share/calendar/.*/calendar%..*'] = starsetf('calendar'),
@@ -2490,7 +2492,7 @@ local function match_pattern(name, path, tail, pat)
24902492
return_early = true
24912493
return nil
24922494
end
2493-
return vim.env[env]
2495+
return vim.pesc(vim.env[env])
24942496
end)
24952497
if return_early then
24962498
return false

test/old/testdir/test_filetype.vim

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,35 @@ func Test_other_type()
4040
filetype off
4141
endfunc
4242

43+
" If $XDG_CONFIG_HOME is set return "fname" expanded in a list.
44+
" Otherwise return an empty list.
45+
func s:WhenConfigHome(fname)
46+
if exists('$XDG_CONFIG_HOME')
47+
return [expand(a:fname)]
48+
endif
49+
return []
50+
endfunc
51+
52+
" Return the name used for the $XDG_CONFIG_HOME directory.
53+
func s:GetConfigHome()
54+
return getcwd() .. '/Xdg_config_home'
55+
endfunc
56+
57+
" saved value of $XDG_CONFIG_HOME
58+
let s:saveConfigHome = ''
59+
60+
func s:SetupConfigHome()
61+
" Nvim on Windows may use $XDG_CONFIG_HOME, and runnvim.sh sets it.
62+
" if empty(windowsversion())
63+
let s:saveConfigHome = $XDG_CONFIG_HOME
64+
call setenv("XDG_CONFIG_HOME", s:GetConfigHome())
65+
" endif
66+
endfunc
67+
4368
" Filetypes detected just from matching the file name.
4469
" First one is checking that these files have no filetype.
45-
let s:filename_checks = {
70+
func s:GetFilenameChecks() abort
71+
return {
4672
\ 'none': ['bsd', 'some-bsd'],
4773
\ '8th': ['file.8th'],
4874
\ '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 = {
94120
\ 'bzr': ['bzr_log.any', 'bzr_log.file'],
95121
\ 'c': ['enlightenment/file.cfg', 'file.qc', 'file.c', 'some-enlightenment/file.cfg'],
96122
\ 'cabal': ['file.cabal'],
97-
\ 'cabalconfig': ['cabal.config'],
123+
\ 'cabalconfig': ['cabal.config', expand("$HOME/.config/cabal/config")] + s:WhenConfigHome('$XDG_CONFIG_HOME/cabal/config'),
98124
\ 'cabalproject': ['cabal.project', 'cabal.project.local'],
99125
\ 'cairo': ['file.cairo'],
100126
\ '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 = {
228254
\ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'],
229255
\ 'gemtext': ['file.gmi', 'file.gemini'],
230256
\ 'gift': ['file.gift'],
231-
\ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'],
257+
\ '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'),
232258
\ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG', 'NOTES_EDITMSG', 'EDIT_DESCRIPTION'],
233-
\ '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'],
234-
\ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'],
259+
\ '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'),
260+
\ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'] + s:WhenConfigHome('$XDG_CONFIG_HOME/git/ignore'),
235261
\ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'],
236262
\ 'gitrebase': ['git-rebase-todo'],
237263
\ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'],
@@ -702,6 +728,7 @@ let s:filename_checks = {
702728
\
703729
\ 'help': [$VIMRUNTIME . '/doc/help.txt'],
704730
\ }
731+
endfunc
705732

706733
let s:filename_case_checks = {
707734
\ 'modula2': ['file.DEF'],
@@ -732,8 +759,14 @@ func CheckItems(checks)
732759
endfunc
733760

734761
func Test_filetype_detection()
762+
call s:SetupConfigHome()
763+
if !empty(s:saveConfigHome)
764+
defer setenv("XDG_CONFIG_HOME", s:saveConfigHome)
765+
endif
766+
call mkdir(s:GetConfigHome(), 'R')
767+
735768
filetype on
736-
call CheckItems(s:filename_checks)
769+
call CheckItems(s:GetFilenameChecks())
737770
if has('fname_case')
738771
call CheckItems(s:filename_case_checks)
739772
endif

0 commit comments

Comments
 (0)