@@ -175,13 +175,51 @@ call s:add_methods('matcher', [
175175 \ ' search_forward' , ' search_backward'
176176 \ ])
177177
178+ " }}}
179+ " Loader prototype {{{
180+
181+ let s: loader_prototype = {}
182+
183+ fun ! s: loader () abort
184+ let loader = {
185+ \ ' filetypes' : {}
186+ \ }
187+ call extend (loader, s: loader_prototype , ' keep' )
188+ return loader
189+ endf
190+
191+ fun ! s: loader_load (ft ) dict abort
192+ return self .filetypes[a: ft ]
193+ endf
194+
195+ fun ! s: loader_save (ft , list ) dict abort
196+ let self .filetypes[a: ft ] = a: list
197+ endf
198+
199+ fun ! s: loader_is_cached (ft ) dict abort
200+ return has_key (self .filetypes, a: ft )
201+ endf
202+
203+ fun ! s: loader_load_by_filetype (ft ) dict abort
204+ if self .is_cached (a: ft )
205+ return self .load (a: ft )
206+ else
207+ let matchers = fancy#ft #{a: ft }#matchers ()
208+ call self .save (a: ft , matchers)
209+ return matchers
210+ endf
211+
212+ call s: add_methods (' loader' , [
213+ \ ' load' , ' save' , ' is_cached' , ' load_by_filetype'
214+ \ ])
215+
178216" }}}
179217" Fancy prototype {{{
180218
181219let s: fancy_prototype = {}
182220
183221fun ! s: fancy () abort
184- let matchers = s: get_filetype_matchers (&filetype )
222+ let matchers = s: loader (). load_by_filetype (&filetype )
185223 if empty (matchers)
186224 call s: error (printf (' %s: no available matcher' , &filetype ))
187225 return
@@ -246,7 +284,7 @@ fun! s:lookup_fancy(id)
246284 return found[0 ]
247285endf
248286
249- fun ! s: get_filetype_matchers (ft )
287+ fun ! s: matchers_by_filetype (ft )
250288 if has_key (g: fancy_filetypes , a: ft )
251289 return g: fancy_filetypes [a: ft ]
252290 endif
0 commit comments