@@ -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+ def s: WhenConfigHome (fname: string ): list <string>
46+ if exists (' $XDG_CONFIG_HOME' )
47+ return [expand (fname)]
48+ endif
49+ return []
50+ enddef
51+
52+ " Return the name used for the $XDG_CONFIG_HOME directory.
53+ def s: GetConfigHome (): string
54+ return getcwd () .. ' /Xdg_config_home'
55+ enddef
56+
57+ " saved value of $XDG_CONFIG_HOME
58+ let s: saveConfigHome = ' '
59+
60+ def s: SetupConfigHome ()
61+ if empty (windowsversion ())
62+ s: saveConfigHome = $XDG_CONFIG_HOME
63+ setenv (" XDG_CONFIG_HOME" , GetConfigHome ())
64+ endif
65+ enddef
66+
4367" Filetypes detected just from matching the file name.
4468" First one is checking that these files have no filetype.
4569def s: GetFilenameChecks (): dict <list<string> >
@@ -95,7 +119,7 @@ def s:GetFilenameChecks(): dict<list<string>>
95119 bzr: [' bzr_log.any' , ' bzr_log.file' ],
96120 c : [' enlightenment/file.cfg' , ' file.qc' , ' file.c' , ' some-enlightenment/file.cfg' ],
97121 cabal: [' file.cabal' ],
98- cabalconfig: [' cabal.config' ] ,
122+ cabalconfig: [' cabal.config' , expand ( " $HOME/.config/cabal/config " )] + WhenConfigHome ( ' $XDG_CONFIG_HOME/cabal/config ' ) ,
99123 cabalproject: [' cabal.project' , ' cabal.project.local' ],
100124 cairo: [' file.cairo' ],
101125 calendar: [' calendar' , ' /.calendar/file' , ' /share/calendar/any/calendar.file' , ' /share/calendar/calendar.file' , ' any/share/calendar/any/calendar.file' , ' any/share/calendar/calendar.file' ],
@@ -229,10 +253,10 @@ def s:GetFilenameChecks(): dict<list<string>>
229253 gedcom: [' file.ged' , ' lltxxxxx.txt' , ' /tmp/lltmp' , ' /tmp/lltmp-file' , ' any/tmp/lltmp' , ' any/tmp/lltmp-file' ],
230254 gemtext: [' file.gmi' , ' file.gemini' ],
231255 gift: [' file.gift' ],
232- 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' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/attributes ' ) ,
233257 gitcommit: [' COMMIT_EDITMSG' , ' MERGE_MSG' , ' TAG_EDITMSG' , ' NOTES_EDITMSG' , ' EDIT_DESCRIPTION' ],
234- 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' ],
235- 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' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/config ' ) ,
259+ gitignore: [' file.git/info/exclude' , ' .gitignore' , ' /.config/git/ignore' , ' some.git/info/exclude' ] + WhenConfigHome ( ' $XDG_CONFIG_HOME/git/ignore ' ) ,
236260 gitolite: [' gitolite.conf' , ' /gitolite-admin/conf/file' , ' any/gitolite-admin/conf/file' ],
237261 gitrebase: [' git-rebase-todo' ],
238262 gitsendemail: [' .gitsendemail.msg.xxxxxx' ],
@@ -807,6 +831,12 @@ def s:CheckItems(checks: dict<list<string>>)
807831enddef
808832
809833def Test_filetype_detection ()
834+ SetupConfigHome ()
835+ if ! empty (s: saveConfigHome )
836+ defer setenv (" XDG_CONFIG_HOME" , s: saveConfigHome )
837+ endif
838+ mkdir (GetConfigHome (), ' R' )
839+
810840 filetype on
811841 CheckItems (s: GetFilenameChecks ())
812842 if has (' fname_case' )
0 commit comments