diff options
Diffstat (limited to '')
-rw-r--r-- | ftplugin/elm.vim | 137 | ||||
-rw-r--r-- | ftplugin/elm/tagbar.vim | 24 |
2 files changed, 100 insertions, 61 deletions
diff --git a/ftplugin/elm.vim b/ftplugin/elm.vim index 7f121520..180e719c 100644 --- a/ftplugin/elm.vim +++ b/ftplugin/elm.vim @@ -1,86 +1,101 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1 -" elm.vim - Plugin for the Elm programming language -" Maintainer: Alexander Noriega <http://lambdatoast.com/> -" Version: 0.4.3 +" plugin for Elm (http://elm-lang.org/) -" Plugin setup stuff - -if exists("b:did_ftplugin") +if exists('b:did_ftplugin') finish endif let b:did_ftplugin = 1 -" Compilation +" Settings +if !exists('g:elm_jump_to_error') + let g:elm_jump_to_error = 0 +endif -function! ElmMake(file) - let args = a:file - return elm#io#system("elm-make", args) -endfunction +if !exists('g:elm_make_output_file') + let g:elm_make_output_file = 'elm.js' +endif -function! ElmMakeCurrentFile() - echo ElmMake(expand("%")) -endfunction +if !exists('g:elm_make_show_warnings') + let g:elm_make_show_warnings = 0 +endif -function! ElmMakeMain() - echo ElmMake("Main.elm") -endfunction +if !exists('g:elm_syntastic_show_warnings') + let g:elm_syntastic_show_warnings = 0 +endif -function! ElmMakeFile(file) - echo ElmMake(a:file) -endfunction +if !exists('g:elm_format_autosave') + let g:elm_format_autosave = 1 +endif -" REPL +if !exists('g:elm_format_fail_silently') + let g:elm_format_fail_silently = 0 +endif -function! ElmRepl() - !elm-repl -endfunction +if !exists('g:elm_setup_keybindings') + let g:elm_setup_keybindings = 1 +endif -" Evaluation +setlocal omnifunc=elm#Complete -function! ElmEvalLine() - return ElmEval(getline(".")) -endfunction +setlocal comments=:-- +setlocal commentstring=--\ %s + +" Commands +command -buffer -nargs=? -complete=file ElmMake call elm#Make(<f-args>) +command -buffer ElmMakeMain call elm#Make("Main.elm") +command -buffer -nargs=? -complete=file ElmTest call elm#Test(<f-args>) +command -buffer ElmRepl call elm#Repl() +command -buffer ElmErrorDetail call elm#ErrorDetail() +command -buffer ElmShowDocs call elm#ShowDocs() +command -buffer ElmBrowseDocs call elm#BrowseDocs() +command -buffer ElmFormat call elm#Format() + +if get(g:, 'elm_setup_keybindings', 1) + nmap <buffer> <LocalLeader>m <Plug>(elm-make) + nmap <buffer> <LocalLeader>b <Plug>(elm-make-main) + nmap <buffer> <LocalLeader>t <Plug>(elm-test) + nmap <buffer> <LocalLeader>r <Plug>(elm-repl) + nmap <buffer> <LocalLeader>e <Plug>(elm-error-detail) + nmap <buffer> <LocalLeader>d <Plug>(elm-show-docs) + nmap <buffer> <LocalLeader>w <Plug>(elm-browse-docs) +endif -function! ElmEvalSelection() - let savedReg = @z - normal! `<v`>"zy - let res = ElmEval(substitute(getreg("z"), "\n", "\\\n", "g")) - let @z = savedReg - normal! gv -endfunction +" Better gf command +nmap <buffer> gf :call elm#util#GoToModule(expand('<cfile>'))<CR> -function! ElmEval(sourceCode) - let currentLine = a:sourceCode - let args = "echo '" . currentLine . "' | elm-repl" - let result = elm#io#system("echo", args) - let cleanResult = "-- " . join(s:Filtered(function("s:IsUsefulReplOutput"), split(result, "\n")), "") - put =cleanResult -endfunction +" Elm code formatting on save +if get(g:, 'elm_format_autosave', 1) + augroup elmFormat + autocmd! + autocmd BufWritePre *.elm call elm#Format() + autocmd BufWritePost *.elm call elm#util#EchoStored() + augroup END +endif +if has('win32') + set viewdir=$HOME/vimfiles/views/ +endif -function! s:IsUsefulReplOutput(str) - return a:str !~ "^Elm REPL" && a:str !~ "Type :help" && a:str !~ ">\\s*$" -endfunction +" Enable go to file under cursor from module name +" Based on: https://github.com/elixir-lang/vim-elixir/blob/bd66ed134319d1e390f3331e8c4d525109f762e8/ftplugin/elixir.vim#L22-L56 +function! GetElmFilename(word) + let l:word = a:word -" List processing + " replace module dots with slash + let l:word = substitute(l:word,'\.','/','g') -function! s:Filtered(fn, l) - let new_list = deepcopy(a:l) - call filter(new_list, string(a:fn) . '(v:val)') - return new_list + return l:word endfunction -command -buffer ElmEvalLine call ElmEvalLine() -command -buffer ElmEvalSelection call ElmEvalSelection() -command -buffer ElmMakeMain call ElmMakeMain() -command -buffer -nargs=1 ElmMakeFile call ElmMakeFile <args> -command -buffer ElmMakeCurrentFile call ElmMakeCurrentFile() -command -buffer ElmRepl call ElmRepl() - -" Define comment convention - -setlocal comments=:-- -setlocal commentstring=--%s +let &l:path = + \ join([ + \ elm#FindRootDirectory().'/src', + \ elm#FindRootDirectory().'/elm-stuff/packages/**/src', + \ &g:path + \ ], ',') +setlocal includeexpr=GetElmFilename(v:fname) +setlocal include=^\\s*import\\s\\+ +setlocal suffixesadd=.elm endif diff --git a/ftplugin/elm/tagbar.vim b/ftplugin/elm/tagbar.vim new file mode 100644 index 00000000..1ad3a48b --- /dev/null +++ b/ftplugin/elm/tagbar.vim @@ -0,0 +1,24 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1 + +if !executable('ctags') + finish +elseif globpath(&runtimepath, 'plugin/tagbar.vim') ==? '' + finish +endif + +function! s:SetTagbar() + if !exists('g:tagbar_type_elm') + let g:tagbar_type_elm = { + \ 'ctagstype' : 'elm', + \ 'kinds' : [ + \ 'c:constants', + \ 'f:functions', + \ 'p:ports' + \ ] + \ } + endif +endfunction + +call s:SetTagbar() + +endif |