summaryrefslogtreecommitdiff
path: root/config/vim/autoload/emmet/lang.vim
blob: 37e426b417298c1164079a62d72a97d3b2b56c7e (plain)
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
let s:exists = {}
function! emmet#lang#exists(type) abort
  if len(a:type) == 0
    return 0
  elseif has_key(s:exists, a:type)
    return s:exists[a:type]
  endif
  let s:exists[a:type] = len(globpath(&rtp, 'autoload/emmet/lang/'.a:type.'.vim')) > 0
  return s:exists[a:type]
endfunction

function! emmet#lang#type(type) abort
  let type = a:type
  let base = type
  let settings = emmet#getSettings()
  while base != ''
    for b in split(base, '\.')
      if emmet#lang#exists(b)
        return b
      endif
      if has_key(settings, b) && has_key(settings[b], 'extends')
        let base = settings[b].extends
        break
      else
        let base = ''
      endif
    endfor
  endwhile
  return 'html'
endfunction

" get all extends for a type recursively
function! emmet#lang#getExtends(type) abort
  let settings = emmet#getSettings()

  if !has_key(settings[a:type], 'extends')
    return []
  endif

  let extends = settings[a:type].extends
  if type(extends) ==# 1
    let tmp = split(extends, '\s*,\s*')
    unlet! extends
    let extends = tmp
  endif

  for ext in extends
    let extends = extends + emmet#lang#getExtends(ext)
  endfor

  return extends
endfunction