From fea851b78b5ad2ba628896e4c8006c3c354cd6d6 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 30 Apr 2022 11:27:12 +0200 Subject: [PATCH] rc filetype: add some missing ModeChange hooks for trim-indent Some languages have a trim-indent command but don't use it (for no apparent reason). Make them trim trailing spaces when exiting insert mode, like most other languages support scripts do. --- rc/filetype/crystal.kak | 1 + rc/filetype/fish.kak | 1 + rc/filetype/gas.kak | 1 + rc/filetype/ruby.kak | 1 + test/indent/ruby/do-keyword/out | 4 ++-- test/indent/ruby/following-blocks-should-not-prevent-end/out | 2 +- test/indent/ruby/indent-after-class/out | 4 ++-- test/indent/ruby/method-definition-shouldnt-duplicate/out | 2 +- 8 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index ada76ff8..7752698a 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -17,6 +17,7 @@ hook global WinSetOption filetype=crystal %{ add-highlighter window/crystal ref crystal evaluate-commands set-option window static_words %opt{crystal_keywords} %opt{crystal_attributes} %opt{crystal_objects} + hook window ModeChange pop:insert:.* -group crystal-trim-indent crystal-trim-indent hook window InsertChar .* -group crystal-indent crystal-indent-on-char hook window InsertChar '\n' -group crystal-indent crystal-indent-on-new-line hook window InsertChar '\n' -group crystal-insert crystal-insert-on-new-line diff --git a/rc/filetype/fish.kak b/rc/filetype/fish.kak index e15660f4..f2ca922f 100644 --- a/rc/filetype/fish.kak +++ b/rc/filetype/fish.kak @@ -14,6 +14,7 @@ hook global BufCreate .*[.](fish) %{ hook global WinSetOption filetype=fish %{ require-module fish + hook window ModeChange pop:insert:.* -group fish-trim-indent fish-trim-indent hook window InsertChar .* -group fish-indent fish-indent-on-char hook window InsertChar \n -group fish-insert fish-insert-on-new-line hook window InsertChar \n -group fish-indent fish-indent-on-new-line diff --git a/rc/filetype/gas.kak b/rc/filetype/gas.kak index cfcf395b..5f753d54 100644 --- a/rc/filetype/gas.kak +++ b/rc/filetype/gas.kak @@ -7,6 +7,7 @@ hook global BufCreate .*\.(s|S|asm)$ %{ hook global WinSetOption filetype=gas %{ require-module gas + hook window ModeChange pop:insert:.* -group gas-trim-indent gas-trim-indent hook window InsertChar \n -group gas-indent gas-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gas-.+ } } diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index 88844ded..a950da19 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=ruby %{ set-option window static_words %opt{ruby_static_words} + hook window ModeChange pop:insert:.* -group ruby-trim-indent ruby-trim-indent hook window InsertChar .* -group ruby-indent ruby-indent-on-char hook window InsertChar \n -group ruby-indent ruby-indent-on-new-line hook window InsertChar \n -group ruby-insert ruby-insert-on-new-line diff --git a/test/indent/ruby/do-keyword/out b/test/indent/ruby/do-keyword/out index b38bd9a4..14d3a5e4 100644 --- a/test/indent/ruby/do-keyword/out +++ b/test/indent/ruby/do-keyword/out @@ -1,7 +1,7 @@ test do - + end e.map do |element| - + end diff --git a/test/indent/ruby/following-blocks-should-not-prevent-end/out b/test/indent/ruby/following-blocks-should-not-prevent-end/out index 53db17a8..ac4f6ebb 100644 --- a/test/indent/ruby/following-blocks-should-not-prevent-end/out +++ b/test/indent/ruby/following-blocks-should-not-prevent-end/out @@ -1,5 +1,5 @@ def foo - + end def bar diff --git a/test/indent/ruby/indent-after-class/out b/test/indent/ruby/indent-after-class/out index ff201238..793a439c 100644 --- a/test/indent/ruby/indent-after-class/out +++ b/test/indent/ruby/indent-after-class/out @@ -1,4 +1,4 @@ class Test - - + + end diff --git a/test/indent/ruby/method-definition-shouldnt-duplicate/out b/test/indent/ruby/method-definition-shouldnt-duplicate/out index 895bd63e..47cc76ba 100644 --- a/test/indent/ruby/method-definition-shouldnt-duplicate/out +++ b/test/indent/ruby/method-definition-shouldnt-duplicate/out @@ -1,5 +1,5 @@ class Test def test - + end end