From c24fa2ea79f24b20eefbea0ee09407554a4f9659 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 21 Jan 2016 18:33:03 +0100 Subject: [PATCH 1/2] support commenting --- rc/ruby.kak | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rc/ruby.kak b/rc/ruby.kak index 77c4a533..28dae4f4 100644 --- a/rc/ruby.kak +++ b/rc/ruby.kak @@ -1,6 +1,8 @@ # http://ruby-lang.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +# require commenting.kak + # Detection # ‾‾‾‾‾‾‾‾‾ @@ -97,6 +99,9 @@ hook global WinSetOption filetype=ruby %{ hook window InsertEnd .* -group ruby-hooks _ruby_filter_around_selections hook window InsertChar .* -group ruby-indent _ruby_indent_on_char hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line + + set window comment_line_chars '#' + set window comment_selection_chars '^begin=:^=end' } hook global WinSetOption filetype=(?!ruby).* %{ From 396534c0bba540661f2b61d03eca545409ae37dc Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 21 Jan 2016 19:19:17 +0100 Subject: [PATCH 2/2] make auto-(indenting/insertion) more robust --- rc/ruby.kak | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) 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 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾