Skip to content

Commit 12ae8c7

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 Co-authored-by: Marcin Szamotulski <[email protected]>
1 parent 957d05d commit 12ae8c7

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

runtime/lua/vim/filetype.lua

Lines changed: 2 additions & 0 deletions
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'),

test/old/testdir/test_filetype.vim

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,34 @@ 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+
if empty(windowsversion())
62+
let s:saveConfigHome = $XDG_CONFIG_HOME
63+
call setenv("XDG_CONFIG_HOME", s:GetConfigHome())
64+
endif
65+
endfunc
66+
4367
" Filetypes detected just from matching the file name.
4468
" First one is checking that these files have no filetype.
45-
let s:filename_checks = {
69+
func s:GetFilenameChecks() abort
70+
return {
4671
\ 'none': ['bsd', 'some-bsd'],
4772
\ '8th': ['file.8th'],
4873
\ 'a2ps': ['/etc/a2ps.cfg', '/etc/a2ps/file.cfg', 'a2psrc', '.a2psrc', 'any/etc/a2ps.cfg', 'any/etc/a2ps/file.cfg'],
@@ -94,7 +119,7 @@ let s:filename_checks = {
94119
\ 'bzr': ['bzr_log.any', 'bzr_log.file'],
95120
\ 'c': ['enlightenment/file.cfg', 'file.qc', 'file.c', 'some-enlightenment/file.cfg'],
96121
\ 'cabal': ['file.cabal'],
97-
\ 'cabalconfig': ['cabal.config'],
122+
\ 'cabalconfig': ['cabal.config', expand("$HOME/.config/cabal/config")] + s:WhenConfigHome('$XDG_CONFIG_HOME/cabal/config'),
98123
\ 'cabalproject': ['cabal.project', 'cabal.project.local'],
99124
\ 'cairo': ['file.cairo'],
100125
\ '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 +253,10 @@ let s:filename_checks = {
228253
\ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'],
229254
\ 'gemtext': ['file.gmi', 'file.gemini'],
230255
\ 'gift': ['file.gift'],
231-
\ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'],
256+
\ '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'),
232257
\ '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'],
258+
\ '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'),
259+
\ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'] + s:WhenConfigHome('$XDG_CONFIG_HOME/git/ignore'),
235260
\ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'],
236261
\ 'gitrebase': ['git-rebase-todo'],
237262
\ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'],
@@ -702,6 +727,7 @@ let s:filename_checks = {
702727
\
703728
\ 'help': [$VIMRUNTIME . '/doc/help.txt'],
704729
\ }
730+
endfunc
705731

706732
let s:filename_case_checks = {
707733
\ 'modula2': ['file.DEF'],
@@ -732,8 +758,14 @@ func CheckItems(checks)
732758
endfunc
733759

734760
func Test_filetype_detection()
761+
call s:SetupConfigHome()
762+
if !empty(s:saveConfigHome)
763+
defer setenv("XDG_CONFIG_HOME", s:saveConfigHome)
764+
endif
765+
call mkdir(s:GetConfigHome(), 'R')
766+
735767
filetype on
736-
call CheckItems(s:filename_checks)
768+
call CheckItems(s:GetFilenameChecks())
737769
if has('fname_case')
738770
call CheckItems(s:filename_case_checks)
739771
endif

0 commit comments

Comments
 (0)