@@ -40,9 +40,34 @@ 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 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
706732let s: filename_case_checks = {
707733 \ ' modula2' : [' file.DEF' ],
@@ -732,8 +758,14 @@ func CheckItems(checks)
732758endfunc
733759
734760func 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