2016-02-26 19:56:08 +01:00
|
|
|
# http://moonscript.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# require commenting.kak
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufSetOption mimetype=text/x-moon %{
|
|
|
|
set buffer filetype moon
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](moon) %{
|
2016-02-28 17:57:38 +01:00
|
|
|
set buffer mimetype text/x-moon
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
addhl -group / regions -default code moon \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
single_string "'" (?<!\\)(\\\\)*' '' \
|
|
|
|
comment '--' '$' '' \
|
|
|
|
|
|
|
|
addhl -group /moon/double_string fill string
|
|
|
|
addhl -group /moon/double_string regions regions interpolation \Q#{ \} \{
|
|
|
|
addhl -group /moon/double_string/regions/interpolation fill meta
|
|
|
|
|
|
|
|
addhl -group /moon/single_string fill string
|
|
|
|
|
|
|
|
addhl -group /moon/comment fill comment
|
|
|
|
|
|
|
|
addhl -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:identifier
|
2016-04-21 21:43:17 +02:00
|
|
|
addhl -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 19:56:08 +01:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-03-03 18:52:54 +01:00
|
|
|
def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{
|
|
|
|
case $kak_buffile in
|
|
|
|
*spec/*_spec.moon)
|
2016-04-23 07:47:01 +02:00
|
|
|
altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//))
|
|
|
|
[ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit
|
2016-03-03 18:52:54 +01:00
|
|
|
;;
|
|
|
|
*.moon)
|
|
|
|
path=$kak_buffile
|
2016-04-23 07:47:01 +02:00
|
|
|
dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2)
|
2016-03-03 18:52:54 +01:00
|
|
|
for dir in $dirs; do
|
|
|
|
altdir=$dir/spec
|
|
|
|
if [ -d $altdir ]; then
|
2016-03-08 20:33:54 +01:00
|
|
|
altfile=$altdir/$(realpath $kak_buffile --relative-to $dir | sed s+[^/]'*'/++';'s/.moon$/_spec.moon/)
|
2016-03-03 18:52:54 +01:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2016-04-23 07:47:01 +02:00
|
|
|
[ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit
|
2016-03-03 18:52:54 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-23 07:47:01 +02:00
|
|
|
echo "echo -color Error 'alternative file not found'" && exit
|
2016-03-03 18:52:54 +01:00
|
|
|
;;
|
|
|
|
esac
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "edit $altfile"
|
2016-03-03 18:52:54 +01:00
|
|
|
}}
|
|
|
|
|
2016-02-26 19:56:08 +01:00
|
|
|
def -hidden _moon_filter_around_selections %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
exec <a-x>
|
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft s \h + $ <ret> d }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -hidden _moon_indent_on_char %{
|
|
|
|
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-&> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -hidden _moon_indent_on_new_line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft K <a-&> }
|
|
|
|
# filter previous line
|
|
|
|
try %{ exec -draft k : _moon_filter_around_selections <ret> }
|
|
|
|
# copy -- comment prefix and following white spaces
|
|
|
|
try %{ exec -draft k x s ^ \h * \K -- \h * <ret> y j p }
|
|
|
|
# indent after start structure
|
|
|
|
try %{ exec -draft k x <a-k> ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ <ret> j <a-gt> }
|
|
|
|
# deindent after return statements
|
|
|
|
try %{ exec -draft k x <a-k> ^ \h * (break|return) \b <ret> j <a-lt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group moon-highlight global WinSetOption filetype=moon %{ addhl ref moon }
|
2016-02-26 19:56:08 +01:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook global WinSetOption filetype=moon %{
|
2016-02-26 19:56:08 +01: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-03-03 18:52:54 +01:00
|
|
|
alias window alt moon-alternative-file
|
|
|
|
|
2016-02-26 19:56:08 +01:00
|
|
|
set window comment_line_chars '--'
|
|
|
|
set window comment_selection_chars ''
|
|
|
|
}
|
|
|
|
|
2016-09-28 08:45:01 +02:00
|
|
|
hool -group moon-highlight global WinSetOption filetype=(?!moon).* %{ rmhl moon }
|
|
|
|
|
2016-02-26 19:56:08 +01:00
|
|
|
hook global WinSetOption filetype=(?!moon).* %{
|
|
|
|
rmhooks window moon-indent
|
|
|
|
rmhooks window moon-hooks
|
2016-03-03 18:52:54 +01:00
|
|
|
|
|
|
|
unalias window alt moon-alternative-file
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|