2016-02-26 19:56:08 +01:00
|
|
|
# http://moonscript.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](moon) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype moon
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=moon %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module moon
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2022-04-30 11:22:47 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group moon-trim-indent moon-trim-indent
|
2019-04-12 00:54:58 +02:00
|
|
|
hook window InsertChar .* -group moon-indent moon-indent-on-char
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group moon-insert moon-insert-on-new-line
|
2019-04-12 00:54:58 +02:00
|
|
|
hook window InsertChar \n -group moon-indent moon-indent-on-new-line
|
|
|
|
|
|
|
|
alias window alt moon-alternative-file
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{
|
|
|
|
remove-hooks window moon-.+
|
|
|
|
unalias window alt moon-alternative-file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group moon-highlight global WinSetOption filetype=moon %{
|
|
|
|
add-highlighter window/moon ref moon
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/moon }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module moon %[
|
|
|
|
|
2016-02-26 19:56:08 +01:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/moon regions
|
|
|
|
add-highlighter shared/moon/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/moon/double_string region '"' (?<!\\)(\\\\)*" regions
|
|
|
|
add-highlighter shared/moon/single_string region "'" (?<!\\)(\\\\)*' fill string
|
|
|
|
add-highlighter shared/moon/comment region '--' '$' fill comment
|
2016-02-26 19:56:08 +01:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/moon/double_string/base default-region fill string
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/moon/double_string/interpolation region -recurse \{ \Q#{ \} fill meta
|
2016-02-26 19:56:08 +01:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/moon/code/ regex ([.\\](?=[A-Za-z]))|(\b[A-Za-z]\w*:)|(\b[A-Za-z]\w*\K!+)|(\W\K[@:][A-Za-z]\w*) 0:variable
|
|
|
|
add-highlighter shared/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
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-05-06 23:29:52 +02:00
|
|
|
define-command moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{
|
2016-03-03 18:52:54 +01:00
|
|
|
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//))
|
2019-10-08 18:06:54 +02:00
|
|
|
[ ! -f $altfile ] && echo "fail '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
|
2019-10-08 18:06:54 +02:00
|
|
|
[ ! -d $altdir ] && echo "fail 'spec/ not found'" && exit
|
2016-03-03 18:52:54 +01:00
|
|
|
;;
|
|
|
|
*)
|
2019-10-08 18:06:54 +02:00
|
|
|
echo "fail '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
|
|
|
}}
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden moon-trim-indent %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2022-03-16 23:20:07 +01:00
|
|
|
execute-keys x
|
2016-02-26 19:56:08 +01:00
|
|
|
# remove trailing white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft s \h + $ <ret> d }
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden moon-indent-on-char %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2016-02-26 19:56:08 +01:00
|
|
|
# align _else_ statements to start
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft x <a-k> ^ \h * (else(if)?) $ <ret> <a-semicolon> <a-?> ^ \h * (if|unless|when) <ret> s \A | \z <ret> ) <a-&> }
|
2016-02-26 19:56:08 +01:00
|
|
|
# align _when_ to _switch_ then indent
|
2022-04-15 00:14:17 +02:00
|
|
|
try %{ execute-keys -draft x <a-k> ^ \h * (when) $ <ret> <a-semicolon> <a-?> ^ \h * (switch) <ret> s \A | \z <ret> ) <a-&> ) , <gt> }
|
2016-02-26 19:56:08 +01:00
|
|
|
# align _catch_ and _finally_ to _try_
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft x <a-k> ^ \h * (catch|finally) $ <ret> <a-semicolon> <a-?> ^ \h * (try) <ret> s \A | \z <ret> ) <a-&> }
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden moon-insert-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-01-11 14:56:48 +01:00
|
|
|
# copy -- comment prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
|
2021-04-17 10:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command -hidden moon-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2016-02-26 19:56:08 +01:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2016-02-26 19:56:08 +01:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : moon-trim-indent <ret> }
|
2016-02-26 19:56:08 +01:00
|
|
|
# indent after start structure
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x <a-k> ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ <ret> j <a-gt> }
|
2016-02-26 19:56:08 +01:00
|
|
|
# deindent after return statements
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x <a-k> ^ \h * (break|return) \b <ret> j <a-lt> }
|
2016-02-26 19:56:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
]
|