2016-02-26 21:56:08 +03:00
|
|
|
# http://moonscript.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](moon) %{
|
2016-12-06 16:40:14 +03:00
|
|
|
set buffer filetype moon
|
2016-02-26 21:56:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group / regions -default code moon \
|
2016-02-26 21:56:08 +03:00
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
single_string "'" (?<!\\)(\\\\)*' '' \
|
|
|
|
comment '--' '$' '' \
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /moon/double_string fill string
|
|
|
|
add-highlighter -group /moon/double_string regions regions interpolation \Q#{ \} \{
|
|
|
|
add-highlighter -group /moon/double_string/regions/interpolation fill meta
|
2016-02-26 21:56:08 +03:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /moon/single_string fill string
|
2016-02-26 21:56:08 +03:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /moon/comment fill comment
|
2016-02-26 21:56:08 +03:00
|
|
|
|
2017-02-10 05:43:29 +03:00
|
|
|
add-highlighter -group /moon/code regex ([.\\](?=[A-Za-z]\w*))|(\b[A-Za-z]\w*:)|(\b[A-Za-z]\w*\K!+)|(\W\K[@:][A-Za-z]\w*) 0:variable
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /moon/code regex \b(and|break|catch|class|continue|do|else(if)?|export|extends|false|finally|for|from|if|import|in|local|nil|not|or|return|super|switch|then|true|try|unless|using|when|while|with)\b 0:keyword
|
2016-02-26 21:56:08 +03:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-03-03 20:52:54 +03:00
|
|
|
def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{
|
|
|
|
case $kak_buffile in
|
|
|
|
*spec/*_spec.moon)
|
2016-04-23 08:47:01 +03:00
|
|
|
altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//))
|
2017-07-19 18:18:52 +03:00
|
|
|
[ ! -f $altfile ] && echo "echo -markup '{Error}implementation file not found'" && exit
|
2016-03-03 20:52:54 +03:00
|
|
|
;;
|
|
|
|
*.moon)
|
|
|
|
path=$kak_buffile
|
2016-04-23 08:47:01 +03:00
|
|
|
dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2)
|
2016-03-03 20:52:54 +03:00
|
|
|
for dir in $dirs; do
|
|
|
|
altdir=$dir/spec
|
|
|
|
if [ -d $altdir ]; then
|
2016-03-08 22:33:54 +03:00
|
|
|
altfile=$altdir/$(realpath $kak_buffile --relative-to $dir | sed s+[^/]'*'/++';'s/.moon$/_spec.moon/)
|
2016-03-03 20:52:54 +03:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2017-07-19 18:18:52 +03:00
|
|
|
[ ! -d $altdir ] && echo "echo -markup '{Error}spec/ not found'" && exit
|
2016-03-03 20:52:54 +03:00
|
|
|
;;
|
|
|
|
*)
|
2017-07-19 18:18:52 +03:00
|
|
|
echo "echo -markup '{Error}alternative file not found'" && exit
|
2016-03-03 20:52:54 +03:00
|
|
|
;;
|
|
|
|
esac
|
2016-04-23 08:47:01 +03:00
|
|
|
printf %s\\n "edit $altfile"
|
2016-03-03 20:52:54 +03:00
|
|
|
}}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden moon-filter-around-selections %{
|
2016-02-26 21:56:08 +03:00
|
|
|
eval -draft -itersel %{
|
|
|
|
exec <a-x>
|
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft s \h + $ <ret> d }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden moon-indent-on-char %{
|
2016-02-26 21:56:08 +03:00
|
|
|
eval -draft -itersel %{
|
|
|
|
# align _else_ statements to start
|
|
|
|
try %{ exec -draft <a-x> <a-k> ^ \h * (else(if)?) $ <ret> <a-\;> <a-?> ^ \h * (if|unless|when) <ret> s \A | \Z <ret> \' <a-&> }
|
|
|
|
# align _when_ to _switch_ then indent
|
|
|
|
try %{ exec -draft <a-x> <a-k> ^ \h * (when) $ <ret> <a-\;> <a-?> ^ \h * (switch) <ret> s \A | \Z <ret> \' <a-&> \' <space> <gt> }
|
|
|
|
# align _catch_ and _finally_ to _try_
|
|
|
|
try %{ exec -draft <a-x> <a-k> ^ \h * (catch|finally) $ <ret> <a-\;> <a-?> ^ \h * (try) <ret> s \A | \Z <ret> \' <a-&> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden moon-indent-on-new-line %{
|
2016-02-26 21:56:08 +03:00
|
|
|
eval -draft -itersel %{
|
2017-01-11 16:56:48 +03:00
|
|
|
# copy -- comment prefix and following white spaces
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft k <a-x> s ^ \h * \K -- \h * <ret> y gh j P }
|
2016-02-26 21:56:08 +03:00
|
|
|
# preserve previous line indent
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2016-02-26 21:56:08 +03:00
|
|
|
# filter previous line
|
2017-01-13 03:56:30 +03:00
|
|
|
try %{ exec -draft k : moon-filter-around-selections <ret> }
|
2016-02-26 21:56:08 +03:00
|
|
|
# indent after start structure
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft k <a-x> <a-k> ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ <ret> j <a-gt> }
|
2016-02-26 21:56:08 +03:00
|
|
|
# deindent after return statements
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft k <a-x> <a-k> ^ \h * (break|return) \b <ret> j <a-lt> }
|
2016-02-26 21:56:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group moon-highlight global WinSetOption filetype=moon %{ add-highlighter ref moon }
|
2016-02-26 21:56:08 +03:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook global WinSetOption filetype=moon %{
|
2017-01-13 03:56:30 +03:00
|
|
|
hook window InsertEnd .* -group moon-hooks moon-filter-around-selections
|
|
|
|
hook window InsertChar .* -group moon-indent moon-indent-on-char
|
|
|
|
hook window InsertChar \n -group moon-indent moon-indent-on-new-line
|
2016-02-26 21:56:08 +03:00
|
|
|
|
2016-03-03 20:52:54 +03:00
|
|
|
alias window alt moon-alternative-file
|
2016-02-26 21:56:08 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group moon-highlight global WinSetOption filetype=(?!moon).* %{ remove-highlighter moon }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2016-02-26 21:56:08 +03:00
|
|
|
hook global WinSetOption filetype=(?!moon).* %{
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window moon-indent
|
|
|
|
remove-hooks window moon-hooks
|
2016-03-03 20:52:54 +03:00
|
|
|
|
|
|
|
unalias window alt moon-alternative-file
|
2016-02-26 21:56:08 +03:00
|
|
|
}
|