From 0e185c54ef6db57556eb6c9491c414a234312060 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Tue, 27 Sep 2016 11:36:43 +0200 Subject: [PATCH 1/4] compact commands --- rc/base/fish.kak | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 08211278..1434124a 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -35,28 +35,28 @@ addhl -group /fish/code regex \b(and|begin|bg|bind|block|break|breakpoint|builti def -hidden _fish_filter_around_selections %{ # remove trailing white spaces - try %{ exec -draft -itersel s \h+$ d } + try %{ exec -draft -itersel s\h+$d } } def -hidden _fish_indent_on_char %{ eval -draft -itersel %{ # deindent on (else|end) command insertion - try %{ exec -draft w (else|end) } + try %{ exec -draft w(else|end) } } } def -hidden _fish_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 : _fish_filter_around_selections } + 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 } + try %{ exec -draft kxs^\h*\K#\h*yjp } # indent after (case|else) commands - try %{ exec -draft k x (case|else) j } + try %{ exec -draft kx(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 } + try %{ exec -draft kx(begin|for|function|(?xypjaendk } } } From f0820bc83d946c4c4fb2537a92401eff66a7f39e Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Tue, 27 Sep 2016 11:47:28 +0200 Subject: [PATCH 2/4] slight refactor in _fish_filter_around_selections command --- rc/base/fish.kak | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 1434124a..1ce6b0fc 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -34,8 +34,10 @@ addhl -group /fish/code regex \b(and|begin|bg|bind|block|break|breakpoint|builti # ‾‾‾‾‾‾‾‾ def -hidden _fish_filter_around_selections %{ - # remove trailing white spaces - try %{ exec -draft -itersel s\h+$d } + eval -draft -itersel %{ + # remove trailing white spaces + try %{ exec -draft s\h+$d } + } } def -hidden _fish_indent_on_char %{ From c853e3a50272f4aaf11eb1ff00b4cf8ae86a7737 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Tue, 27 Sep 2016 11:48:46 +0200 Subject: [PATCH 3/4] disable hooks --- rc/base/fish.kak | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 1ce6b0fc..d6200461 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -34,21 +34,21 @@ addhl -group /fish/code regex \b(and|begin|bg|bind|block|break|breakpoint|builti # ‾‾‾‾‾‾‾‾ def -hidden _fish_filter_around_selections %{ - eval -draft -itersel %{ + eval -no-hooks -draft -itersel %{ # remove trailing white spaces try %{ exec -draft s\h+$d } } } def -hidden _fish_indent_on_char %{ - eval -draft -itersel %{ + eval -no-hooks -draft -itersel %{ # deindent on (else|end) command insertion try %{ exec -draft w(else|end) } } } def -hidden _fish_indent_on_new_line %{ - eval -draft -itersel %{ + eval -no-hooks -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } # filter previous line From 5c4eda5ba6547d610bb0ff2df33d41fa545a7873 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Tue, 27 Sep 2016 12:08:42 +0200 Subject: [PATCH 4/4] refactorize command hooks --- rc/base/fish.kak | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index d6200461..d8cfab39 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -42,8 +42,10 @@ def -hidden _fish_filter_around_selections %{ def -hidden _fish_indent_on_char %{ eval -no-hooks -draft -itersel %{ - # deindent on (else|end) command insertion - try %{ exec -draft w(else|end) } + # align middle and end structures to start and indent when necessary + try %{ exec -draft ^\h*(else)$^\h*(if)s\A|\Z' } + try %{ exec -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|\Z' } + try %{ exec -draft ^\h*(case)$^\h*(switch)s\A|\Z'' } } } @@ -53,12 +55,20 @@ def -hidden _fish_indent_on_new_line %{ try %{ exec -draft K } # filter previous line try %{ exec -draft k:_fish_filter_around_selections } - # copy '#' comment prefix and following white spaces + # indent after start structure + try %{ exec -draft kx^\h*(begin|case|else|for|function|if|switch|while)\bj } + } +} + +def -hidden _fish_insert_on_new_line %{ + eval -no-hooks -draft -itersel %{ + # copy _#_ comment prefix and following white spaces try %{ exec -draft kxs^\h*\K#\h*yjp } - # indent after (case|else) commands - try %{ exec -draft kx(case|else)j } - # indent after (begin|for|function|if|switch|while) commands and add 'end' command - try %{ exec -draft kx(begin|for|function|(?xypjaendk } + # wisely add end structure + eval -save-regs x %{ + try %{ exec -draft kxs^\h+"xy } catch %{ reg x '' } + try %{ exec -draft kx^x(begin|for|function|if|switch|while)jiXK^x(begin|for|function|if|switch|while).*\nxend$jxypjaend } + } } } @@ -68,13 +78,13 @@ def -hidden _fish_indent_on_new_line %{ 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 + hook window InsertChar \n -group fish-insert _fish_insert_on_new_line } hook global WinSetOption filetype=(?!fish).* %{ rmhl fish rmhooks window fish-indent - rmhooks window fish-hooks + rmhooks window fish-insert }