diff --git a/rc/ruby.kak b/rc/ruby.kak index 28dae4f4..b95b4068 100644 --- a/rc/ruby.kak +++ b/rc/ruby.kak @@ -62,33 +62,40 @@ addhl -group /ruby/code regex \<(alias|and|begin|break|case|class|def|defined|do # ‾‾‾‾‾‾‾‾ def -hidden _ruby_filter_around_selections %{ - # remove trailing white spaces - try %{ exec -draft -itersel s \h+$ d } + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h + $ d } + } } -def -hidden _ruby_indent_on_char %< - eval -draft -itersel %< - # deindent on (else|elsif|end|rescue|when) keyword insertion - try %{ exec -draft w (else|elsif|end|rescue|when) } - # align closer token to its opener when alone on a line - try %< exec -draft ^\h+[]}]$ m s \`|.\' 1 > - > -> +def -hidden _ruby_indent_on_char %{ + eval -draft -itersel %{ + # align middle and end structures to start + try %{ exec -draft ^ \h * (else|elsif) $ ^ \h * (if) s \A | \Z \' } + try %{ exec -draft ^ \h * (when) $ ^ \h * (case) s \A | \Z \' } + try %{ exec -draft ^ \h * (rescue) $ ^ \h * (begin) s \A | \Z \' } + try %{ exec -draft ^ \h * (end) $ ^ \h * (begin|case|class|def|do|for|if|module|unless|until|while) s \A | \Z \' } + } +} -def -hidden _ruby_indent_on_new_line %( - eval -draft -itersel %( +def -hidden _ruby_indent_on_new_line %{ + eval -draft -itersel %{ # preserve previous line indent - try %{ exec -draft K } + try %{ exec -draft K } # filter previous line try %{ exec -draft k : _ruby_filter_around_selections } # copy _#_ comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y j p } - # indent after (else|elsif|rescue|when) keywords and lines beginning / ending with opener token - try %( exec -draft k x (else|elsif|rescue|when)|^\h*[[{]|[[{]$ j ) - # indent after (begin|case|class|def|do|if|loop|module|unless|until|while) keywords and add _end_ keyword - try %{ exec -draft k x (begin|case|class|def|do|(? x y p j a end k } - ) -) + try %{ exec -draft k x s ^ \h * \K \# \h * y j p } + # indent after start structure + try %{ exec -draft k x ^ \h * (begin|case|class|def|do|else|elsif|ensure|for|if|module|rescue|unless|until|when|while) \b j } + # wisely add end structure + eval -save-regs x %{ + try %{ exec -draft k x s ^ \h + \" x y } catch %{ reg x '' } + try %{ exec -draft k x ^ x (begin|case|class|def|do|for|if|module|unless|until|while) j i X K ^ x (for|function|if|while) . * \n x end $ j x y p j a end } + } + } +} # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾