]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/filetypes.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / filetypes.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: This file handles guessing file extensions for filetypes, etc.
3
4 function! ale#filetypes#LoadExtensionMap() abort
5     " Output includes:
6     "    '*.erl setf erlang'
7     let l:output = execute('exec "autocmd"')
8
9     let l:map = {}
10
11     for l:line in split(l:output, "\n")
12         " Parse filetypes, like so:
13         "
14         "    *.erl setf erlang
15         " *.md      set filetype=markdown
16         " *.snippet setlocal filetype=snippets
17         let l:match = matchlist(l:line, '\v^ *\*(\.[^ ]+).*set(f *| *filetype=|local *filetype=)([^ ]+)')
18
19         if !empty(l:match)
20             let l:map[substitute(l:match[3], '^=', '', '')] = l:match[1]
21         endif
22     endfor
23
24     return l:map
25 endfunction
26
27 let s:cached_map = {}
28
29 function! s:GetCachedExtensionMap() abort
30     if empty(s:cached_map)
31         let s:cached_map = ale#filetypes#LoadExtensionMap()
32     endif
33
34     return s:cached_map
35 endfunction
36
37 function! ale#filetypes#GuessExtension(filetype) abort
38     let l:map = s:GetCachedExtensionMap()
39     let l:ext = get(l:map, a:filetype, '')
40
41     " If we have an exact match, like something for javascript.jsx, use that.
42     if !empty(l:ext)
43         return l:ext
44     endif
45
46     " If we don't have an exact match, use the first filetype in the compound
47     " filetype.
48     for l:part in split(a:filetype, '\.')
49         let l:ext = get(l:map, l:part, '')
50
51         if !empty(l:ext)
52             return l:ext
53         endif
54     endfor
55
56     " Return an empty string if we don't find anything.
57     return ''
58 endfunction