2016-12-20 14:57:20 -05:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
function! elixir#util#get_filename(word) abort
|
|
|
|
let word = a:word
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
" get first thing that starts uppercase, until the first space or end of line
|
|
|
|
let word = substitute(word,'^\s*\(\u[^ ]\+\).*$','\1','g')
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
" remove any trailing characters that don't look like a nested module
|
|
|
|
let word = substitute(word,'\.\U.*$','','g')
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
" replace module dots with slash
|
|
|
|
let word = substitute(word,'\.','/','g')
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
" remove any special chars
|
|
|
|
let word = substitute(word,'[^A-z0-9-_/]','','g')
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
" convert to snake_case
|
|
|
|
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
|
|
|
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
|
|
|
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
|
|
|
|
let word = substitute(word,'-','_','g')
|
|
|
|
let word = tolower(word)
|
2016-12-20 14:57:20 -05:00
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
return word
|
2017-02-02 15:16:29 -05:00
|
|
|
endfunction
|
|
|
|
|
2016-12-20 14:57:20 -05:00
|
|
|
endif
|