summaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2015-12-06 11:53:26 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2015-12-06 11:53:26 +0100
commit08ea94e01188531e819e5d6bea5c84a773b4eb98 (patch)
tree595c73c1476e2fdc8458529907efea083a405f68 /ftplugin
parentba7a783c7f3d3c923ef151e4d3e99e087831ef69 (diff)
downloadvim-polyglot-08ea94e01188531e819e5d6bea5c84a773b4eb98.tar.gz
vim-polyglot-08ea94e01188531e819e5d6bea5c84a773b4eb98.zip
Add elm support, closes #81
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/elm.vim86
1 files changed, 86 insertions, 0 deletions
diff --git a/ftplugin/elm.vim b/ftplugin/elm.vim
new file mode 100644
index 00000000..7f121520
--- /dev/null
+++ b/ftplugin/elm.vim
@@ -0,0 +1,86 @@
+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 setup stuff
+
+if exists("b:did_ftplugin")
+ finish
+endif
+
+let b:did_ftplugin = 1
+
+" Compilation
+
+function! ElmMake(file)
+ let args = a:file
+ return elm#io#system("elm-make", args)
+endfunction
+
+function! ElmMakeCurrentFile()
+ echo ElmMake(expand("%"))
+endfunction
+
+function! ElmMakeMain()
+ echo ElmMake("Main.elm")
+endfunction
+
+function! ElmMakeFile(file)
+ echo ElmMake(a:file)
+endfunction
+
+" REPL
+
+function! ElmRepl()
+ !elm-repl
+endfunction
+
+" Evaluation
+
+function! ElmEvalLine()
+ return ElmEval(getline("."))
+endfunction
+
+function! ElmEvalSelection()
+ let savedReg = @z
+ normal! `<v`>"zy
+ let res = ElmEval(substitute(getreg("z"), "\n", "\\\n", "g"))
+ let @z = savedReg
+ normal! gv
+endfunction
+
+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
+
+function! s:IsUsefulReplOutput(str)
+ return a:str !~ "^Elm REPL" && a:str !~ "Type :help" && a:str !~ ">\\s*$"
+endfunction
+
+" List processing
+
+function! s:Filtered(fn, l)
+ let new_list = deepcopy(a:l)
+ call filter(new_list, string(a:fn) . '(v:val)')
+ return new_list
+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
+
+endif