From 148ad6c1abdb02f14a76ebec75e0976543f063d7 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sat, 5 Jun 2021 23:28:10 +0600 Subject: [PATCH 1/6] Add test for electric indentation in Ruby --- test/indent/ruby/deindent-on-if-else-end/cmd | 1 + test/indent/ruby/deindent-on-if-else-end/in | 1 + test/indent/ruby/deindent-on-if-else-end/out | 4 ++++ test/indent/ruby/deindent-on-if-else-end/rc | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 test/indent/ruby/deindent-on-if-else-end/cmd create mode 100644 test/indent/ruby/deindent-on-if-else-end/in create mode 100644 test/indent/ruby/deindent-on-if-else-end/out create mode 100644 test/indent/ruby/deindent-on-if-else-end/rc diff --git a/test/indent/ruby/deindent-on-if-else-end/cmd b/test/indent/ruby/deindent-on-if-else-end/cmd new file mode 100644 index 00000000..af7a7628 --- /dev/null +++ b/test/indent/ruby/deindent-on-if-else-end/cmd @@ -0,0 +1 @@ +celsifelse diff --git a/test/indent/ruby/deindent-on-if-else-end/in b/test/indent/ruby/deindent-on-if-else-end/in new file mode 100644 index 00000000..d2ff880a --- /dev/null +++ b/test/indent/ruby/deindent-on-if-else-end/in @@ -0,0 +1 @@ +if%( ) diff --git a/test/indent/ruby/deindent-on-if-else-end/out b/test/indent/ruby/deindent-on-if-else-end/out new file mode 100644 index 00000000..0c6e08ae --- /dev/null +++ b/test/indent/ruby/deindent-on-if-else-end/out @@ -0,0 +1,4 @@ +if +elsif +else +end diff --git a/test/indent/ruby/deindent-on-if-else-end/rc b/test/indent/ruby/deindent-on-if-else-end/rc new file mode 100644 index 00000000..934f7e83 --- /dev/null +++ b/test/indent/ruby/deindent-on-if-else-end/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/ruby.kak" +set buffer filetype ruby From 02e625e8fb942121ba76448a33408890eadb4f07 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 6 Jun 2021 00:30:50 +0600 Subject: [PATCH 2/6] Remove electric behavior for end keyword Correctly indentint on "end" keyword seems very hard, it is simpler to remove it. And we already insert "end" in ruby-insert-on-new-line hook, so the removal shouldn't hurt too much. --- rc/filetype/ruby.kak | 1 - .../4086-ruby-deindenting-other-lines-than-keywords/cmd | 1 + .../4086-ruby-deindenting-other-lines-than-keywords/in | 6 ++++++ .../4086-ruby-deindenting-other-lines-than-keywords/out | 6 ++++++ .../4086-ruby-deindenting-other-lines-than-keywords/rc | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/regression/4086-ruby-deindenting-other-lines-than-keywords/cmd create mode 100644 test/regression/4086-ruby-deindenting-other-lines-than-keywords/in create mode 100644 test/regression/4086-ruby-deindenting-other-lines-than-keywords/out create mode 100644 test/regression/4086-ruby-deindenting-other-lines-than-keywords/rc diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index 8c6dea3f..00adaa68 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -156,7 +156,6 @@ define-command -hidden ruby-indent-on-char %{ try %{ execute-keys -draft ^ \h * (elsif) $ i ^ \h * (if) 1 } try %{ execute-keys -draft ^ \h * (when) $ i ^ \h * (case) 1 } try %{ execute-keys -draft ^ \h * (rescue) $ i ^ \h * (begin|def) 1 } - try %{ execute-keys -draft ^ \h * (end) $ i ^ \h * (begin|case|class|def|for|if|module|unless|until|while) 1 } } } diff --git a/test/regression/4086-ruby-deindenting-other-lines-than-keywords/cmd b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/cmd new file mode 100644 index 00000000..af092ecb --- /dev/null +++ b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/cmd @@ -0,0 +1 @@ +cend diff --git a/test/regression/4086-ruby-deindenting-other-lines-than-keywords/in b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/in new file mode 100644 index 00000000..115984bf --- /dev/null +++ b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/in @@ -0,0 +1,6 @@ +class MyClass + def method +%( ) + + expression +end diff --git a/test/regression/4086-ruby-deindenting-other-lines-than-keywords/out b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/out new file mode 100644 index 00000000..52988874 --- /dev/null +++ b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/out @@ -0,0 +1,6 @@ +class MyClass + def method + end + + expression +end diff --git a/test/regression/4086-ruby-deindenting-other-lines-than-keywords/rc b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/rc new file mode 100644 index 00000000..934f7e83 --- /dev/null +++ b/test/regression/4086-ruby-deindenting-other-lines-than-keywords/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/ruby.kak" +set buffer filetype ruby From fcc04384d13a380dd10d3049c54d7c460aa6bf31 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 6 Jun 2021 00:38:36 +0600 Subject: [PATCH 3/6] Fix Ruby mid-comment Implementation is copied from Nim. --- rc/filetype/ruby.kak | 2 +- test/indent/ruby/insert-comment-hash/cmd | 1 + test/indent/ruby/insert-comment-hash/in | 1 + test/indent/ruby/insert-comment-hash/out | 2 ++ test/indent/ruby/insert-comment-hash/rc | 3 +++ 5 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/indent/ruby/insert-comment-hash/cmd create mode 100644 test/indent/ruby/insert-comment-hash/in create mode 100644 test/indent/ruby/insert-comment-hash/out create mode 100644 test/indent/ruby/insert-comment-hash/rc diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index 00adaa68..9c94b7be 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -173,7 +173,7 @@ define-command -hidden ruby-indent-on-new-line %{ define-command -hidden ruby-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ # copy _#_ comment prefix and following white spaces - try %{ execute-keys -draft k s '^\h*\K#\h*' y j P } + try %{ exec -draft k s ^\h*#\h* y jgh P } # wisely add end structure evaluate-commands -save-regs x %[ try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' } diff --git a/test/indent/ruby/insert-comment-hash/cmd b/test/indent/ruby/insert-comment-hash/cmd new file mode 100644 index 00000000..e3036a40 --- /dev/null +++ b/test/indent/ruby/insert-comment-hash/cmd @@ -0,0 +1 @@ +c diff --git a/test/indent/ruby/insert-comment-hash/in b/test/indent/ruby/insert-comment-hash/in new file mode 100644 index 00000000..450a9496 --- /dev/null +++ b/test/indent/ruby/insert-comment-hash/in @@ -0,0 +1 @@ +# Comment%( ) comment2 diff --git a/test/indent/ruby/insert-comment-hash/out b/test/indent/ruby/insert-comment-hash/out new file mode 100644 index 00000000..bde83b7a --- /dev/null +++ b/test/indent/ruby/insert-comment-hash/out @@ -0,0 +1,2 @@ +# Comment +# comment2 diff --git a/test/indent/ruby/insert-comment-hash/rc b/test/indent/ruby/insert-comment-hash/rc new file mode 100644 index 00000000..934f7e83 --- /dev/null +++ b/test/indent/ruby/insert-comment-hash/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/ruby.kak" +set buffer filetype ruby From 0b1654b0cf1582f73939aa36ffa8ebf70d5565ab Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 6 Jun 2021 14:13:34 +0600 Subject: [PATCH 4/6] Better comment inserting tests and fix implementation --- rc/filetype/ruby.kak | 2 +- test/indent/ruby/insert-comment-hash/cmd | 2 +- test/indent/ruby/insert-comment-hash/out | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index 9c94b7be..feeb6347 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -173,7 +173,7 @@ define-command -hidden ruby-indent-on-new-line %{ define-command -hidden ruby-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ # copy _#_ comment prefix and following white spaces - try %{ exec -draft k s ^\h*#\h* y jgh P } + try %{ exec -draft k s ^\h*\K#\h* y jgi P } # wisely add end structure evaluate-commands -save-regs x %[ try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' } diff --git a/test/indent/ruby/insert-comment-hash/cmd b/test/indent/ruby/insert-comment-hash/cmd index e3036a40..bd828f35 100644 --- a/test/indent/ruby/insert-comment-hash/cmd +++ b/test/indent/ruby/insert-comment-hash/cmd @@ -1 +1 @@ -c +cjo# comment3comment4jo# indentedindented2 diff --git a/test/indent/ruby/insert-comment-hash/out b/test/indent/ruby/insert-comment-hash/out index bde83b7a..1dba5ac9 100644 --- a/test/indent/ruby/insert-comment-hash/out +++ b/test/indent/ruby/insert-comment-hash/out @@ -1,2 +1,8 @@ # Comment # comment2 + +# comment3 +# comment4 + +# indented +# indented2 From 4e94bf0e41f3e6fab5ef349476997bea8c854bb0 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 6 Jun 2021 14:27:39 +0600 Subject: [PATCH 5/6] Event better tests for comments --- test/indent/ruby/insert-comment-hash/cmd | 2 +- test/indent/ruby/insert-comment-hash/out | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/indent/ruby/insert-comment-hash/cmd b/test/indent/ruby/insert-comment-hash/cmd index bd828f35..1b9319dc 100644 --- a/test/indent/ruby/insert-comment-hash/cmd +++ b/test/indent/ruby/insert-comment-hash/cmd @@ -1 +1 @@ -cjo# comment3comment4jo# indentedindented2 +cjo# comment3comment4jo# indentedindented2jodef f# commentcomment2jjodef f# commenthhhi diff --git a/test/indent/ruby/insert-comment-hash/out b/test/indent/ruby/insert-comment-hash/out index 1dba5ac9..b5683071 100644 --- a/test/indent/ruby/insert-comment-hash/out +++ b/test/indent/ruby/insert-comment-hash/out @@ -6,3 +6,13 @@ # indented # indented2 + +def f + # comment + # comment2 +end + +def f + # comm + # ent +end From a65501a1d99ee1a2114ef65fea6aa5fc9f2eb7b0 Mon Sep 17 00:00:00 2001 From: Dmitry Matveyev Date: Sun, 6 Jun 2021 14:28:28 +0600 Subject: [PATCH 6/6] Rename exec->execute-keys for consistency --- rc/filetype/ruby.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index feeb6347..88844ded 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -173,7 +173,7 @@ define-command -hidden ruby-indent-on-new-line %{ define-command -hidden ruby-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ # copy _#_ comment prefix and following white spaces - try %{ exec -draft k s ^\h*\K#\h* y jgi P } + try %{ execute-keys -draft k s ^\h*\K#\h* y jgi P } # wisely add end structure evaluate-commands -save-regs x %[ try %{ execute-keys -draft k s ^ \h + \" x y } catch %{ reg x '' }