@@ -40,9 +40,35 @@ 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+ " 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
706733let s: filename_case_checks = {
707734 \ ' modula2' : [' file.DEF' ],
@@ -732,8 +759,14 @@ func CheckItems(checks)
732759endfunc
733760
734761func 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