<title>CodeMirror: LiveScript mode</title>
<link rel=stylesheet href="../../doc/docs.css">
<link rel="stylesheet" href="../../lib/codemirror.css">
<link rel="stylesheet" href="../../theme/solarized.css">
<script src="../../lib/codemirror.js"></script>
<script src="livescript.js"></script>
<style>.CodeMirror {font-size: 80%;border-top: 1px solid silver; border-bottom: 1px solid silver;}</style>
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/codemirror/codemirror">Code</a>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">LiveScript</a>
<form><textarea id="code" name="code">
# LiveScript mode for CodeMirror
# The following script, prelude.ls, is used to
# demonstrate LiveScript mode for CodeMirror.
# https://github.com/gkz/prelude-ls
export objToFunc = objToFunc = (obj) ->
export each = (f, xs) -->
f = objToFunc f if typeof! f isnt \Function
{[key, f x] for key, x of xs}
result = [f x for x in xs]
if type is \String then result * '' else result
export filter = (f, xs) -->
f = objToFunc f if typeof! f isnt \Function
{[key, x] for key, x of xs when f x}
result = [x for x in xs when f x]
if type is \String then result * '' else result
export reject = (f, xs) -->
f = objToFunc f if typeof! f isnt \Function
{[key, x] for key, x of xs when not f x}
result = [x for x in xs when not f x]
if type is \String then result * '' else result
export partition = (f, xs) -->
f = objToFunc f if typeof! f isnt \Function
(if f x then passed else failed)[key] = x
(if f x then passed else failed)push x
export find = (f, xs) -->
f = objToFunc f if typeof! f isnt \Function
for , x of xs when f x then return x
for x in xs when f x then return x
export head = export first = (xs) ->
return void if not xs.length
return void if not xs.length
return void if not xs.length
return void if not xs.length
for x of xs then return false
xs = values xs if typeof! xs is \Object
export cons = (x, xs) -->
if typeof! xs is \String then x + xs else [x] ++ xs
export append = (xs, ys) -->
if typeof! ys is \String then xs + ys else xs ++ ys
export join = (sep, xs) -->
xs = values xs if typeof! xs is \Object
then (xs / '')reverse! * ''
export fold = export foldl = (f, memo, xs) -->
for , x of xs then memo = f memo, x
for x in xs then memo = f memo, x
export fold1 = export foldl1 = (f, xs) --> fold f, xs.0, xs.slice 1
export foldr = (f, memo, xs) --> fold f, memo, xs.slice!reverse!
export foldr1 = (f, xs) -->
export unfoldr = export unfold = (f, b) -->
[that.0] ++ unfoldr f, that.1
f = objToFunc f if typeof! f isnt \Function
f = objToFunc f if typeof! f isnt \Function
for , x of xs when x not in result then result.push x
for x in xs when x not in result then result.push x
if typeof! xs is \String then result * '' else result
export sortBy = (f, xs) -->
return [] unless xs.length
export compare = (f, x, y) -->
for , x of xs then result += x
for x in xs then result += x
for , x of xs then result *= x
for x in xs then result *= x
export mean = export average = (xs) -> (sum xs) / len xs
export concat = (xss) -> fold append, [], xss
export concatMap = (f, xs) --> fold ((memo, x) -> append memo, f x), [], xs
export listToObj = (xs) ->
export maximum = (xs) -> fold1 (>?), xs
export minimum = (xs) -> fold1 (<?), xs
export scan = export scanl = (f, memo, xs) -->
then [memo] ++ [last = f last, x for , x of xs]
else [memo] ++ [last = f last, x for x in xs]
export scan1 = export scanl1 = (f, xs) --> scan f, xs.0, xs.slice 1
export scanr = (f, memo, xs) -->
scan f, memo, xs .reverse!
export scanr1 = (f, xs) -->
scan f, xs.0, xs.slice 1 .reverse!
export replicate = (n, x) -->
while i < n, ++i then result.push x
export take = (n, xs) -->
if typeof! xs is \String then '' else []
| otherwise => xs.slice 0, n
export drop = (n, xs) -->
| otherwise => xs.slice n
export splitAt = (n, xs) --> [(take n, xs), (drop n, xs)]
export takeWhile = (p, xs) -->
return xs if not xs.length
p = objToFunc p if typeof! p isnt \Function
if typeof! xs is \String then result * '' else result
export dropWhile = (p, xs) -->
return xs if not xs.length
p = objToFunc p if typeof! p isnt \Function
export span = (p, xs) --> [(takeWhile p, xs), (dropWhile p, xs)]
export breakIt = (p, xs) --> span (not) << p, xs
export zip = (xs, ys) -->
export zipWith = (f,xs, ys) -->
f = objToFunc f if typeof! f isnt \Function
if not xs.length or not ys.length
[f.apply this, zs for zs in zip.call this, xs, ys]
export zipAll = (...xss) ->
export zipAllWith = (f, ...xss) ->
f = objToFunc f if typeof! f isnt \Function
if not xss.0.length or not xss.1.length
[f.apply this, xs for xs in zipAll.apply this, xss]
export compose = (...funcs) ->
args = [f.apply this, args]
curry$ f # using util method curry$ from livescript
export flip = (f, x, y) --> f y, x
( (g, x) -> -> f(g g) ...arguments ) do
(g, x) -> -> f(g g) ...arguments
return [] if not str.length
export unlines = (strs) -> strs * \\n
return [] if not str.length
export unwords = (strs) -> strs * ' '
export negate = (x) -> -x
export quot = (x, y) --> ~~(x / y)
export div = (x, y) --> Math.floor x / y
# changed from log as log is a
# common function for logging things
export atan2 = (x, y) --> Math.atan2 x, y
export truncate = (x) -> ~~x
export round = Math.round
export ceiling = Math.ceil
export floor = Math.floor
export isItNaN = (x) -> x isnt x
export even = (x) -> x % 2 == 0
export odd = (x) -> x % 2 != 0
Math.abs Math.floor (x / (gcd x, y) * y)
export installPrelude = !(target) ->
unless target.prelude?isInstalled
target <<< out$ # using out$ generated by livescript
target <<< target.prelude.isInstalled = true
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
theme: "solarized light",
<p><strong>MIME types defined:</strong> <code>text/x-livescript</code>.</p>
<p>The LiveScript mode was written by Kenneth Bentley.</p>