Skip to content

Commit

Permalink
Enable partial wildcard.
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Mar 12, 2018
1 parent 7a72294 commit a4b1b50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
41 changes: 38 additions & 3 deletions autoload/precious.vim
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,44 @@ endfunction


function! s:is_enable_switch(switch, filetype)
return (get(get(g:precious_enable_switchers, "*", {}), a:switch, 1)
\ || get(get(g:precious_enable_switchers, a:filetype, {}), a:switch, 0))
\ && get(get(g:precious_enable_switchers, a:filetype, {}), a:switch, 1)
let def = precious#switch_def(g:precious_enable_switchers, a:filetype, {})
return get(def, a:switch, 1)
endfunction


function! precious#switch_def(defs, filetype, ...)
let NOTDEF = {}
let cache = get(a:defs, "__cache__", NOTDEF)
if cache is NOTDEF
let cache = {}
let a:defs["__cache__"] = cache
endif
let ft_def = get(cache, a:filetype, NOTDEF)

if ft_def is NOTDEF
let ft_def = get(a:defs, a:filetype, NOTDEF)

if ft_def is NOTDEF
if exists("*glob2regpat")
let matches = filter(copy(a:defs), "v:key != '*' && v:key =~ '[*?\\[]'"
\ . " && match(a:filetype, glob2regpat(v:key)) != -1")
if !empty(matches)
let ft_def = copy(
\ sort(map(items(matches), "[strlen(v:val[0]), v:val[1]]"),
\ {a, b -> a[0] == b[0] ? 0 : a[0] > b[0] ? -1 : 1})[0][1])
endif
endif

if ft_def is NOTDEF
let fallback = a:0 ? a:1 : 0
let ft_def = copy(get(a:defs, "*", fallback))
endif
endif

let cache[a:filetype] = ft_def
endif

return ft_def
endfunction


Expand Down
12 changes: 3 additions & 9 deletions plugin/precious.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@ let g:precious_enable_switch_CursorHold


function! s:is_enable_switch_CursorMoved(filetype)
return (get(g:precious_enable_switch_CursorMoved, "*", 1)
\ || get(g:precious_enable_switch_CursorMoved, a:filetype, 0))
\ && get(g:precious_enable_switch_CursorMoved, a:filetype, 1)
return precious#switch_def(g:precious_enable_switch_CursorMoved, a:filetype, 1)
endfunction


function! s:is_enable_switch_CursorMoved_i(filetype)
return (get(g:precious_enable_switch_CursorMoved_i, "*", 1)
\ || get(g:precious_enable_switch_CursorMoved_i, a:filetype, 0))
\ && get(g:precious_enable_switch_CursorMoved_i, a:filetype, 1)
return precious#switch_def(g:precious_enable_switch_CursorMoved_i, a:filetype, 1)
endfunction


function! s:is_enable_switch_CursorHold(filetype)
return (get(g:precious_enable_switch_CursorHold, "*", 1)
\ || get(g:precious_enable_switch_CursorHold, a:filetype, 0))
\ && get(g:precious_enable_switch_CursorHold, a:filetype, 1)
return precious#switch_def(g:precious_enable_switch_CursorHold, a:filetype, 1)
endfunction


Expand Down

0 comments on commit a4b1b50

Please sign in to comment.