From e621814a786ee526d8270b72ff1a402487283520 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 01:08:45 +0200 Subject: [PATCH 1/5] clean_around_selections: select full lines before filtering --- rc/fish.kak | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rc/fish.kak b/rc/fish.kak index 9f46516e..b03ca9ee 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -35,8 +35,9 @@ addhl -group /fish/code regex %sh{ printf '\<(%s)\>' $(printf '\Q%s\\E|' $(fish def -hidden _fish_clean_around_selections %{ eval -draft -itersel %{ + exec # trailing white spaces - try %{ exec -draft s \h+$ d } + try %{ exec -draft s \h+$ d } } } From 46d086fbbc64671f5383c967b0679f14e7059e37 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 01:33:06 +0200 Subject: [PATCH 2/5] rename clean_around_selections command to filter_around_selections --- rc/fish.kak | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rc/fish.kak b/rc/fish.kak index b03ca9ee..ae0c7691 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -33,10 +33,10 @@ addhl -group /fish/code regex %sh{ printf '\<(%s)\>' $(printf '\Q%s\\E|' $(fish # Commands # ‾‾‾‾‾‾‾‾ -def -hidden _fish_clean_around_selections %{ +def -hidden _fish_filter_around_selections %{ eval -draft -itersel %{ exec - # trailing white spaces + # remove trailing white spaces try %{ exec -draft s \h+$ d } } } @@ -45,8 +45,8 @@ def -hidden _fish_indent_on_new_line %{ eval -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } - # cleanup previous line - try %{ exec -draft k : _fish_clean_around_selections } + # filter previous line + try %{ exec -draft k : _fish_filter_around_selections } # copy '#' comment prefix and following white spaces try %{ exec -draft k x s ^\h*\K#\h* y j p } # indent after (begin|for|function|if|switch|while) commands and add 'end' command @@ -60,7 +60,7 @@ def -hidden _fish_indent_on_new_line %{ hook global WinSetOption filetype=fish %{ addhl ref fish - hook window InsertEnd .* -group fish-hooks _fish_clean_around_selections + hook window InsertEnd .* -group fish-hooks _fish_filter_around_selections hook window InsertChar \n -group fish-indent _fish_indent_on_new_line } From 1bcec582d322e9438c220e928e364964f75a33d4 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 17:19:58 +0200 Subject: [PATCH 3/5] indent_on_new_line: handle 'else if' command --- rc/fish.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/fish.kak b/rc/fish.kak index ae0c7691..2f5f9c15 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -50,7 +50,7 @@ def -hidden _fish_indent_on_new_line %{ # copy '#' comment prefix and following white spaces try %{ exec -draft k x s ^\h*\K#\h* y j p } # indent after (begin|for|function|if|switch|while) commands and add 'end' command - try %{ exec -draft k x (begin|for|function|if|switch|while) x y p j a end k } + try %{ exec -draft k x (begin|for|function|(? x y p j a end k } } } From 1a84ca46f6ba6d8bac7119fb8f26fc5767bee0fe Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 17:47:11 +0200 Subject: [PATCH 4/5] indent_on_new_line: indent after (case|else) commands --- rc/fish.kak | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rc/fish.kak b/rc/fish.kak index 2f5f9c15..769b6f26 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -49,6 +49,8 @@ def -hidden _fish_indent_on_new_line %{ try %{ exec -draft k : _fish_filter_around_selections } # copy '#' comment prefix and following white spaces try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after (case|else) commands + try %{ exec -draft k x (case|else) j } # indent after (begin|for|function|if|switch|while) commands and add 'end' command try %{ exec -draft k x (begin|for|function|(? x y p j a end k } } From 0fcdbfbdd9064e7851e5460eb1bd3f16c4e8574f Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 17:50:48 +0200 Subject: [PATCH 5/5] indent_on_char: deindent on (else|end) command insertion --- rc/fish.kak | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rc/fish.kak b/rc/fish.kak index 769b6f26..f0e2fd8e 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -41,6 +41,13 @@ def -hidden _fish_filter_around_selections %{ } } +def -hidden _fish_indent_on_char %{ + eval -draft -itersel %{ + # deindent on (else|end) command insertion + try %{ exec -draft w (else|end) } + } +} + def -hidden _fish_indent_on_new_line %{ eval -draft -itersel %{ # preserve previous line indent @@ -63,6 +70,7 @@ hook global WinSetOption filetype=fish %{ addhl ref fish hook window InsertEnd .* -group fish-hooks _fish_filter_around_selections + hook window InsertChar .* -group fish-indent _fish_indent_on_char hook window InsertChar \n -group fish-indent _fish_indent_on_new_line }