From 422a963697785d83567111480213c87076274ed7 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Tue, 13 May 2025 18:32:14 -0400 Subject: [PATCH] AutoYADM commit: 2025-05-13 18:32:14 --- .config/kak/kakrc | 7 +++-- .config/kak/scripts/kakfmt | 56 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/.config/kak/kakrc b/.config/kak/kakrc index bc851354..91e35b86 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -64,17 +64,18 @@ define-command ui-scrolloff-toggle -docstring "toggle scrolloff" %{ CUR="$kak_opt_scrolloff" IFS=, read TARG HOR <<<$kak_opt_base_scrolloff - if [ "$CUR" != ${CUR#99} ]; then + IFS=, + read VSCROLL _ <<<$kak_opt_scrolloff + if [ "$VSCROLL" = 99 ]; then final="$TARG,$HOR" else final="99,$HOR" fi - # echo "echo final: $final, targ: $TARG, hor: $HOR" echo "set-option window scrolloff $final" } } -map global ui z ": ui-scrolloff-toggle 3 3" +map global ui z ": ui-scrolloff-toggle" hook global WinCreate .* %{ ui-wrap-enable diff --git a/.config/kak/scripts/kakfmt b/.config/kak/scripts/kakfmt index 5751fa03..7321d05c 100755 --- a/.config/kak/scripts/kakfmt +++ b/.config/kak/scripts/kakfmt @@ -1,5 +1,24 @@ #!/usr/bin/env perl +# old +# use strict; +# use warnings; + +# my $Indent = 0; +# my $Blank_Lines = 0; +# my $Open = qr/[{\[(]$/; +# my $Close = qr/^[}\])]/; +# while (<>) { +# s/^\h*//; +# $Blank_Lines++, next if m/^$/; +# my $Comment = m/^#/; +# $Indent-- if m/$Close/ and not $Comment; +# $Blank_Lines = 0, print "\n" if $Blank_Lines; +# print "\t" x $Indent, $_; +# $Indent++ if m/$Open/ and not $Comment; +# } +#!/usr/bin/env perl + use strict; use warnings; @@ -7,12 +26,45 @@ my $Indent = 0; my $Blank_Lines = 0; my $Open = qr/[{\[(]$/; my $Close = qr/^[}\])]/; +my $InShell = 0; +my $ShellIndent = 0; + while (<>) { s/^\h*//; - $Blank_Lines++, next if m/^$/; + + # Track blank lines + if (/^$/) { + $Blank_Lines++; + next; + } + + # Detect start of %sh{ + if (/^%sh\s*{/) { + print "\t" x $Indent, $_; + $InShell = 1; + $ShellIndent = 0; + next; + } + + # Detect end of shell block + if ($InShell && /^\}/) { + $InShell = 0; + print "\t" x $Indent, $_; + next; + } + + if ($InShell) { + $ShellIndent-- if /^\s*(?:fi|done|esac|elif|else|elif|;;)/; + print "\t" x ($Indent + $ShellIndent), $_; + $ShellIndent++ if /\b(?:then|do|case)\b(?:\s*#.*)?$/ or /{\s*$/; + next; + } + my $Comment = m/^#/; $Indent-- if m/$Close/ and not $Comment; - $Blank_Lines = 0, print "\n" if $Blank_Lines; + print "\n" if $Blank_Lines; + $Blank_Lines = 0; print "\t" x $Indent, $_; $Indent++ if m/$Open/ and not $Comment; } +