diff --git a/.config/kak/kakrc b/.config/kak/kakrc index 12b0c93..d82d690 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -55,33 +55,12 @@ map global insert '' 'b' source "%val{config}/plugins/smarttab.kak/rc/smarttab.kak" hook global ModuleLoaded smarttab %{ set-option global softtabstop 4 + + source "%val{config}/sleuth.kak" + hook -group sleuth global BufOpenFile .* %{ sleuth } + hook -group sleuth global BufWritePost .* %{ sleuth } } -# https://github.com/mawww/kakoune/issues/2108#issuecomment-721313321 -define-command sleuth -docstring 'Heuristically set buffer options' %{ - try %{ - evaluate-commands -draft %{ - # Search the first indent level - execute-keys 'gg' '/' '^\h+' '' - - # Tab vs. Space - # https://youtu.be/V7PLxL8jIl8 - try %{ - execute-keys '' '\t' '' - noexpandtab - set-option buffer indentwidth 0 - } catch %{ - expandtab - set-option buffer indentwidth %val{selection_length} - set-option buffer softtabstop %val{selection_length} - } - } - } -} - -hook -group sleuth global BufOpenFile .* %{ sleuth } -hook -group sleuth global BufWritePost .* %{ sleuth } - # ------------ # FZF # ------------ diff --git a/.config/kak/sleuth.kak b/.config/kak/sleuth.kak new file mode 100644 index 0000000..96367ee --- /dev/null +++ b/.config/kak/sleuth.kak @@ -0,0 +1,22 @@ +# https://github.com/mawww/kakoune/issues/2108#issuecomment-721313321 +define-command sleuth -docstring 'Heuristically set buffer options' %{ + try %{ + evaluate-commands -draft %{ + # Search the first indent level + execute-keys 'gg' '/' '^\h+' '' + + # Tab vs. Space + # https://youtu.be/V7PLxL8jIl8 + try %{ + execute-keys '' '\t' '' + noexpandtab + set-option buffer indentwidth 0 + } catch %{ + expandtab + set-option buffer indentwidth %val{selection_length} + set-option buffer softtabstop %val{selection_length} + } + } + } +} +