summaryrefslogtreecommitdiffstats
path: root/autoload/polyglot/util.vim
blob: f0fd0388a324cc2d0635cf3f98920293a87044f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
" Restore 'cpoptions'
let s:cpo_save = &cpo
set cpo&vim

let s:disabled_packages = {}
let s:new_polyglot_disabled = []

if exists('g:polyglot_disabled')
  for pkg in g:polyglot_disabled
    let base = split(pkg, '\.')
    if len(base) > 0
      let s:disabled_packages[pkg] = 1
      call add(s:new_polyglot_disabled, base[0])
    endif
  endfor
else
  let g:polyglot_disabled_not_set = 1
endif


let s:base = expand('<sfile>:p:h:h:h')

func polyglot#util#Filter(idx, val)
  let val = fnamemodify(a:val . '/', ':p:h')
  return resolve(val) !=? s:base && stridx(val, $VIMRUNTIME) == -1 && val !~? '[/\\]after$'
endfunc

let s:rtp = join(filter(split(&rtp, ','), function('polyglot#util#Filter')), ',')

func polyglot#util#IsEnabled(type, file)
  if a:file != "ftdetect"
    let file = a:file[len(s:base) + 1:]
    let files = globpath(s:rtp, file, 1, 1)
    if !empty(files)
      exec 'source' files[0]
      return 0
    endif
  endif
  if a:type == "jsx"
    return !has_key(s:disabled_packages, "jsx") && !has_key(s:disabled_packages, "javascript")
  endif
  return !has_key(s:disabled_packages, a:type)
endfunc

func! polyglot#util#Verify()
  if exists("g:polyglot_disabled_not_set")
    if exists("g:polyglot_disabled")
      echohl WarningMsg
      echo "vim-polyglot: g:polyglot_disabled should be defined before loading vim-polyglot"
      echohl None
    endif

    unlet g:polyglot_disabled_not_set
  endif
endfunc

" Save polyglot_disabled without postfixes
if exists('g:polyglot_disabled')
  let g:polyglot_disabled = s:new_polyglot_disabled
endif

" Restore 'cpoptions'
let &cpo = s:cpo_save
unlet s:cpo_save