@@ -40,6 +40,30 @@ func Test_other_type()
4040 filetype off
4141endfunc
4242
43+ " If $XDG_CONFIG_HOME is set return "fname" expanded in a list.
44+ " Otherwise return an empty list.
45+ func 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 GetConfigHome ()
54+ return getcwd () .. ' /Xdg_config_home'
55+ endfunc
56+
57+ " saved value of $XDG_CONFIG_HOME
58+ let s: saveConfigHome = ' '
59+
60+ func SetupConfigHome ()
61+ if empty (windowsversion ())
62+ let s: saveConfigHome = $XDG_CONFIG_HOME
63+ call setenv (" XDG_CONFIG_HOME" , 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.
4569let s: filename_checks = {
@@ -94,7 +118,7 @@ let s:filename_checks = {
94118 \ ' bzr' : [' bzr_log.any' , ' bzr_log.file' ],
95119 \ ' c' : [' enlightenment/file.cfg' , ' file.qc' , ' file.c' , ' some-enlightenment/file.cfg' ],
96120 \ ' cabal' : [' file.cabal' ],
97- \ ' cabalconfig' : [' cabal.config' ] ,
121+ \ ' cabalconfig' : [' cabal.config' , expand ( " $HOME/.config/cabal/config " )] + WhenConfigHome ( ' $XDG_CONFIG_HOME/cabal/config ' ) ,
98122 \ ' cabalproject' : [' cabal.project' , ' cabal.project.local' ],
99123 \ ' cairo' : [' file.cairo' ],
100124 \ ' 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 +252,10 @@ let s:filename_checks = {
228252 \ ' gedcom' : [' file.ged' , ' lltxxxxx.txt' , ' /tmp/lltmp' , ' /tmp/lltmp-file' , ' any/tmp/lltmp' , ' any/tmp/lltmp-file' ],
229253 \ ' gemtext' : [' file.gmi' , ' file.gemini' ],
230254 \ ' gift' : [' file.gift' ],
231- \ ' gitattributes' : [' file.git/info/attributes' , ' .gitattributes' , ' /.config/git/attributes' , ' /etc/gitattributes' , ' /usr/local/etc/gitattributes' , ' some.git/info/attributes' ],
255+ \ ' gitattributes' : [' file.git/info/attributes' , ' .gitattributes' , ' /.config/git/attributes' , ' /etc/gitattributes' , ' /usr/local/etc/gitattributes' , ' some.git/info/attributes' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/attributes ' ) ,
232256 \ ' 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' ],
257+ \ ' 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' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/config ' ) ,
258+ \ ' gitignore' : [' file.git/info/exclude' , ' .gitignore' , ' /.config/git/ignore' , ' some.git/info/exclude' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/ignore ' ) ,
235259 \ ' gitolite' : [' gitolite.conf' , ' /gitolite-admin/conf/file' , ' any/gitolite-admin/conf/file' ],
236260 \ ' gitrebase' : [' git-rebase-todo' ],
237261 \ ' gitsendemail' : [' .gitsendemail.msg.xxxxxx' ],
@@ -731,6 +755,12 @@ func CheckItems(checks)
731755endfunc
732756
733757func Test_filetype_detection ()
758+ call SetupConfigHome ()
759+ if ! empty (s: saveConfigHome )
760+ defer setenv (" XDG_CONFIG_HOME" , s: saveConfigHome )
761+ endif
762+ call mkdir (GetConfigHome (), ' R' )
763+
734764 filetype on
735765 call CheckItems (s: filename_checks )
736766 if has (' fname_case' )
0 commit comments